When I highlight and 'f9' the components of an array formula it will compute the answer correctly, but doesn't work normally - excel

So I have replicated the error with dummy data here.
I am trying to populate C2:C5 with the totals from the value column in the rawdata table that correspond to the values in B2:B4 multiplied by the looked up values in type table.
when I highlight the respective arrays in the Sumproduct formula and leave them as values they are calculating correctly, but for some reason the formula doesn't work as is.
=SUMPRODUCT(RawData[Value],--($B2=RIGHT(RawData[Vehicle],LEN($B2))),OFFSET(Multiplier[[#Headers],[Multiplier]],MATCH(RawData[Type],Multiplier[[Type ]],0),0))
EDIT:
I have a sumproduct formula with three arrays, the first is a column full of values, the second is a list of bools and the third is a list of multipliers.
The formula is returning 0 even when all criteria are met.
I have identified that it is the third array of multipliers that is causing the problem. If I highlight that section of formula, hit F9 and convert it to values, the whole thing calculates correctly. but when it is left as a formula it is returning 0.

Just in case anyone in the future has a similar issue, I think it's the offset part of the function.
=SUMPRODUCT(RawData[Value],--($B2=RIGHT(RawData[Vehicle],LEN($B2))),OFFSET(Multiplier[[#Headers],[Multiplier]],MATCH(RawData[Type],Multiplier[[Type ]],0),0))
You can in this situation use sumif instead:
=SUMPRODUCT(RawData[Value],--($B2=RIGHT(RawData[Vehicle],LEN($B2))),SUMIF(Multiplier[[Type ]],RawData[Type],Multiplier[Multiplier]))
credit to /u/rnelsonee
/r/excel Thread

Related

Excel CountIfs with an or condition on Dates

Looking to try and find the following in Excel but am having issues getting this to work.
I have Dates in Column A which need to be checked against Dates in the Query Column to compare. I want to count all records where the comparison column is greater than the date in A5 or is an empty cell. There are other conditions that I will also want to check but cannot seem to get this to work.
=COUNTIFS(Query1[Purchased Date],OR(Query1[Purchased Date]="",Query1[Purchased Date]>A5))
use:
=SUMPRODUCT(--((Query1[Purchased Date]="")+(Query1[Purchased Date]>A5)>0))
You can use an array function instead of countif.
Suppose your dates are in the range A2:A25 and your reference date is in cell B2.
If you type in any other cell
=SUM((A2:A25>B2)+(A2:A25=""))
and hit Ctrl+Shift+Enter it will give you the count you want.
This happens because Excel will resolve the first inner parentheses (A2:A25>B2) as an array of TRUE/FALSE, and does the same to the second (A2:A25=""). Next it will sum them, which is equivalent to the OR operation, and yields as a result an array of zeros (FALSE) and ones (TRUE). It wraps up by summing this array (with the function sum), all in one cell.
Perhaps this is more of a comment than an answer, but in this particular case you can just add the two separate totals:
=COUNTIF(Query1[Purchased Date],"")+COUNTIF(Query1[Purchased Date],">"&A5)
because the conditions are mutually exclusive.
Whether this helps or not depends on what additional criteria you want to add.
BTW there are two issues with your original formula:
(1) If you are combining lists of values with OR logic, you have to use addition instead (as in the two answers which use Sum or Sumproduct).
(2) The syntax of a Countif or Countifs where the range has to be kept separate from the criteria won't let you do what you want to do, so this again leads you to Sum or Sumproduct.

How do I use an array formula over a whole column or varying range?

I have a spreadsheet that I'm importing data into. I need to find the value within a column that is closest to zero. The column contains both positive and negative values, and the value closest to zero will be used in another formula. I've found an answer using an array formula, but it will only work for a fixed range (e.g. K2:K10), and the number of records imported into my sheet will vary each time I use it.
Here's what I have so far:
=INDEX(K:K,MATCH(MIN(ABS(K:K)),ABS(K:K),0))
Is there a way to apply an array formula over an entire column and just include non-zero cells other than the column title? Or possibly just cells with numerical values? Or is it possible to control the range that it applies to?
We can dynamically find the last cell in the range by using another INDEX/MATCH formula that is not an array:
=INDEX(K:K,MATCH(1E+99,K:K))
This will find the last cell that has a number in column K.
So we now use this as the last cell in the range:
=INDEX($K$2:INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS($K$2:INDEX(K:K,MATCH(1E+99,K:K)))),ABS($K$2:INDEX(K:K,MATCH(1E+99,K:K))),0))
And now the formula is dynamic.
This formula is still an array formula and must be confirmed with Ctrl-Shift-Enter when exiting edit mode. If done correctly then Excel will put{} around the formula.
If as you pointed out there is a chance of deleting row 2 then all the K2 references will also be deleted.
In place of K2 we can use INDEX(K:K,2) It will now always look at the second row and will not error when row 2 is erased. So use this instead:
=INDEX(INDEX(K:K,2):INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS(INDEX(K:K,2):INDE‌​X(K:K,MATCH(1E+99,K:K)))),ABS(INDEX(K:K,2):INDEX(K:K,MATCH(1E+99,K:K))),0))
There is nothing wrong with the Offset() function in small amounts, but it is a volatile function. Which means that it will calculate EVERY TIME excel calculate whether the data to which it is dependent has changed or not.
For the benefit of anyone reading this post, I ran into another issue and found a way around it. Scott Craner's answer above worked well until I ran a macro that I had for that sheet, which would delete certain rows. If row 2 got deleted, the formula would give a #REF error, because it was trying to call $K$2.
My solution was to replace $K$2 with
OFFSET(K1,1,0)
Therefore, the complete formula would be:
=INDEX(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K)),MATCH(MIN(ABS(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K)))),ABS(OFFSET(K1,1,0):INDEX(K:K,MATCH(1E+99,K:K))),0))
And as Scott mentioned, remember to hit Ctrl-Shift-Enter to execute the array formula.

CountIf cell value meets a condition

Hi I have a row of calculated values that I need to count based on a condition.
I have the conditions working in conditional formatting so that is the condition is met the cell changes color, however I need to find the totals of each color.
=AND($V1/$Z1>0.5, $V1/$Z1<=0.79)
so for this I want to only count values if this statement is true
=COUNTIF(Z:Z, (AND($V1/$Z1>0.5, $V1/$Z1<=0.79)))
currently this returns 0 when there is 10 values that meet this criteria
does anyone know if countif can be used like this?
I can see your issue, I've had a play around and am unable to crack it, if you wish to keep it in a singular cell you'll probably need to go down the route of an array formula. Its probably complicating it too much and you should look to have a helper column,
in Column AA, have the formula =$v1/$z1, then for your count write:
=countifs(AA:AA,">0.5",AA:AA,"<=0.79")
This can be done without a helper column using the Sumproduct() function.
=SUMPRODUCT(--($V$1:$V$100/$Z$1:$Z$100>0.5),--($V$1:$V$100/$Z$1:$Z$100<=0.79))
or
=SUMPRODUCT(($V$1:$V$100/$Z$1:$Z$100>0.5)*($V$1:$V$100/$Z$1:$Z$100<=0.79))
This will count all instances where the values in V1 to V100 divided by the values in Z1 to Z100 are between 0.5 and 0.79
Note that SumProduct is essentially an array formula (even though it does not require confirmation with Ctrl-Shift-Enter, but it evaluates each range as an array), so you don't want to use it with whole column references. If you want to retain calculation speed, make sure to refer to used rows only, not gazillions of empty cells.

SUMIF with several OR criteria

The blue cell summates to 1, but that is not correct and it should summate to more because of the row text match with B47 row. Any ideas what's wrong?
SUMIF is not supposed to work with more than one criteria (you can't check multiple criteria within one SUMIF as you tried in your formula).
This formula will calculate the right result for you: =SUM(B3:BI3*(IFERROR(MATCH(B2:BI3,B47:AL47,0)>0,0))), this is an array formula, so you need to press CTRL+SHIFT+ENTER after it.
MATCH(...): look for all students whether they are in the list with requirments (this is the part which works only as array formula)
IFERROR(...): converts #N/A errors to 0
If I am not wrong, you are trying to calculate the number of students for a particular project with skill1 and skill2.
You may also try using COUNTIFS() function. This works for multiple criteria.

CountIf and Subtotal

I have a series of data columnar that I am wanting to use a countif for visible cells only that have the value 1. I can do either formula with no problem, CountIF, or SubTotal for visible cells, however when I try to combin them I get lost. Here is an example of my formula segments.
=CountIf(I5:I6500,1)
=SubTotal(3,I5:I6000)
How do I combine the two formulas to have a single formula that counts all instances of the number 1 in a column while not counting hidden cells due to filtering???
Desert Spider,
This worked for me:
=SUMPRODUCT(--(I5:I6000=(C12)),SUBTOTAL(3,OFFSET(I5,ROW(I5:I6000)-ROW(I5),0)))
OR (the above uses another cell value to determine your query, the below uses your user input (X))
=SUMPRODUCT(--(I5:I6000="X"),SUBTOTAL(3,OFFSET(I5,ROW(I5:I6000)-ROW(I5),0)))
Credit to:
pgc01
http://www.mrexcel.com/forum/excel-questions/600223-subtotal-countif.html#post2971937
Filter on ColumnI (as well) to select 1 and the count should appear at the bottom left of your screen (just to the right of Ready, so no formula may be needed.

Resources