I have a curious question about using the "OR" in an excel SUMIF.
Basically, in a
SUMIF(A:A,"Cat" OR "Dog", C1:C10)
How can I use the OR function in an excel SUMIF function?
You need to wrap the different OR parameters into curly brackets and enclose the whole Sumif in a SUM function, because Sumif will return an array of values that need to be summed up.
Also, the two ranges need to be the same size.
=SUM(SUMIF(A1:A10,{"cat","dog"}, C1:C10))
Related
I am attempting to use an array formula with multiple criteria in an AVERAGEIFS formula.
=AVERAGEIFS('sheet1'!$R:$R,'sheet1'!$B:$B,{"a","b","c","d","e","f","g","h","i"},'sheet1'!$A:$A,Q$2)
The formula only seems to be calculating the first criteria that is within the array ("a").
I searched the forums, but I am not seeing anything that directly relates to this this.
Any and all help would be greatly appreciated!
The trick when using an array inside something like AVERAGEIFS is to then wrap it in AVERAGE. However, this will take the average of the averages which is probably not what you want. This method however does work well with Counts and Sums from which you can make your own average.
=SUM(SUMIFS(SumRange,CriteriaRange,{"a","b","c"}))/SUM(COUNTIFS(CriteriaRange,{"a","b","c"}))
This will be the same answer as if you had used Average(<select only the cells with "a", "b", "c" values>)
And to elaborate on how the Average(AverageIfs()) process works you can see the difference when you Evaluate your formula
There AverageIfs only regarded the first argument of the array.
However when it is returning a value to another function which itself can take an array as an argument the array is preserved
Similar questions to this have been asked but not exactly like this. There is one that is very close, but that solution is not working for me.
I have a function which returns comma separated values into a cell. I would like to pass the elements in that cell as criteria to a SUMIFS function using an approach like this one.
My attempt is pictured below:
I believe that this is somehow tied to the way that the function is understanding what is in cell G8. It looks like it is adding some extra quotes. If I highlight G8 in the formula bar and press F9, I get:
There are extra quotes on each side of each criteria.
I am open to a custom VBA function solution, but I would prefer something which can be built as a worksheet function. The criteria are returned from a custom VBA function that pulls elements out of a list box and does some regex work to remove extra commas. The number of elements that can be selected is variable so I would like to avoid having to split the criteria into more than one cell. Thanks.
Seems that the raw comma-separated criteria is in G6, All you need is to split this criteria into an array and feed it to SUMIFS. Splitting is available in VBA, but not exposed to Excel. All we need is to write a little UDF that does the splitting of the CSV and use it in our formula:
Function splitCSV(str As String)
splitCSV = Split(str, ",")
End Function
Now the formula in F10 would be:
=SUM(SUMIFS(C3:C10, B3:B10, "blue", A3:A10, splitCSV(G6)))
EDIT
The above is an array formula (Ctrl+Shift+Enter). To have it a normal formula we can use SUMPRODUCT instead of SUM. This leads to more flexibility (normal formula vs array formula) as well as some "expected" performance improvement.
=SUMPRODUCT(SUMIFS(C3:C10, B3:B10, "blue", A3:A10, splitCSV(G6)))
I'm trying to utilize the syntax for OR like criteria for a COUNTIFS function in Excel. However, when trying use cell references, it just tells me
There is a problem with this formula
Function: =SUM(COUNTIFS(rosterTable[lastDayWithClient], {">="&A7,""}))
Specifically if I'm trying to use &A7 to concatenate the criteria with a cell value, it fails.
">="&A7 is not an allowed entry in an array constant.
Per Excel Help: Array constants can contain numbers, text, logical values (such as TRUE and FALSE), and error values.
As #ScottCraner indicated, you can accomplish the same by summing separate COUNTIF functions. The AGGREGATE function, or various types of SUMPRODUCT implementations may also provide a solution.
Tryingto CountIf with Exclusions and multiple criteria,
Here's an example of just multiple critera:
=SUM(COUNTIFS(A1:A9,"YES",B1:B9,{"JOHN","GEORGE","RINGO","PAUL"}))
Here's an example of just exlusion:
=SUM(COUNTIFS(A1:A9,"YES",B1:B9,"<>*JOHN*"))
And here's the sum we're currently got but not working:
=SUM(COUNTIFS(A1:A9,"YES",B1:B9,{"<>*JOHN*","<>*GEORGE*","<>*RINGO*","<>*PAUL*"}))
When criteria becomes too complex for COUNTIFS, you can often use an array formula. I think the following array formula will achieve your goal...
=SUM(IF(A1:A9="YES",1,0)*(IF(ISNUMBER(FIND("JOHN",B1:B9)),0,1))*(IF(ISNUMBER(FIND("GEORGE",B1:B9)),0,1))*(IF(ISNUMBER(FIND("RINGO",B1:B9)),0,1))*(IF(ISNUMBER(FIND("PAUL",B1:B9)),0,1)))
Make sure to use CTRL+SHIFT+ENTER to enter the array formula.
I have this Array formula that Works good:
{=SUM(IF(Range1="L";Range*Range))/SUM(IF(Range1="L";Range))}
But if I change SUM(IF to SUMIF doesn't work I don't know why.
{=SUMIF(Range1;"L";Range*Range)/SUMIF(Range1;"L";Range)}
And I want to put SUMIFS, because I want to add a new IF in the first formula, like this:
{=SUMIFS(Range*Range;Range1;"L";Range2;"N")/SUMIFS(Range*Range;Range1;"L";Range2;"N")}
What I can do to put two ifs in the array formula?
SUMIF and SUMIFS are already array formulas (somewhat) and they don't take well to range multiplication. You can use the two criteria in a SUM(IF, or in a SUMPRODUCT, e.g.
=SUM(IF(AND(Range1="L",Range2="N"),Range*Range,0))
=SUMPRODUCT((Range1="L")*(Range2="N")*Range*Range)