Sumproducts #value! error - excel

I am trying to use the Sumproducts function, but get the #VALUE error
The code looks like this:
=SUMPRODUCT('Combined Output Table'!AO4:BH4,'ECAP CONSTANTS'!B2:I2)
Both arrays are made up percentage values.
I use the second array in a Sumproducts function elsewhere where it works perfectly, and i have checked that the first array is only made up of number values (in percentage format). Neither array has any characters or non-number values.

The two ranges need to be the same size, in your formula the first range is 20 cells, the second is only 8, so I don't know which cells should be multiplied but this should make it work
=SUMPRODUCT('Combined Output Table'!AO4:BH4,'ECAP CONSTANTS'!B2:U2)
Second range to finish at U2, making it the same size as the first range

Your ranges aren't the same size. It makes no sense for the algorithm to try to multiply some value by some value that is not present, thus all the ranges in a SUMPRODUCT() must always match in size.

Related

Error when finding MAX ABS using indirect function in VLOOKUP

I am trying to set up a sheet that I can use as a template to sort data, find perticular values and create a chart. Everything is working fine for the maximum magnitude and average magnitude values I am looking for. I am running into an issue in the formula in the images attatched. Below is the full code.
=VLOOKUP(MAX(ABS(INDIRECT("J"&P3&":J"&Q3))),INDIRECT("J"&P3&":M"&Q3),4,FALSE)
With this code I am fining the maximum value in the vertical direction, then returning the corresponding magnitude value.
When I was just inputting the cell values it was working fine (taking a long time but it was working) however to make it quick and easy to apply to the other data files (they are in the same layout with the same number of values but have different values) I have adjusted it to the above formula.
In the P and Q columns I have found the row of the top and bottom of the ranges I am interested in and then have substituted these values into my working formula.
This method works great for the average magnitude and maximum magnitude so I know it should work, but when used the formula above it finds the incorrect value. For some reason it evaluates an array to a single value that is the second in the list.
1: evaluated formula before the miss-step (the array that is the range I am looking for)
2: evaluated formula after the miss-step (3.5 which is not close to the maximum absolute value)
Any help would be great.
You cannot convert the max(abs(...)) and use that for the lookup; that only works for positive numbers. You need to pass processing to a second VLOOKUP if the first fails with IFERROR.
You would be better off with a slightly more advanced sub-formula that can retrieve the absolute maximum than using an array formula to achieve the same.
Additionally, the non-volatile INDEX can replace the volatile INDIRECT.
As a non-array formula,
=iferror(vlookup(max(max(index(j:j, p3):index(j:j, q3)), abs(min(index(j:j, p3):index(j:j, q3)))), index(j:j, p3):index(m:m, q3), 4, false),
vlookup(-max(max(index(j:j, p3):index(j:j, q3)), abs(min(index(j:j, p3):index(j:j, q3)))), index(j:j, p3):index(m:m, q3), 4, false))
In other words, if you cannot find the max(abs(...)) then look for the -max(abs(...)).

Use of ROW() or COLUMN() in OFFSET(...) generating #N/A! error

I want to have a cell at the top of a column of data which uses a worksheet function to record the total number of cells below it which contain data. There are no gaps in the column, so I figure I don’t need to use COUNTA, it would be more efficient to find the first blank cell. To this end I have the following function in cell R12:
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12,1,0,1000,1)),0),0)-1
This worked fine until I tried to use a named reference cell to define the resized range a bit more flexibly… replacing the above with
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12,1,0,ROW(last_cell)-ROW(),1)),0),0)-1
gives #N/A! in the cell. As a formula =ROW(last_cell)-ROW() works fine on its own so it’s a puzzle to me why it doesn’t work in the compound formula… even replacing a 1 in the OFFSET parameters with ROW(A1) throws an error.
I can work round it, but this behaviour is really annoying! Can anyone shed any light on this?
The problem you are having is that the OFFSET function is expecting a long integer as its [height] parameter and you are shoving an array of integers at it. Yes, there is only one integer in the array but it is still an array and OFFSET is jumping ship at the first sign of potential trouble. If you evaluate the formula as suggested by Grade 'Eh' Bacon above, you will see that the result of that simple math subtraction is wrapped in braces (e.g. { and } ). You need to remove any indication that the [height] parameter is being fed an array or OFFSET will keep choking.
=MATCH(TRUE,INDEX(ISBLANK(OFFSET($R$12, 1, 0, MIN(ROW(last_cell)-ROW()), 1)),0),0)-1
There are any number of basic Excel worksheet functions that can take an array of 1 and turn it into an integer. I've used the MIN function. MAX, SUM, AVERAGE, etc. would all work. They take an array of numbers and return a single integer, even if that array of numbers has only one number.
On a related topic, I find it admirable that you are trying to reduce the calculation cycles in your workbook but you are missing one important consideration. The first thing you should do is throw out the OFFSET function altogether.
=MATCH(TRUE,INDEX(ISBLANK($R$12:INDEX($R:$R, ROW(last_cell)+1)), , ), 0)-1
OFFSET is a volatile formula that recalculates whenever anything in the workbook changes. Opting for the INDEX function equivalent takes the formula out of volatile mode and it will only recalculate when something that affects its outcome changes.
You may be interested in the way OFFSET erroneously treats floating point errors. See OFFSET_Floating_Point_Error for more on that.
Having had a chance to play around a bit, I'm still confused!
OFFSET itself doesn't seem to have a problem accepting the return values of ROW and COLUMN as parameters. To use a trivial example, this formula works:
=COUNTBLANK(OFFSET($R$12,ROW(1)+1,0,ROW(R20)-COLUMN(),1))
Trying different ways of eliminating OFFSET from the expression, I came up with:
=MATCH(TRUE,INDEX(ISBLANK(INDIRECT(ADDRESS(13,18)&":"&ADDRESS(1012,18))),0),0)-1
Which works, at the cost of swapping OFFSET for INDIRECT (which I'm hoping is the lesser of 2 evils!) However I would prefer to use:
=MATCH(TRUE,INDEX(ISBLANK(INDIRECT(ADDRESS(ROW()+1,COLUMN())&":"&ADDRESS(ROW(last_cell),COLUMN()))),0),0)-1
Which doesn't work, giving #N/A! again, as does changing any of the explicit integers to ROW or COLUMN expressions.
Individually, I've tried OFFSET, INDEX, ISBLANK and MATCH with ROW and COLUMN expressions and they all seem to work, so it seems to be something about using them in compound formulae which is throwing the error.

Conditional Maximum in Excel using Array Formulae - how to ignore Blank Rows

There are quite a few questions on Stack Overflow about doing a conditional MIN and MAX in Excel
e.g. Excel: Find min/max values in a column among those matched from another column
However, I don't think the following question is covered.
Normally the MIN and MAX functions will ignore blank rows, however it seems that if used in conjunction with a conditional array formula then they will NOT ignore.
For instance
If I enter the array formula =MAX(IF(A1:A8="A",B1:B8)) then I get zero, when I really want to see -1, since of all the non-blank 'A' rows, the maximum is -1.
I thought that the following array formula would work =MAX(IF(AND(A1:A8="A",B1:B8<>""),B1:B8)) but it ALWAYS returns zero
You nearly had it! However, in an array formula, you cannot replicate an "AND" construction so straightforwardly, in essence since the return from the AND function is always a single value, never an array.
Hence, your attempt:
=MAX(IF(AND(A1:A8="A",B1:B8<>""),B1:B8))
would initially correctly resolve to (using the values you posted):
=MAX(IF(AND({TRUE;FALSE;TRUE;FALSE;TRUE;FALSE;TRUE;FALSE},{TRUE;TRUE;FALSE;TRUE;FALSE;TRUE;TRUE;FALSE}),B1:B8))
though the AND function would then look at that those two arrays of Boolean TRUE/FALSE returns and return a single value, i.e. FALSE (since there is at least one FALSE amongst those 16 entries).
The correct syntax would be:
=MAX(IF(A1:A8="A",IF(B1:B8<>"",B1:B8)))
Regards
you can test for blank in the if, and substitute an appropriate value if found.
The Array formula =MAX(IF(A1:A8="a",IF(ISBLANK(B1:B8),-999,B1:B8))) will substitute the value -999 for any blank cells, allowing you to find you maximum - alter the -999 depending on how low your numbers get

Excel, Array Formulas, N/A outside of range, and ROW()

I have a problem with ROW() in an array formula in Excel 2013.
Example:
I make a named range, called 'input', say 4 cells wide and 10 high. Then I make an array formula =ROW(input) one cell wide, 15 cells high.
I get 10 numbers - the first is the first row of input, and the rest count up from that, and then 5 #N/A follow. This is as it should be.
If instead of =ROW(input) I try one of the following:
=IFERROR(ROW(input),"x")
or
=IF(ISNA(ROW(input)),"x",ROW(input))
to catch the #N/As then what I expect to see is ten numbers, and then five x's. Instead I still see ten numbers and then five #N/As.
Can anyone tell me how to solve this problem? I want to get ten numbers, and then five x's.
And of lesser importance but just for curiosity (or in case it comes up in another case), why does this happen?
Why do I want to do this? It's part of a larger formula that I have simplified for this question.
I believe that, in such clauses, Excel gives precedence to the artificial expansion of the reference to match that of the worksheet range selected (which it will always do by filling with #N/As) over first resolving the IF clause over the array.
So, whereas "normally" (e.g in a single-cell array formula), e.g.:
=SUM(IF(ISNA(ROW(input)),"YES","NO"))
would, effectively, coerce Excel into expanding the single value_if_true and value_if_false parameters of the IF function into syntactically-appropriate arrays of those values, viz:
=SUM(IF({FALSE;FALSE;FALSE;FALSE;FALSE},{"YES","YES","YES","YES","YES"},{"NO","NO","NO","NO","NO"}))
i.e.:
=SUM({"NO";"NO";"NO";"NO";"NO"})
with multi-cell array formulas, e.g. your:
=IF(ISNA(ROW(input)),"YES","NO")
entered over a 10-cell range, is NOT first resolved thus:
=IF(ISNA({1;2;3;4;5;#N/A;#N/A;#N/A;#N/A;#N/A}),{"YES";"YES";"YES";"YES";"YES";"YES";"YES";"YES";"YES";"YES"},{"NO";"NO";"NO";"NO";"NO";"NO";"NO";"NO";"NO";"NO"})
(In which the the value_if_true and value_if_false parameters are first re-dimensioned in accordance with the dimension of the worksheet range in which the array is being entered.)
i.e.:
=IF({FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;TRUE;TRUE;TRUE},{"YES";"YES";"YES";"YES";"YES";"YES";"YES";"YES";"YES";"YES"},{"NO";"NO";"NO";"NO";"NO";"NO";"NO";"NO";"NO";"NO"})
i.e.:
={"NO";"NO";"NO";"NO";"NO";"YES";"YES";"YES";"YES";"YES"}
but rather as:
=IF(ISNA({1;2;3;4;5;#N/A;#N/A;#N/A;#N/A;#N/A}),{"YES";"YES";"YES";"YES";"YES";#N/A;#N/A;#N/A;#N/A;#N/A},{"NO";"NO";"NO";"NO";"NO";#N/A;#N/A;#N/A;#N/A;#N/A})
(The value_if_true and value_if_false parameters first being re-dimensioned in accordance rather with the dimensions of the Named Range input.)
i.e.:
=IF({FALSE;FALSE;FALSE;FALSE;FALSE;TRUE;TRUE;TRUE;TRUE;TRUE},{"YES";"YES";"YES";"YES";"YES";#N/A;#N/A;#N/A;#N/A;#N/A},{"NO";"NO";"NO";"NO";"NO";#N/A;#N/A;#N/A;#N/A;#N/A})
i.e.:
{"NO";"NO";"NO";"NO";"NO";#N/A;#N/A;#N/A;#N/A;#N/A}
Hope that helps a bit.
Regards

Why this array formula doesn't work?

On the illustration all formulas are array. The range that each formula spans is bordered, and the first formula on each block is written on the top of that block.
Range A4:A103 is an input vector (which is numeric), range C4:G23 is a given (input) permutation of the rows of A4:A103 (necessarily positive non-zero integer numbers not greater then the length of the input vector).
Let us I interpret the permutation matrix as set of rows.
How to compute for each row in a constant number of cells the minimal number in the input vector? By the constant number of cells, I mean solution, that would require fixed number of cells for each row, regardless of the number of columns in permutation. (In the production case each dimension is much, much bigger; there is about 100 columns in the permutation matrix.)
I don't ask for VBA solutions. If it is necessary the solution can use a free and publicly available Excel add-on, like MoreFunc, but I'd prefer to keep it vanilla Excel 2007 or later.
I thought that the formula {=MIN(INDEX(INDIRECT($A$2);$C4:$G4))} would solve my problem. Surprisingly, Excel seems to not take into account the array nature of the formula, and evaluates it as if it was written as =MIN(INDEX(INDIRECT($A$2);$C4) which is equivalent to dysfunctional =INDEX(INDIRECT($A$2);$C4).
On the other hand, we can see the argument to the MIN is understood as array in the range I4:M4.
INDEX works in some strange ways!
Normally INDEX can't return an array - although you seem to have found the one exception to that - when it's an array formula entered in a range.
You should be able to use OFFSET to return the required array that will work within MIN, i.e. with this formula
=MIN(N(OFFSET(INDIRECT($A$2);$C4:$G4-1;0)))
confirmed with CTRL+SHIFT+ENTER

Resources