I have data in the format (Observed value, Number of observations) and would like to convert it to an array of values. For example, if I had (Value = 12, Number of observations = 3), I would like to use built-in formulas to create 3 cells each containing the number 12. Is this possible? This is an example of what I'm trying to do. Thanks!
If you're willing to accept empty string instead of blank then, assuming your first column of inputs are in A1:A2, fill your output range for column A starting from A4 with:
=IF(ROW()-ROW(A$4)<A$2,A$1,"")
You can avoid the reference to the top cell by using:
=IF(ROW()-MIN(ROW())<A$2,A$1,"")
Make it an array formula (Ctrl+Shift+Enter) in the output range of column A.
You can copy either of these to the right to support additional columns.
Related
The following works as expected and counts all the cells in the range A2:P2 that contains either PH, V or O.
=SUM(COUNTIFS(A2:P2;{"PH";"V";"O"}))
I have to reuse this several places and therefore want to place the criteria array in a cell and read it from there. Something like:
=SUM(COUNTIFS(A2:P2;"&A1&")) where cell A1 contains {"PH";"V";"O"}.
Is it possible to parse the text from A1 into the formula?
Assuming that you're using Excel 2013 or later, and that A1 contains the text PH;V;O the formula below should work
=SUM(COUNTIFS(A2:P2;FILTERXML("<c><e>"&SUBSTITUTE(A1;";";"</e><e>")&"</e></c>";"//e")))
(this will have to be entered as an array formula if you don't have dynamic arrays)
i have this formula and it works fine:
=OFFSET(INDIRECT(CELL("address";INDEX(INDIRECT($F6&"!C:C");MATCH($G$2;INDIRECT($F6&"!C:C");0))));0;14;1;1)
i give it name of a sheet and a value in a certain column in that sheet and it returns the number in the 14th column in front of that target value. the value in that cell is in fact sum of 12 values beside it (12 values for 12 months of the year).
the hot point:
;14;1;1)
now i want to change the formula so that it returns an array of 12 values so that I can then sumproduct them with another array. actually I want to be able to choose which months to be included in the final sum operation. I changed the above formula to the following:
SUMPRODUCT(OFFSET(INDIRECT(CELL("address";INDEX(INDIRECT($F6&"!C:C");MATCH($G$2;INDIRECT($F6&"!C:C");0))));0;{2;3;4;5;6;7;8;9;10;11;12;13};1;1);$E$52:$E$63)
the changed part:
SUMPRODUCT( ..... ;{2;3;4;5;6;7;8;9;10;11;12;13};1;1);$E$52:$E$63)
a simple change, apparently, but it returns zero.
thanks for help
The first argument in SUMPRODUCT returns an array of references. As such, you'll need to obtain the values from those references by "de-referencing". One way would be to pass the array of references to the N() function. So your formula should be as follows...
=SUMPRODUCT(N(OFFSET(INDIRECT(CELL("address",INDEX(INDIRECT("'"&$F6&"'!C:C"),MATCH($G$2,INDIRECT("'"&$F6&"'!C:C"),0)))),0,{2;3;4;5;6;7;8;9;10;11;12;13})),$E$52:$E$63)
Note that my version of Excel uses the comma as a list separator. Therefore, adjust the formula accordingly.
How do I convert a string from a cell to a text array inside of a function, that should use the array, without using VBA and without adding the array into any other part of the document? It will be one of these arrays on more than 1000 rows. The string format is ^[a-zA-Z0-9.,-]*$ with "," as delimiter.
This is the functionality I would like to achieve
I have an excel table with the following columns
A: ID numbers to compare, separated by comma (delimiter can be changed if needed). About 100 ID's would be good to support at least.
B: ID (Each value on the rows in the column are unique but not sorted and can't be sorted because sorting is needed based on other criterias)
C: Value (Several rows in the column can have the same value)
D: Output the one ID of the comma separated ID's that has the highest value on its row
The problem part of the output
So far I have made a function which find the correct ID in column B based on the values in column C but only if I enter the string from column A as an array constant manually within the function. I have not managed to get the function to create the array itself from column A, which is required.
Working part of the code
In this code I have entered the values from column A manually and this is working as it should.
=INDEX({"1.01-1","1.01-3","1.08-1","1.01-1-1A"},MATCH(MAX(INDEX(C$10:C$20,N(IF(1,MATCH({"1.01-1","1.01-3","1.08-1","1.01-1-1A"},B$10:B$20,0))))),INDEX(C$10:C$20,N(IF(1,MATCH({"1.01-1","1.01-3","1.08-1","1.01-1-1A"},B$10:B$20,0)))),0))
Note that the start row is not the first row and the array is used 3 times in the function.
Code to try to convert the string to a text array
Not working but if wrapped in SUMPRODUCT() it provide an array to the SUMPRODUCT() function, of course not usable since I then can't pass on the array. The background to this code can be found in question Split a string (cell) in Excel without VBA (e.g. for array formula)!.
=TRIM(MID(SUBSTITUTE(A10,",",REPT(" ",99)),(ROW(OFFSET($A$1,,,LEN(A10)-LEN(SUBSTITUTE(A10,",",""))+1))-1)*99+((ROW(OFFSET($A$1,,,LEN(A10)-LEN(SUBSTITUTE(A10,",",""))+1)))=1),99))
The second code output the first item of the array and inserted in the first code do not change this result as it did when wrapping the second code in SUMPRODUCT().
Here is a picture of my simplified test setup in Excel for this case, identical to what is described above.
Simplified test setup
I'm not really sure what you are doing with your formula.
But to convert contents of a cell to a comma separated text array to be used as the array argument to the INDEX or MATCH functions, you can use the FILTERXML function. You'll need to educate yourself about XML and XPATH to understand what's going on, but there are plenty of web resource for this.
For example, with
A10: "1.01-1","1.01-3","1.08-1","1.01-1-1A"
The formula below will return 1.08-1. Note the 3 for the row argument to the INDEX function.
=INDEX(FILTERXML("<t><s>" & SUBSTITUTE(SUBSTITUTE(A10,"""",""), ",", "</s><s>") & "</s></t>", "//s"),3)
I have a struct array imported from a tab file, with 100+ name\double rows. The first row has a character value (name\char). I'm trying to load this as a matrix and converted it to cells, removing the top row entirely.
But when I use cell2mat(array), it has the error:
All contents of the input cell array must be of the same data type.
I know this is from the Names vs. double columns. But is there a way to convert this to a matrix? Or, if the data is rows of
name | 1000x1 double
is it better just to leave this as a cell array?
It's not possible to have a matrix containing both strings and numeric values. If you want something like that, cell array is your only option. But, it will be very limiting if you want to process the numeric values using matrix/vector operations, or functions that expect matrices/vectors as input. One option would be to store the strings and numeric data separately; keep the strings in a cell array S and the numeric data in a matrix M. Then, keep track of the elements. For example, S{i} and row M(i, :) could both correspond to entry i from your original table. Another option would be to make your own data structure using struct(), which can contain both strings and numeric values.
What I would like to do is to count the amount of lines that matches criterias to be verified in two arrays.
I can't use VBA, add new columns (for instance a new column with VLOOKUP formula) and preferably use arrays.
I have two separate ranges, each with a ID column for the identifier and other fields with data.
For instance, range 1:
Range 2:
If I had only to check the first range I would do:
={SUM((D4:D7="Red") * (E4:E7="Big"))}
But I don't know how to check also using data from the other range.
How, for example, to count the number of items that are Red, Big and Round by using both Ranges ?
Put this in the cell F4:
=IF((VLOOKUP(C4,$C$11:$D$12,2)="Round")*(D4="Red")*(E4="Big"),1,"")
Note that the behavior of VLOOKUP is that it finds the value up to the first parameter. Since there's no 1 in your second dataset, this first cell is going to show "#N/A", which I don't know how to solve, but when you extend this formula down to also compare the other sample data in the first set, the ID numbers 2 and 4 will show up as "yes" for you.
Edit: You wanted a count of this list. So after this, it should be easy to get a count of cells in this column using the COUNT function.
Try this array formula
=SUM((D4:D7="Red")*(E4:E7="Big")*ISNUMBER(MATCH(C4:C7,IF(D12:D13="Round",C12:C13),0)))
The last part is the added criterion you want - the IF function returns {2,4} [IDs where Data 3 is "Round"] and then you can use MATCH to compare C4:C7 against that. If there is a match you get a NUMBER (instead of #N/A) so you can then use ISNUMBER to get TRUE/FALSE and that feeds in to your original formula - result should be 2