I have the following Excel spreadsheet:
A B C
1 50 20 =IFERROR(A1/B1,"") = 2.5
2 60 0 =IFERROR(A2/B2,"") = ""
3 80 0 =IFERROR(A3/B3,"") = ""
4 10 50 =IFERROR(A4/B4,"") = 0.2
5
6 COUNT: 2
7
In Cell C6 I want to count the number of items in the list which are not " " according to Column C.
I tried to do this with the following formula:
=COUNTIF(C1:C4;"<>""")
However, this formula gives me back the value 4 instead of 2.
Therefore, I guess the issue is related to the IFERROR functions which I use in Column C.
Do you have any idea how I have to change the COUNTIF formula to only count the cells without " "?
I know - in this specific case - I could solve the issue by using the COUNTIF formula over Column B. However, I would prepfer a solution that goes over Column C.
Instead of COUNTIF use SUMPRODUCT as
=SUMPRODUCT((C1:C4<>"")*1)
This can be tricky. I usually count the blanks using COUNTBLANK and take that away from the total count
`=COUNTA(D1:D4)-COUNTBLANK(D1:D4)`
Also because in this case your output is the result of a division you could use =COUNTIF(D1:D4,">-1") to count everything with a value zero or above.
Please see https://www.ablebits.com/office-addins-blog/2014/07/02/excel-countif-examples/#countif-blank
In your example, the formula could be
=COUNTIF(C1:C4;"")
Related
Excel
A B C D E F
1 4 400
2 0
3 700
4 0
5 300
6 0
7 0
8 100
9
In the above Excel table I have values in different cells.
In cell A1 I want to count the number of cells that contain a value <> 0.
Therefore, I tried to go with this formula:
A1 = COUNTIF((D1,E2,F3,D4,D5,F6,F7,E8),0)
However, with this formula I get #VALUE!.
I assume the issue is that the array for the COUNTIF formula is not in one row.
One way of solving the issue would be to make a helper column in which I put all the values in one row but I am wondering if there is another way of doing it without any helper column?
If using a non-continuous range is a must you could use:
=SUM(COUNTIF(INDIRECT({"D1","E2","F3","D4:D5","F6:F7","E8"}),"<>0"))
Note that this is volatile!
This is a problem due to your regional settings.
By default, Excel uses the list separator defined under regional settings in Control Panel. The US English version of Excel uses a comma (,) for list separator by default, while other international versions may use a semicolon (;). Try to put a semicolon between range and condition.
A1 = COUNTIF(D1,E2,F3,D4,D5,F6,F7,E8; 0)
It's a bit more typing but if you are intent on using specific cells:
=SUM(D1<>0,E2<>0,F3<>0,D4<>0,D5<>0,F6<>0,F7<>0,E8<>0)
The D1<>0 test will return TRUE or FALSE. In the SUM() function, Excel treats TRUE as 1, and FALSE as 0. And you don't have to use INDIRECT() which can store up trouble for the future.
I am trying to do STDEVP on a range of cells matching date range. I did not find STDEVPIFS. I would like to know how I can accomplish this?
We have excel rows like this. I need a formula for Column E which is standard deviation for 3 months multiplied by num days A. Num days cannot be 90 (3 months) as we need to include only working days and not saturday / sunday or holiday.
FORMULA1 = STDEVP(ColumnB[between[C1 & D1]])* SQRT(NUM A ROWS BETWEEN C1 & D1)
FORMULA2 = STDEVP(ColumnB[between[C2 & D2]])* SQRT(NUM A ROWS BETWEEN C2 & D2)
ROW A B C D E
1 03-01-2007 1-1-2007 31-3-2007 FORMULA1
2 04-01-2007 0.000495 1-4-2007 30-6-2007 FORMULA2
3 05-01-2007 -0.00662 1-7-2007 30-9-2007
4 08-01-2007 0.002055 1-10-2007 31-12-2007
5 09-01-2007 -0.00055 1-1-2008 31-3-2008
6 10-01-2007 0.002059 1-4-2008 30-6-2008
..
..
60 30-03-2007 0.004350
01-04-2007
If there is not a FUNCTIONIF or FUNCTIONIFS then using {=FUNCTION(IF(...))} instead can be the alternate. This is an array formula which uses the array returned by IF as a function parameter for the surrounding FUNCTION.
Such array formulas can be entered in Excel by typing in the formula without the curly brackets. Then press Ctrl+Shift+Enter. Then the curly brackets are added automatically.
In your example, if column A contains only the working days, then the {=STDEVP(IF...))} would be:
{=STDEVP(IF(($A$1:$A$1000>=$C1)*($A$1:$A$1000<=$D1),$B$1:$B$1000))}
In array formulas one should not using whole column references since those contain more than one million cells in modern Excel versions.This would lead to performance issues. That's why do using $A$1:$A$1000 instead of $A:$A and $B$1:$B$1000 instead of $B:$B.
The counting the number of days would be:
=COUNTIFS($A$1:$A$1000,">="&$C1,$A$1:$A$1000,"<="&$D1)
I am not clear about the sense of your complete formula. That's why please put it together your own.
I need to compare two sets of two columns and find the count of number of IDs that match a certain criteria.
A B C D E
ID: ListNum: RefNum: List2Num: Ref2Num:
1 10 5 12 6
2 3 7 10 2
3 12 8 1 5
4 2 15 13 4
5 4 11 2 8
6 6 9 1 3
Let's say that the cell containing ID = "1" is A2 and it goes down to A7
I have to count the number of IDs that have a ListNum that is higher than the RefNum AND also have a List2Num that is higher than Ref2Num. Both criteria must be satisfied in order to count the ID.
I used the following formula: =COUNT(IF(B2:B7 > C2:C7) & (D2:D7 > E2:E7))
I get a value, but it's not the right count (it's taking the total for both conditions rather than only counting it once). The final answer should be 1. Any help would be appreciated, thank you!
One reason why yours didn't work: In your formula you use & to mean AND, but & actually concatenate strings.
Option 1: Array Formula
IF and AND don't work on arrays so a normal formula containing them won't work. So use an array formula instead:
You need to enter this as an array formula (you need to press control-shift-enter instead of enter when you put the formula in):
=SUM((B2:B7 > C2:C7)*(D2:D7 > E2:E7))
When it is in the cell it will display in braces to show it is an array formula. Like so:
{=SUM((B2:B7 > C2:C7)*(D2:D7 > E2:E7))}
In this formula the X>Y will return 1 or 0 for true or false. So multiplication is the same as AND and addition is the same as OR. Then (B2:B7 > C2:C7)*(D2:D7 > E2:E7) means B2:B7 > C2:C7 AND D2:D7 > E2:E7 and it returns an array of 1 and 0 which are then summed up to get the count.
Option 2: SUMPRODUCT
There is a normal function whose sole purpose is to multiply arrays together and then add them up the same way as the array formula does: SUMPRODUCT
The problem with SUMPRODUCT is that the arrays must be numbers and not logical true and false values so any of these works:
=SUMPRODUCT(--(B2:B7 > C2:C7),--(D2:D7 > E2:E7))
=SUMPRODUCT((B2:B7 > C2:C7)*1,(D2:D7 > E2:E7)*1)
=SUMPRODUCT((B2:B7 > C2:C7)+0,(D2:D7 > E2:E7)+0)
And this does not:
=SUMPRODUCT((B2:B7 > C2:C7),(D2:D7 > E2:E7))
But SUMPRODUCT is a normal function so you don't need to enter it with control-shift-enter.
Try entering this formula into cell F1:
=IF(AND(B1 > C1, D1 > E1), 1, 0)
Then just take the sum of the F column for however many rows you really have, and you should be left with the answer (which is 1 for the sample data you gave above).
If you put a simple AND formula next to your table, you can autofill that all the way down. Next, you could count the number of True values in that column (see pic). You could combine into an IF statement as Tim suggests.
The two formulas would be
"=AND(B2>C2,D2>E2)"
"=COUNTIF(G2:G7,TRUE)"
Link to picture of possible solution
I have googled for hours, not being able to find a solution to what I need/want. I have an Excel sheet where I want to sum the values in one column based on the criteria that either one of two columns should have a specific value in it. For instance
A B C
1 4 20 7
2 5 100 3
3 100 21 4
4 15 21 4
5 21 24 8
I want to sum the values in C given that at least one of A and B contains a value of less than or equal to 20. Let us assume that A1:A5 is named A, B1:B5 is named B, and C1:C5 is named C (for simplicity). I have tried:
={SUMPRODUCT(C,((A<=20)+(C<=20)))}
which gives me the rows where both columns match summed twice, and
={SUMPRODUCT(C,((A<=20)*(C<=20)))}
which gives me only the rows where both columns match
So far, I have settled for the solution of adding a column D with the lowest value of A and B, but it bugs me so much that I can't do it with formulas.
Any help would be highly appreciated, so thanks in advance. All I have found when googling is the "multiple criteria for same column" problem.
Thanks. That works. Found another one that works, after I figured out that excel does not treat 1 + 1 = 1 as I learnt in discrete mathematics, but as you say, counts the both the trues. Tried instead with:
{=SUM(IF((A<=20)+(B<=20);C;0))}
But I like yours better.
Your problem that it is "summing twice" in this formula
={SUMPRODUCT(C,((A<=20)+(C<=20)))}
is due to addition turning first TRUE plus the second TRUE into 2. It is not actually summing twice, because for any row, if only one condition is met, it would count that row only once.
The solution is to transform either the 1 or the 2 into a 1, using an IF:
={SUMPRODUCT(C,IF((A<=20)+(C<=20))>0, 1, 0)}
That way, each value in column C would only be counted at max once.
Following this site you could build up your SUMPRODUCT() formula like this:
=SUMPRODUCT(C,SIGN((A<=20)+(C<=20)))
So, instead of a nested IF() you control your or condition with the SIGN()function.
hth
If you plan to use a large set of data then it is best to use the array formula:
{=SUM(IF((A1:A5<=20)+(B1:B5<=20),C1:C5,0))}
Obviously adjust the range to suit the data set, however if the whole of each column is to form part of the formula then you can simply adjust to:
{=SUM(IF((A:A<=20)+(B:B<=20),C:C,0))}
This will perform the calculation on all rows of data within the A, B and C columns. With either example remember to press Ctrl + Shift + Enter in order to trigger the array formula (as opposed to typing the { and }).
I have a column on Excel, I found out how to count how many times a value appears in it (ex: how many 1 in the column), but I can't find how to make it count how many times one OR another value appears in this column (ex: how many cells with the value 1 OR 2).
Here is an example of my colum:
A1 1;
A2 1;2;
A3 1;3;
A4 2;
A5 1;
A6 2;3;
A7 1;2;
In this column, if I want to find how many cells with the number 1 there are, I would do :
=COUNTIF(A1:A7,"1") and then the result would be : 5
But if I want to find how many cells have the number 1 OR the number 2, I can't find how to do, but I know the result is 7 (because the all of these cells have or the number 1, or the number 2)
The only way I found is to calculate the number of cells with the number 1 wich don't have the number 2, and to calculate the number of cells with the number 2 wich don't have the number 1, and add the sum of those to the number of cells with the value "1;2", wich gives me a long formula like:
=(COUNTIF(A1:A7,"1")-COUNTIFS(A1:A7,"1",A1:A7,"2"))+(COUNTIF(A1:A7,"2")-COUNTIFS(A1:A7,"2",A1:A7,"1"))+COUNTIF(A1:A7,"1;2")
Any one has a simpler formula?
Thank you so much if someone can resolve this!!
I'm a little confused by your formula, this part, for example
=COUNTIFS(A1:A7,"1",A1:A7,"2")
...can only ever return 0 because COUNTIFS works on an "AND" basis and no cell can be both = 1 and = 2 at the same time
and if the data is exactly as shown with semi colons then surely this formula
=COUNTIF(A1:A7,"1")
will return zero too because none of your cell values are exactly 1
Are you over-simplifying your data for your question? I don't see how that formula will give you a result of 7
Try this formula to count how many cells contain either 1 or 2 (or both)
=SUMPRODUCT((ISNUMBER(FIND(1,A1:A7))+ISNUMBER(FIND(2,A1:A7))>0)+0)
...of course it will also count a cell if it contains 22 or 11, do you want it to do so in that case?
You could create a vba function and reference it.
something like
Function MyOrTest(cell)
If InStr(1, cell.Value, 1) Or InStr(1, cell.Value, 2) Then
MyOrTest = 1
Else
MyOrTest = 0
End If
End Function
You will need to add it to a new Module in VBA. Using this will allow just a normal sum function.