PRODUCT array formula containing INDIRECT not working - arrays

Can anybody see why this array formula isn't working?:
{=PRODUCT(IF(INDIRECT(F7)=1,INDIRECT(AM7)))}
NB: the cells to which the cell references refer each contain ranges, e.g. $E$3:$E$6 is in F7.
And these range reference strings have been generated by, for example:
=ADDRESS(K7,MATCH("N",$5:$5,0))&":"&ADDRESS(L7,MATCH("N",$5:$5,0))
For the avoidance of doubt, 3 is in K7 and 5 is in L7.
Cheers

Related

Transpose array in countifs formula - error

The picture gives a schematic representation of the data. Columns up to 17th in the actual spreadsheet is the raw data entries.
First I sort Brand according to SUMIF and add the Brand Month Sorted into an array - ArrayCurrentMonth.
Then I add individual categories into Specialty Array.
Now what I want is to countifs number of entries with COUNTIFS formula for columns that are schematically pictured 9-12 using ArrayCurrentMonth and Specialty as Range arguments in SUM(COUNTIFS(.. function
Thus 10-12 - ArrayCurrentMonth transposed ;
Column 9 - Specialty Values
Rammaged through earlier Q&A's and found useful variants, that seems to work for others, but for me on Transpose I stubbornly get Sub or Function Not defined no matter how i use it - with Range or with Array.
ActiveSheet.Range(X;Y) = Application.WorksheetFunction.Sum(Application.WorksheetFunction.CountIfs(Range("C:C"), RTrim(Month(Mesyaz1)), Range("H:H"), "Headephones", Transpose(Range("F:F"), ArrayCurrentMonth(c)), Range("L:L"), Specialty(g)))
or
ActiveSheet.Range(X;Y) = Application.WorksheetFunction.Sum(Application.WorksheetFunction.CountIfs(Range("C:C"), "Month1", Range("H:H"), "Product1", Transpose(ArrayCurrentMonth), Range("L:L"), Specialty(g)))
or any other way I could think of just to check how it would work.
I would try looping For g=1 etc but I guess I need some Transpose anyhow
Would be grateful for some tips.

formula to generate array with variables such as =B1/B2, etc

How does one generate an array whose elements are cell values or math operation of cell values? For example, how does one generate an array of {0,1,A1,B1}) or {8,3,A1/B1,A1*B1} or {0,1,A1/B1-2, A1*B1+3}?
I have not found anything on the net regarding this topic.

using OFFSET with an array of columns then SUMPRODUCT

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.

Get Row and Column Totals from 2d Array in Excel

I wanted to know how to get row and column totals from a 2D array in Excel. This is a fairly common thing to do but I couldn't find an answer to it by searching on row and column totals so I thought it would be worth posting it as a question.
Supposing I wanted to find the lowest column total and highest row total in the following array which is in cells A1:D3:-
1 2 3 4
5 6 7 8
9 10 11 12
my initial thoughts were along the lines of
=min(A1:D3*(column(A1:D3)={1,2,3,4}))
but this kind of simple approach doesn't work. I remembered reading that you had to use mmult in some of these situations and have seen advanced formulae using them but couldn't quite remember how. I shall try and answer my own question but other suggestions are more than welcome.
You can do it with MMULT as you mentioned. The following should work with your setup:
Smallest column
=MIN(MMULT({1,1,1},A1:D3))
Largest row:
=MAX(MMULT(A1:D3,{1;1;1;1}))
Note how many 1s in the array - for the rows calc you need a 1 for each column (i.e. 3) and vica versa for columns. Also note the order of the arrays - it won't work the other way around
Yes you have to mmult to deliver either a column array or row array containing the required totals, then use can use MAX, MIN or any other aggregate function to get the value you require.
Column totals
=MIN(MMULT(TRANSPOSE(ROW(A1:D3))^0,A1:D3))
Row Totals
=MAX(MMULT(A1:D3,TRANSPOSE(COLUMN(A1:D3))^0))
So the idea is that you create a single-row array {1,1,1} and multiply it by the 2D array to end up with an array {15,18,21,24} and take the minimum value from it.
Or create a single-column array {1;1;1;1} and multiply the original array by it to end up with an array {10;26;42} from which you get the maximum value.
Remember that mmult works like the matrix multiplication you might have learned at college where for each cell it works across the cells in the corresponding row of the first array and down the cells of the corresponding column in the second array multiplying each pair and adding them to the total. So the number of columns in the first array must always equal the number of rows in the second array.
These are, as #Scott Craner reminds me, array formulae that have to be entered with
Ctrl Shift Enter

Change array dimensions, using spreadsheet functions, when used inside SUMPRODUCT

I am interested in spreadsheet functions, not VBA solutions, to be included in a single cell formula.
[A1:A15 contain numeric values from 1 to 127, B1:B15 contain integers from 1 to 7 that set a divisor.]
Given the function:
=SUMPRODUCT(MOD(FREQUENCY(A1:A15;A1:A15);B1:B15))
FREQUENCY(A1:A15;A1:A15) gives a 1-column array of 15+1 rows, whereas the second part (B1:B15) is a 1-column array of 15 rows.
I would like to change the resulting array given by FREQUENCY (only in memory -not explicit in sheet-) from a 1-column 16 rows array to a 1-column 15 rows array with the first 15 cell values of that array.
[FREQUENCY documentation: https://support.office.com/en-us/article/FREQUENCY-function-44e3be2b-eca0-42cd-a3f7-fd9ea898fdb9 NB: for Excel, second remark states number of elements that depend on bins_array. ]
I would appreciate suggestions.
Thus, both arrays within MOD will have the same dimensions and SUMPRODUCT will not find cells with error values. I can disregard error values using IF and ISERROR within SUMPRODUCT, but I'd rather disregard the non-relevant part of the FREQUENCY resulting array if it is possible.
It has been thought that making it more specific might be more helpful, so it has been heavily reduced and simplified.
With external help, I have been able to fine-tune a way to solve my problem using INDEX in array formula mode. I am posting the answer in case it helps others.
One way: Put FREQUENCY(A1:A15;A1:A15), or any formula that produces an multi-cell array, within INDEX and have 2nd and/or 3rd arguments as array of consecutive values which will represent rows/columns.
INDEX(FREQUENCY(A1:A15;A1:A15);ROW(INDIRECT("1:" & ROWS(FREQUENCY(A1:A15;A1:A15)-1));1)
First argument within INDEX is the resulting array coming from a formula to shrink (from 16x1 to 15x1), which would be a multi-cell array formula if explicitly entered; second argument is the array 1..15 given by row numbers from 1 to the number of total rows of the "array from formula to shrink" MINUS 1: the first 15 (out of 16) values in the array from a formula; 3rd argument is the column of the shrank array (if need be, more than one could be selected using an analogue to the second argument).
In the particular case of FREQUENCY, because it is known that we are interested in the "bins" part of the function, the formula can be simplified by including the total rows of the "bins"/"intervals" array inside FREQUENCY (its second argument). We will have
INDEX(FREQUENCY(A1:A15;A1:A15);ROW(INDIRECT("1:" & ROWS(A1:A15)));1)
and the complete formula would become
SUMPRODUCT(MOD(INDEX(FREQUENCY(A1:A15;A1:A15);ROW(INDIRECT("1:" & ROWS(A1:A15)));1);B1:B15))
Now, both dividend and divisor of MOD have exactly the same dimensions (15x1) and because B1:B15 includes integers greater than 0 there are no errors.
Thanks all for helping me in making question more concise and better formatted.
ADDITIONAL INFORMATION: As pointed out correctly in comments by XOR LX, this does not seem to work in the widely popular spreadsheet software Excel. It has been developed for an INDEX function inside SUMPRODUCT as used in Open Office Calc which I had mistakenly thought 100% equivalent to Excel's version. A more complete answer perhaps using other functions would be appreciated.
In the previous answer, XOR LX points out very correctly that this formula cannot work in Excel, due to row_num/column_num argument behaviour. Very kindly XOR LX has shown me how that approach can work, and also thanks and credit for supplying a good answer: "INDEX can be used to redimension array (even dynamically created ones) if the row_num/column_num array is coerced to take an arbitrary array with the right dimensions, as shown on this blog entry " The following formula has been checked in Excel 2010 and has the expected results:
SUMPRODUCT(MOD(INDEX(FREQUENCY(A1:A15,A1:A15),N(INDEX(ROW(INDIRECT("1:" & ROWS(A1:A15))),,)),1),B1:B15))
NB: row_num argument of first INDEX, a ROW generated auxiliary array, has been nested inside N(INDEX([...],,)); at least one comma is necessary to account for the two arguments minimum of the nested INDEX. It is in itself interesting the discussion that applies generally to INDEX's arguments, and other functions', that need to be coerced to take arrays (see, here and here at XOR LX's blog). For Open Office users it might be worth stressing the point made at the blog
Unlike OFFSET, (...) for which the first parameter must be a
reference (...) in the worksheet, INDEX can also accept –
and manipulate – for its reference arrays which consist of values
generated e.g. via other subfunctions within the formula. XOR LX's blog
That would be indeed the case in changing the dimension in an array as in this question, but also useful in reversing or displacing the values in an array, for example. Open Office accepts arrays as row_num/column_num, so the coercion is not needed and some formulas rely on this, but without it, these formulas are unlikely to work when files are open in Excel.
Regrettably, this type of coercion is not passed correctly to Open Office, and formula need to be "decoerced" to work, at least in my casual tests.
In order to use a formula that would work in both spreadsheet programs regarding shortening arrays, the only thing I have managed is the following (required: arrays must be single-column)
SUMPRODUCT(
(COLUMN(INDIRECT("R1C1:R"& ROWS(vals_to_mod) &"C"& ROWS(FREQUENCY(vals_for_freq,vals_for_freq)),FALSE))
-ROW(COLUMN(INDIRECT("R1C1:R"& ROWS(vals_to_mod) &"C"& ROWS(FREQUENCY(vals_for_freq,vals_for_freq)),FALSE))
=0)
*MOD(TRANSPOSE(FREQUENCY(vals_for_freq,vals_for_freq)),vals_to_mod)
)
(it "shortens" one array to the shortest of the pair, by creating an auxiliary array with TRUE/1s on the diagonal starting top-left and FALSE/0s elsewhere, therefore disregarding all defined values outside the square section of the array. Thus, SUMPRODUCT adds values within the diagonal of the square section which are the product of the corresponding values up to the last value of the shorter array.)

Resources