I'm trying to sum only if a value from a collection is not in a set list of values.
Given:
and
and
I've Tried:
=SUM(SUMIF(M7:M10,"<>" & X2:X4,H7:H10))
I should Expect to see 10,000 (for row 8) But it keeps returning a nonsensical value (120,000).. How can I modify this to correctly SUMIF not in the range.
You can use Array/CSE formula:
=SUM(IF(COUNTIF($X$2:$X$4,M7:M10)=0, H7:H10, 0))
Just hit Ctrl+Shift+Enter to enter that in so it gets the squirrelly brackets around it.
Or you can hit it with sumproduct and some sneaky boolean logic to avoid the array formula:
=SUMPRODUCT(NOT(COUNTIF($X$2:$X$4,M7:M10))*H7:H10)
Take one of the answers in your other thread and substract it from:
SUM(H7:H10)
That is:
=SUM(H7:H10)-SUM(SUMIF(M7:M10,X2:X4,H7:H10))
Entered as an Array Formula
Related
If you have a CSE array constant as follows in cell A1:
{={2,4,6,8}}
How can you get a specific element from the array constant? I tried the following formulas but they all return the first value of the array constant (2).
=INDEX(A1, 0)
=INDEX(A1, 1)
However, it does work if the array is not a reference. The following formula returns the 3rd element (6).
=INDEX({2,4,6,8},3)
Thank you
You could put the array constant in a Name instead of a cell.
Then INDEX will work with it properly with no implicit intersection.
Or you could parse the formula using the FORMULATEXT function, but that sounds tedious.
Try =INDEX(A1#,1). The # tells excel that A1 is a spill formula (more than 1 cell long). The array index starts at 1, not 0 in this case.
As a side note, Index knows you are referring to an index, not a row, when you give it a 1D array. In your example =INDEX(A1#,4) and =INDEX(A1#,1,4) return the Fourth item in your array (8 in this case), but =INDEX(A1#,4,1) will give you the error #REF!. If you define your array vertically {={2;4;6;8}}, =INDEX(A1#,4) and =INDEX(A1#,4,1) both work.
Edit: It looks like this does not always work in Excel 365 when a an array formula is created using Ctrl+Shift+Enter. I think this is due to the changes in 365. Array formulas have pretty much been replaced with spill formulas. Entering ={2,4,6,8} is mostly equivalent to a pre-365 array formula, but creating an array formula with Ctrl+Shift+Enter confines the output to as many cells as selected. In Dan's case, he selected only one cell and the formula doesn't automatically spill, so the formula is confined only to that cell. Excel seems to treat that cell as if it only contains that array element. If you select 2 cells and enter an array formula then =INDEX(A1#,2) will work but =INDEX(A1#,3) returns #REF!.
Edit2: It is possible with the FORMULATEXT Function as #DickKusleika suggested. Here is a function adapted from ExcelJet that does the job.
=LET(
DesiredIndex, 1,
ArrayFormulaRef, A1,
Formula, FORMULATEXT(ArrayFormulaRef),
FormulaLen, LEN(Formula),
CSVStart, FIND("{",Formula,2),
CSV, MID(LEFT(Formula,FormulaLen-1),CSVStart+1,FormulaLen),
TRIM(MID(SUBSTITUTE(CSV,",",REPT(" ",LEN(CSV))),(DesiredIndex-1)*LEN(CSV)+1,LEN(CSV)))
)
=ADDRESS(3,1) 'evaluates to $A$3
=ROW($A$3) 'evaluates to 3
Why can't I nest them?
=ROW(ADDRESS(3,1)) 'Gives an error.
Try:
=ROW(INDIRECT(ADDRESS(3,1)))
instead of using ADDRESS which returns a string, consider using INDEX which will return a cell reference. The general format of INDEX is:
INDEX(Range you want to look in, rows down from top row, columns right for first column)
so in order to reference your whole sheet like address would you would need to select the range of the entire sheet:
=INDEX($A$1:$XFD$1048576,3,1)
The above formula actually returns the cell reference of $A$3 ($ is due to 3 and 1 being hard coded) then turns around and displays the contents of $A$3. As a result you don't actually see the $A$3. On the interesting side of things it also means you can define a range with INDEX(...):INDEX(...). To finish off your formula you would nest the INDEX in your ROW function as follows:
=ROW(INDEX($A$1:$XFD$1048576,3,1))
This avoids the use of the volatile function of INDIRECT and some of its other restrictions.
I have the below formula that Lookup the A1:A10 appropriated Score Number.
{=INDEX(Table1[ScoreNum],MATCH(A1:A10,Table1[ScoreWord],0))}
I need calculate the AVERAGE result of this entire array.
But when using this:
{=AVERAGE(INDEX(Table1[ScoreNum],MATCH(A1:A10,Table1[ScoreWord],0)))}
Returns the first looked up result with Index/Match, against returns the average of all returnable values whit this array formula.
How can do that?
The sample Workbook file
Sheet1
Sheet2: Table1
Note: The formula in B11 is: =AVERAGE(B1:B10) and returns the true value. I need return this without using the B helper column, directly in a single cell (A11) with the true form of formula shows in the picture.
Very truly yours.
Another method:
=AVERAGE(INDEX(Table1[Column2],N(IF({1},MATCH(A1:A10,Table1[Column1],0)))))
also entered as an array formula.
I would use, instead, this array-formula:
=AVERAGE(AVERAGEIF(Table1[Column1],A1:A10,Table1[Column2]))
To enter/confirm an array formula, hold down ctrl + shift while hitting enter. If you do this correctly, Excel will place braces {...} around the formula seen in the formula bar.
The AVERAGEIF function returns the array {1;0.8;1;0.2;0.6;0.8;1;1;0.6;0.2} which is what you are showing in your column B in your screenshot.
We then AVERAGE that array by nesting the AVERAGEIF(.. within the AVERAGE function.
I have a worksheet with the following contents in A1:G1
7 8 4 2 9 11 10
Formula
=SUMPRODUCT(MIN($B1:$G1-$A1)) (1)
evaluates to -5,
=SUMPRODUCT(ABS($B1:$G1-$A1)) (2)
evaluates to 18. But
=SUMPRODUCT(MIN(ABS($B1:$G1-$A1))) (3)
gives #VALUE!.
To try to understand the issue, I use Formula Auditing -> Evaluate Formula.
In the formulas that work (1 and 2), $A1 is evaluated (underlined) first.
In the formula that doesn't work (3), $B1:$G1 is evaluated (underlined) first.
What is the reason for the error, and the different behavior among formulas?
As per my comment, to get the smallest difference between A1 and B1:G1 without using an "array entered" formula you can use INDEX to do what you were trying to do with SUMPRODUCT, i.e.
=MIN(INDEX(ABS($B1:$G1-$A1),0))
It looks like you are using the SUMPRODUCT function to make this formula work as an array formula and that Excel is not calculating your third formula as an array, giving you a #VALUE error when the formula is entered in column A. It did not give me this error in the columns B through G, but it also did not calculate as an array. Entering your formula as an array formula by pressing Shift+Ctrl+Enter after typing in your formula will fix this. You can also get the same result using a simpler formula:
=MIN(ABS($B1:$G1-$A1))
Once this is entered as an array formula, you will be able to step through the evaluation and see it working correctly.
More info on arrays here: http://office.microsoft.com/en-us/excel-help/introducing-array-formulas-in-excel-HA001087290.aspx
Summarizing the comments by Brad and barry houdini (originally this):
The documentation says the ABS takes a number as its input, that MIN takes an arbitrary number of numbers, and SUMPRODUCT takes an arbitrary number or arrays. Seems like when the ABS is nested so deep it defaults to taking the number and can't figure out how to return an array.
So to counteract that we can use INDEX round ABS and get the correct result without "array entry" and without SUMPRODUCT, i.e. =MIN(INDEX(ABS($B1:$G1-$A1),0)).
This shows the right way of entering the formula, and it explains the cause of the error.
I think you were on course to investigate this using 'Formulas > Evaluate Formula'
The results are for typical math operations: functions are evaluated from the inside out.
Because =SUMPRODUCT(MIN(ABS($B1:$G1-$A1))) is not forced to evaluate as an array $B1:$G1 will return the value from that array from the same column from where the calling cell is located. I.e. if B2 = then $B1:$G1 will return B1, if A2= $B1:$G1 then it will try to return A1 but there is nothing to return so it gives you the #VALUE error.
I have a situation where I need to calculate ontime vs. late in a range of cells.
I use the if statement =IF(N2>K2 +30,"Late","") and this works fine however I would like to combine the countif statement to count the range of cells that contain "late"
Thanks
Try this:
=SUM(IF(N:N>K2+30,1,0))
Enter it as array formula by pressing CTRL+SHIFT+ENTER.
updated if you only need to count the number of lates.
As per Roberto's comment, if you are actually using a formula to put "Late" in column L for each relevant row you can use a simple COUNTIF to count those
=COUNTIF(L:L,"Late")
or if you want to use the source data in column N just use COUNTIF with that
=COUNTIF(N:N,">"&K2+30)