I'm trying to perform a sumproduct function on two arrays. I'd like to find a way of asking excel to select the first array if the column match a certain value.
In my simplified case if the value is "1" pick the first array and perform sumproduct with the array below A ...something that prevent me from spending the day nesting if (obviously a formula like =SUMPRODUCT(IF(O4=1;F4:F8;IF(O4=2;G4:G8;IF(O4=3;H4:H8;IF(O4=4;I4:I8))));L4:L8) works but in my real case is no use)
=SUMPRODUCT((O4=$F$4:$I$4)*$F$4:$I$8*$L$4:$L$8)
I'd like to create a formula that creates multiple arrays based on an if statement, multiplies the arrays, and then sums the products.
So if these are my arrays:
I'd like to sum their product if A doesn't equal 0. My current formula works, but I'd like to be able to do this with only one if statement.
=SUMPRODUCT(IF(A1:A5<>"",A1:A5%),IF(A1:A5<>"",B1:B5))
Try...
=SUM(IF(A1:A5<>"",(A1:A5%*B1:B5)))
...which needs to be confirmed with CONTROL+SHIFT+ENTER.
I want to use COUNTIF function to evaluate how many items out of 2,0,0,5 are greater than 2? In Countif function, first argument is range and second is criteria. I have tried the below formula. Even tried using Ctrl+Shift+Enter at the end to evaluate. But doesn't seem to work.
=COUNTIF({"2","0","0","5"},">2")
COUNTIF doesn't accept array constants (as far as I know). Try this:
=SUMPRODUCT(--({2,0,0,5}>2))
You could also create a countif-style formula like this (the combination ctrl+shift+enter):
=COUNT(IF({2,0,0,5}>2,1,""))
Recommended reading:
Array vs Range
Some functions like Offset, SumIf, CountIf, SumIfs, and CountIfs are designed to operate only on (multi-cell) range objects. Sum, SumProduct, Frequency, Linest, lookup functions, etc. take both range and array objects.
Array means: {2,0,0,5}
Range means:
To use countif, you have to use range in cells, defining the array in the formula on the go will not work.
=COUNTIF(A1:A4,">"&2)
I know this thread is a few years old, but I ended up here with a similar problem (how to use arrays, not ranges, with countif).
Although my end goal was a little different (I wanted to find items common to two arrays), I figure the workaround I came up with might be useful for others: I ended up using the "match" function coupled with "isnumber". The formula looked like this:
=isnumber(match({a},{b},0))
this will return an array of true/false which corresponds to the values in {a} that are also in {b}. In case it wasn't clear, {a} and {b} are arrays...
I have an array formula that looks like this:
{=SUMIF(C11:C23,budgets,F11:F23)}
What I want it to do is sum cells F11:F23 where cells C11:C23 are values within the named range budgets.
Right now budgets has two values: 10361 and 10300 (these are transaction codes). However, the formula seems to only work for the first code 10361 but not for the second one.
I don't want to use SUMIFS because I have multiple worksheets where I would like this array formula to work, and the codes may change so changing them in one place (the named range budgets) will make things easier.
Any ideas? I don't know VBA, so was hoping for a formula solution.
Use SUMPRODUCT with COUNTIF():
=SUMPRODUCT((COUNTIF(budgets,$C$11:$C$23)>0)*$F$11:$F$23)
Or you can use this array formula:
=SUM(SUMIF(C11:C23,budgets,F11:F23))
Being an array it needs to be entered with Ctrl-Shift-Enter when exiting edit mode instead of Enter. If done properly Excel will put {} around the formula.
I was surprised to find that in Excel you can divide a range in the SUMPRODUCT function (per this answer: https://stackoverflow.com/a/13650170/50899). Note that this doesn't require the use of array formulas (i.e, pressing ctrl+shift+enter is not necesary)
=SUMPRODUCT(1/A1:A3, B1:B3) <= note the division operator
But why can you NOT do it for, e.g., =SUM(1/A1:A3)?
To which functions can it be applied?
And what is the name of this feature?
SUMPRODUCT does array calculations under the covers, but SUM does not. Array entering {SUM(A1:A3/10)} gives the same answer as SUMPRODUCT(A1:A3/10) but SUMPRODUCT does not need array entering because Excel already knows that its an array processing function.