count if odd or even
What formula should i use to count the number of cells that are odd, or even?
MacBook Pro (Retina, 13-inch, Late 2013), OS X Yosemite (10.10.2)
What formula should i use to count the number of cells that are odd, or even?
MacBook Pro (Retina, 13-inch, Late 2013), OS X Yosemite (10.10.2)
Hello FePerrella,
This is one way:
This solution requires an auxiliary column. In this case, the data is in B and column A is the auxiliary column. You can pick any columns and adjust the expressions. Then you may hide the auxiliary column if you wish.
The expression in Column A is:
=IF(MOD(B, 2)=0, "EVEN", "ODD")
The expression for counting odd results is: =COUNTIF(A, "ODD")
and, the expression for counting even results is: =COUNTIF(A, "EVEN")
I am not aware of any way, short of a script, to both calculate the evenness or oddness of each entry and do the count in one cell.
Jerry
Hi Jerold, thanks for the help.
I want to count just one of then, for example ODD, i have a table like this one.
ODD Count | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O |
04 | 12 | 21 | 22 | 02 | 11 | 24 | 25 | 01 | 10 | 14 | 17 | 08 | 13 | 23 |
It won't be easy to add the IF column to count the ODDs, because i have a lot of lines, but fixed columns, it wouldn't work for me if i transpose the table also.
Do you think there is other solution?
I found in Excel and Google Spreadsheet the sumproduct but couldn't make it work also...
So you just want to see if an odd (1 odd number) exist in the range (all the columns)?
Hi Charles, i want to count the odd numbers, like in Jerry's example, 6 odds.
However i don't want to create a new line for each IF sentence.
Hi Jerrold,
It's like this table, with more lines...
ODD Count | A | B | C | D | F | G | H | I | K |
5 | 5 | 3 | 6 | 7 | 8 | 5 | 13 | 22 | 12 |
4 | 3 | 25 | 6 | 8 | 19 | 18 | 21 | 4 | 2 |
4 | 12 | 13 | 20 | 17 | 3 | 21 | 8 | 22 | 2 |
Thanks again
Hi FP,
However i don't want to create a new line for each IF sentence.
Try this. Create another table ('Odds') to test is a value is odd.
Formula in B2 of the Odds table (and Fill Right and Down)
=ISODD(Table 1::B2)
I added Conditional Highlighting to the Odds table to show green for TRUE. You can move the Odds table to another Sheet to 'hide' it if you want.
Formula in A2 of Table 1 (and Fill Down)
=COUNTIF(Odds::2:2,"TRUE")
Regards,
Ian.
Thanks Ian, this will ease the problema... but i wonder if Apple could just supply a function that would do that without needing another table, like competitors have.
Regards,
FP
Hello
Obviously you may calculate sum of MOD(n,2) for given numbers. Formula would become lengthy, though.
E.g.,
Table 1 (excerpt) A2 =MOD(B2,2)+MOD(C2,2)+MOD(D2,2)+MOD(E2,2)+MOD(F2,2) +MOD(G2,2)+MOD(H2,2)+MOD(I2,2)+MOD(J2,2)+MOD(K2,2) +MOD(L2,2)+MOD(M2,2)+MOD(N2,2)+MOD(O2,2)+MOD(P2,2) B2 =RANDBETWEEN(0,50) C2 =RANDBETWEEN(0,50) D2 =RANDBETWEEN(0,50) E2 =RANDBETWEEN(0,50) F2 =RANDBETWEEN(0,50) G2 =RANDBETWEEN(0,50) H2 =RANDBETWEEN(0,50) I2 =RANDBETWEEN(0,50) J2 =RANDBETWEEN(0,50) K2 =RANDBETWEEN(0,50) L2 =RANDBETWEEN(0,50) M2 =RANDBETWEEN(0,50) N2 =RANDBETWEEN(0,50) O2 =RANDBETWEEN(0,50) P2 =RANDBETWEEN(0,50)
Or you may introduce auxiliary columns to store MOD(n,2) for given numbers. Formula would be concise and easily filled.
E.g.,
Table 2 (excerpt) A2 =SUM(Q2:AE2) B2 =RANDBETWEEN(0,50) C2 =RANDBETWEEN(0,50) D2 =RANDBETWEEN(0,50) E2 =RANDBETWEEN(0,50) F2 =RANDBETWEEN(0,50) G2 =RANDBETWEEN(0,50) H2 =RANDBETWEEN(0,50) I2 =RANDBETWEEN(0,50) J2 =RANDBETWEEN(0,50) K2 =RANDBETWEEN(0,50) L2 =RANDBETWEEN(0,50) M2 =RANDBETWEEN(0,50) N2 =RANDBETWEEN(0,50) O2 =RANDBETWEEN(0,50) P2 =RANDBETWEEN(0,50) Q2 =MOD(B2,2) R2 =MOD(C2,2) S2 =MOD(D2,2) T2 =MOD(E2,2) U2 =MOD(F2,2) V2 =MOD(G2,2) W2 =MOD(H2,2) X2 =MOD(I2,2) Y2 =MOD(J2,2) Z2 =MOD(K2,2) AA2 =MOD(L2,2) AB2 =MOD(M2,2) AC2 =MOD(N2,2) AD2 =MOD(O2,2) AE2 =MOD(P2,2)
Regards,
H
Hi Hiroto, this was very helpful!
It's lengthy but doesn't need any other column/table, etc.
As i have a fixed number of columns, to copy the formula is easier...
Thanks!
count if odd or even