COUNTIFS function not working with single cell range - excel

I'm having an issue with COUNTIFS function in excel, i have a very large formula that I was getting an error on, but I have slowly taken the formula apart to a smaller subset and identified the issue I'm having. Excel won't use COUNTIFS correctly when the criteria range is one cell. Here's the formula I'm using:
=COUNTIFS(A7:A7,1,Sheet1!F:F,$A$9,Sheet2!S:S,$B$8)
Whenever I take the first criteria out "A7:A7,1" my formula returns a value, without it I receive #VALUE! error. Can you not use one cell as the criteria for CountIFS? I've also tried replacing "A7:A7" with just "A7" or "$A$7". The first criteria is the most important, because i'm going to be using a listbox for that cell that will change the values in my range for interactive graphs..

The ranges in the countifs need to be the same size.
Wrap the COUNTIFS() in a IF:
=IF(A7=1,COUNTIFS(Sheet1!F:F,$A$9,Sheet2!S:S,$B$8),0)

Related

Using COUNTIFS in Excel, check cells (containing formulas) that are empty

Good day.
In it's basic form, I need to count how many cells are empty.
Using the following below, I can count how many cells are empty.
=COUNTIF(Sheet1!C:C,"<>")
However, if the cells in column C contain formulas, it won't work.
After some googling, I found out that using SUMPRODUCT will get what I need
=SUMPRODUCT(--(LEN(Sheet1!C:C)>0))
Now, here's my problem.
I need to use that as a criteria inside a COUNTIFS function, but I don't know how to do that because it's referencing some ranges.
So just to make it simple, using COUNTIF or COUNTIFS function specifically, how can I pass a criteria that checks if cell (with formula) is empty.
This formula returns 0 but most likely I'm just not passing it properly as a criteria.
=COUNTIF(Sheet1!C:C,SUMPRODUCT(--(LEN(Sheet1!C:C)>0)))
Happy for other ways to count cells (with formulas) which are empty, but I need to use it as a criteria for a COUNTIF/COUNTIFS function.
Thank you very much.
If I understand what you're looking for, you were pretty close already.
Following the formula's you already found you can use them like:
=COUNTIF(Sheet1!C:C,"<>")-SUMPRODUCT(--(LEN(Sheet1!C:C)>0))
It will result in the count of cells that have a value/formula minus the count of cells that show a value (blank formula result is excluded).
The result is the count of cells that contain a formula with blank result.

Excel error - formula contains SUMIFS, and OR and Some Dates

I'm trying to get the formula below to work but I'm getting a #Spill! error
Adding Feb-20 works fine but adding the Mar-20 appears to break something.
=SUMIFS(Calcs!CZ:CZ,Calcs!$AL:$AL,{"Feb-20","Mar-20"},Calcs!$AJ:$AJ,"<>"&"")
I think that due to the later additions into excel, the modern interpretation of array criteria is that for each of your criteria, it produces an array of answers, so you are getting #Spill! because excel is trying to make your single celled sumifs formula spill into two cells, each using a single criteria of your array criteria:
one cell having this formula in:
=SUMIFS(Calcs!CZ:CZ,Calcs!$AL:$AL,"Feb-20",Calcs!$AJ:$AJ,"<>"&"")
and the other cell having this formula in:
=SUMIFS(Calcs!CZ:CZ,Calcs!$AL:$AL,"Mar-20",Calcs!$AJ:$AJ,"<>"&"")
The spill error is likely because the cell adjacent to the cell you are performing this sumifs formula in has something in it.
documentation on this here:
https://www.excelcampus.com/functions/dynamic-array-formulas-spill-ranges/
My suggestion therefore is to simply wrap your current formula with a final sum, like this:
=SUM(SUMIFS(Calcs!CZ:CZ,Calcs!$AL:$AL,{"Feb-20","Mar-20"},Calcs!$AJ:$AJ,"<>"&""))

Median Calculation in Excel with Conditions

I am having trouble getting the following Excel formula to work. I think I am having an issue with my parenthesis. I am trying to take the median based off of 3 conditions. The last condition is a date range.
=MEDIAN(IF($G$3:$G$458=$K$3,IF($A$3:$A$458=M$3,IF(AND($E$3:$E$458>DATEVALUE("1/1/2014"),$E$3:$E$458<DATEVALUE("12/31/2014")),$H$3:$H$458))))
Your formula is correct you just need to hit CTRL+SHIFT+ENTER to make it an array formula.
Whenever you apply a formula (E3:E458=$E$458) to a range within one cell you need to make the calculation an array formula.

Formula returns #VALUE! when entered as array

I've put together an Excel spreadsheet to keep track of employees' time off using an array formula. The formula works for date ranges that are entered as "mm/dd - mm/dd", but I'd like it to also support single dates "mm/dd". However, I get a #VALUE! error when one of the cells in the range is of this format, even though the formula supports both formats when not entered as an array formula.
Example:
With the value "11/28" in cell B2, and a table of holidays in B31:B37, the following formula accurately calculates the number of work days as 1.
=SUM(IF(ISBLANK(B2),0,(IF(ISERR(FIND("-",B2)),NETWORKDAYS(B2,B2,$B$31:$B$37),NETWORKDAYS(LEFT(B2,5),MID(B2,FIND("- ",B2)+2,5),$B$31:$B$37)))))
If the value of B2 is "11/28 - 12/03", the formula returns 4.
I want this formula to work over a range of of cells for each employee, so I expand the range from "B2" to "B2:B10", and enter as the following array formula:
=SUM(IF(ISBLANK(B2:B10),0,(IF(ISERR(FIND("-",B2:B10)),NETWORKDAYS(B2:B10,B2:B10,$B$31:$B$37),NETWORKDAYS(LEFT(B2:B10,5),MID(B2:B10,FIND("- ",B2:B10)+2,5),$B$31:$B$37)))))
This formula works fine when every cell in the range is blank or has a date range of "mm/dd - mm/dd". However, if one of the cells has a single date "mm/dd", it throws a #VALUE! error.
What am I missing?
If there is no "-" in a given string then the FIND function will return a #VALUE! error for that string.
In general, there are two ways to resolve such issues. One is to include an error trap; the other, slightly longer though perhaps nevertheless preferable (IFERROR clauses are generally best avoided if possible), is to make suitable amendments to the strings being passed to MID and FIND such that this combination of functions does not error, whilst also ensuring that correct results are returned.
One such solution (still array-entered) is:
=SUM(IF(B2:B10<>"",NETWORKDAYS(LEFT(B2:B10,5),MID(B2:B10&"- "&B2:B10,FIND("- ",B2:B10&"- ")+2,5),$B$31:$B$37)))
Regards

Reusing of formula driven result in a if statement in excel

=IFERROR(IF((INDEX(named range1,MATCH(named range2&A1,named range3,0)))<>"",INDEX(named range1,MATCH(named range2&A1,named range3,0)),"-"),"")
Here in this formula I am trying to vertical lookup a value using index-match and checking it within a if statement for blank value.If it is not blank I am using the non-blank value to set it in a given cell.
How can I optimise my formula to reduce performance overhead in excel.
I don't want to use vba for this by storing the result in a variable
The most time consuming bit is the Match(), so avoiding a duplication of the same Match is key. You can
place the Index/Match in a helper cell and then use the formula
=IFERROR(IF(B1<>"",B1,"-"),"")
This way the Index/Match will be calculated only once.
place the Match into a named formula. If you keep your wits about you, named formulas can work with relative cell references. Select the cell where you want the formula to go, then create a named range "NamedRange4" with the formula
=MATCH(named range2&A1,named range3,0)
Then use this formula in the selected cell:
=IFERROR(IF((INDEX(named range1,NamedRange4))<>"",INDEX(named range1,NamedRange4),"-"),"")
The Match will be calculated only once and the result stored in the named range. With relative cell referencing of NamedRange4, the IfError formula can be used in other cells with correct results.

Resources