Sumifs with logical OR using cell references - excel-formula

I am using sumifs with OR as shown below:
=SUM(SUMIF(B:B,{"Apples","Oranges"},C:C))
The above works fine but instead of Apples and Oranges I want to use the cell reference that contains this text as shown below:
=SUM(SUMIF(B:B,{D4,D5},C:C))
Apparently "There's a problem with this formula". How do I fix this?

Use SUMPRODUCT to avoid the need for Ctrl+Shift+Enter, and just put the full range reference without the {}:
=SUMPRODUCT(SUMIF(B:B,D4:D5,C:C))
If the range is not consequitive then you will need to change the formula to something like:
=SUMPRODUCT(SUMIF(B:B,CHOOSE({1,2},D4,D7),C:C))

Related

In Excel, is it possible to construct an array with formulas inside it?

In Google Sheets, it's possible to create an array with formulas with in it. For example, ={SUM(1,2);SUM(3,4)} evaluates to a column with the numbers 3 and 7.
When I try the same thing in Excel, I get a formula syntax error. Is a similar thing possible? I've also tried putting names defined with LET in an array, but that throws the same error.
Thanks!
You can use CHOOSE function to combine formulas in array:
=CHOOSE({1;2},SUM(1,2),SUM(3,4))
formula works for O365, for earlier versions select desired count of cells and enter formula in first cell as array formula (with CSE).

MS Excel: COUNTIFS doesn't work when A criteria cell is empty

I would really appreciate some help whit my problem. I tried to read about it but nothing I found works.
I am trying to pull some data from another spreadsheet based on multiple criteria /entered in cells B4:B6/.
B4 - Customer Name
B5 - FROM Date
B6 - TO Date
I want to be able to extract data based on only one cell or any combination of them.
/B4&B5,B4&B6,B5&B6,B4&B5&B6/
I tried using the following formula:
COUNTIFS(JOBS!$C$1:$C$10000,$B$4,JOBS!$L$1:$L$10000,">="&$B$5,JOBS!$L$1:$L$10000,"<="&$B$6)
The formula works fine if all cells /B4:B6/ are filled but returns #NUM! if one is empty.
I tried:
COUNTIF(JOBS!$C$1:$C$10000,$B$4)+COUNTIF(JOBS!$L$1:$L$10000,">="&$B$5)+COUNTIF(JOBS!$L$1:$L$10000,"<="&$B$6)
The formula works fine if only one cell /B4:B6/ is filled but the data overlaps if 2 or more are filed.
Use wildcards when empty:
=COUNTIFS(JOBS!$C$1:$C$10000,IF($B$4="","*",$B$4),JOBS!$L$1:$L$10000,">="&IF($B$5="",0,$B$5),JOBS!$L$1:$L$10000,"<="&IF($B$6="",99999,$B$6))
In fact the formula I am using looks very weird. The positions of criteria and range appeared to be switched.
The original formula looks like this:
COUNTIFS($B$4,JOBS!$C$1:$C$10000,$B$5,<="&JOBS!$L$1:$L$10000,$B$6,">="&JOBS!$L$1:$L$10000)
And it is working fine, apart from the problem I mentioned in the title.
Thanks to the idea Scott gave me I have rewritten my formula and now it looks like this:
COUNTIFS($B$4,IF($B$4="","",JOBS!$C$1:$C$10000),$B$5,IF($B$5="","","<="&JOBS!$L$1:$L$10000),$B$6,IF($B$6="","",">="&JOBS!$L$1:$L$10000))
Although, I am not sure if this is the right way the formula should be written, it works great and my problem is now solved.

Data validation gives error normal cell doesnt

I have this formula
=OFFSET(Products[[#Headers];[Merk]];
MATCH(A2;Producten!$A:$A;0)-1;1;COUNTIF(Producten!$A:$A;A2);1)
It works fine in a normal cell. But as soon as I putt it in the Data Validation>List I get the error.
There is a problem with this formula.
Not trying to type a formula?
Does anybody know what the problem is?
Suggest to change the reference to the Table for the cell address (e.g. assuming the table starts at B6 and Merk is the 1st field then change Products[[#Headers];[Merk]] for B6).
Not all formulas that are valid for Cells are accepted by DataValidation, particularly when they refer to a ListObject for example the formula COUNTA(Products[Merk])is valid in a Cell but not accepted by DataValidation
Formula should be:
=OFFSET(B6;
MATCH(A2;Producten!$A:$A;0)-1;1;COUNTIF(Producten!$A:$A;A2);1)
When referring to a table in a validation formula you cannot refer directly to a table and must use intermediate names.
For example, define a name like this:
_name_Product that is equal to: ="Products[[#Headers];[Merk]"
Then use INDIRECT in the formula:
INDIRECT(_name_Product)
or use entries like INDIRECT("Products[[#Headers];[Merk]")
Hope this helps.

COUNTIFS with greater than TODAY OR blank cell

I have a question regarding COUNTIFS. The simple boiled down version of what I am trying to do is this:
I am trying to use COUNTIFS to count the number of entries that the cell in a column is either blank or in the future (greater than today) and that is marked with an “X” in another column.
There are several other renditions in the formula but if I can get this, I can get the rest. So far, I have this:
=SUM(COUNTIFS($C$2:$C$50,{"";">"&TODAY()},$E$2:$E$50,"X"))
Excel won’t let me return out of the formula and highlights the quotation mark following the greater than symbol.
=SUM(COUNTIFS($C$2:$C$50,{"";">100"},$E$2:$E$50,"X")) works fine when I play around and test things but when I try to add in &TODAY() or reference a cell, things go sideways.
Any suggestions as to what I am doing wrong? The actual formula is quite long and there are several comparisons that are made between columns. I've seen some references to using SUMPRODUCT but haven't been able to figure it out that way either.
You can use a formula to generate the criteria array, i.e.
=SUMPRODUCT(COUNTIFS($C$2:$C$50,IF({1;0},"",">"&TODAY()),$E$2:$E$50,"X"))
I used SUMPRODUCT in this version because with SUM you'd need CTRL+SHIFT+ENTER
The IF function generates an array that resolves to something like this:
{"";">43060"}

Multiple values for an AND/OR statement

Is it possible to combine AND (or OR) statement criteria to avoid repeating a cell name?
For example, I want to see if cell C2 contains the any of the numbers 2,3,5,7, or 10. I want to avoid writing
IF(AND(C2=2,C2=3... etc.
and simplify it to an array of the numbers like
IF(AND(C2=[2,3,5,7,10]...
Unfortunately, I have a lot more than just 5 numbers to add so it's getting be very laborious. Anyone have an easier way than repeating the cell name=__ over and over?
You can use an "array constant" like this
=IF(OR(C2={2,3,5,7,10}),"Yes","No")
.....or for a large set of numbers you could put all the numbers in a cell range, e.g. Z2:Z100 and do the same
=IF(OR(C2=$Z$2:$Z$100),"Yes","No")
although when you use a range rather than an array constant the formula becomes an "array formula" so needs to be confirmed with CTRL+SHIFT+ENTER
perhaps better to use COUNTIF and avoid "array entering"...
=IF(COUNTIF($Z$2:$Z$100,C2)>0,"Yes","No")
=IF(ISERROR(MATCH(C2,{2,3,5,7,11},0)),"no","yes")
No need to enter this as an array formula. How it works: MATCH returns a #N/A! error if it can't find the lookup value in the lookup array. ISERROR catches this.
But as barry houdini suggests, you may want to put your numbers in some range e.g. Z1:Z5 instead of hard-coding them into your formula. So you would have this formula instead:
=IF(ISERROR(MATCH(C2,Z1:Z5,0)),"no","yes")

Resources