How to do a little math in the criteria_range of Countifs Functions (using OR in Countif) - excel

The Excel File is like this
A B
1 0
0 1
1 1
0 1
0 0
1 0
I want to use Countifs function to count how many rows have at least one "1" in any columns, like
=Countifs(A:A+B:B,">=1")
or
=Countifs(or(A:A=1,B:B=1))
I know I can add a Column C, let Column C = Column A + B, and then just count Column C; or I can count the total rows and count rows with "0" in both columns, and then calculate Total Row - Both "0". But in real Scenario, I have more complicated situation, so I prefer not using these two solutions.

Use a SUMPRODUCT function to provide cyclic calculation.
=SUMPRODUCT(--((A1:A6)+(B1:B6)>=1))
SUMPRODUCT does not like trying to calculate text values and full column references slow it down so keep your ranges to a minimum. Using the INDEX function can help isolate a dynamic range of true numbers.

Another solution using array formula:
=SUM(IF(A1:A6=1,1,IF(B1:B6=1,1,0)))
Being an array formula, you'll have to enter this formula by pressing Ctrl+Shift+Enter together.

Use =COUNT(A:A)-COUNTIFS(A:A,0,B:B,0) to count both 0 columns and subtract it from the total rows:
Or you can use:
=COUNTIFS(A:A,1,B:B,1)+COUNTIFS(A:A,0,B:B,1)+COUNTIFS(A:A,1,B:B,0)
if it is not clear what it the total number of rows.

Related

Excel - How to Rank from 1 to 100 Based on Values in More than 100 Cells

I am trying to figure out how to assign a rank from 1 to 100 in a column that has over 200 cells. I need an Excel formula that will keep the correct 1 to 100 rank even when the order of rows is changed. The way I manually calculate the rank is shown in the picture below:
=RANK.EQ and =RANK.AVG rank cells from 1 to however many cells are included in the reference, but I need a 1 to 100 rank.
I have tried using =IF(MAX($K:$K)=K3,100,M2-(100/COUNT($K:$K))) but because M2 is based on a cell rather than the next descending sequential number in column K, when I change the order of the rows, the rank becomes inacurrate.
Can you just use rank.eq or rank.avg and normalise the result to a range of 1-100?
=99*(RANK.AVG(A2,A:A,1)-1)/(COUNT(A:A)-1)+1

Excel counting taking into account adjacent cells (summing along a column, but looking across a row)

I have a table that tells me whether a value is found in a source:
(image of excel cells)
Value
Source1
Source2
Source3
alpha
1
0
1
beta
0
1
1
gamma
1
0
0
delta
1
1
1
epsilon
0
1
0
zeta
0
1
0
What I'd like to do is count the number of times that each source uniquely finds a given value. For this example, there are:
one value unique to Source1 (gamma)
two values unique to Source2 (epsilon and zeta)
zero values unique to Source3
In practice, this calculation will be used on ~10 columns and 1000s of rows, so I need some formula help.
I've tried various combinations of sumifs, countifs, sumproducts, and array formulas, but I am stumped by the fact that the sum needs to look perpendicularly to the column.
Any help is much appreciated!
With Excel365 you can try below formula-
=SUM(--(MMULT($B$2:$D$7,SEQUENCE(COLUMNS($B$2:$D$2),,,0))*(B$2:B$7)=1))
For Non365 version of excel you try below array (CTRL+SHIFT+ENTER) formula. In this case you must enter same number of one 1 of source column.
=SUM(--(MMULT($B$2:$D$7,TRANSPOSE({1,1,1}))*(B$2:B$7)=1))

Excel formula: make the average depending on a cell

I want to make a formula that turns in a VBA code that makes the average for column A even though there are some 0 there. I want to divide it by a the number in a cell that counts the objects in column A.
I used to use this formula, but it divides my sum incorrectly because I have 0's (I want to keep the 0's there):
=AVERAGE(Sheet1!$B$2:$B$10000)
The easiest way to do this, is to get the total of column B by using sum(B:B) (or a more specific range, if you want), and the amount of non-blank cells in column A by using counta(A:A) (in my comment I used count which only counts the amount of numbers in the range, counta should count all non-blank cells). You can then divide the former by the latter to get the number you are looking for, resulting in a formula looking something like
=SUM(B:B)/COUNTA(A:A)
If you already have the count of column A in a cell (e.g. E3), it's even simpler, just use something like
=SUM(B:B)/E3
You can use AverageIf for such a purpose, as you can see in my example:
Row/Column A B C D
1
2 2 =AVERAGE(B2:B5) => value 3
3 4 =AVERAGEIF(B2:B5;"<>0") => value 4
4 0
5 6

Using COUNTIFS for a series of values at once

Working a step higher then COUNTIFS, I appose a challenge to write a formula without VBA code. The basic data is combined from 1000s of rows with:
Column A: rows with values from 1 to 3
Column B: rows with values from 1 to 250.
For this purpose lets say, we are looking at all cells of value "1" in column A, that suit value "5" in column B. To find all matches, we'd use COUNTIFS command.
1 1
2 5
1 5
1 7
1 10
3 45
2 12
1 2
2 1
=COUNTIFS(A1:A9;1;B1:B9;5)
The answer here is 1.
Next thing, the "5" in column B belongs to a group, e.g. group from 1 to 9. What would the best way be, to count all the matches in this example, so that for all "1"'s in column A, we'd have to find all matches with values from 1 to 9 in column B?! In the upper example that would result in "4". The obvious solution is with a series of IF commands, but that's unefficient and it easy to make a mistake, that get's easily overseen.
=COUNTIFS(A1:A9;1;B1:B9;"<="&9)
Works only as the upper limit. If I give the third criteria range and condition as ">="&1 it does not work - returns 0.
Gasper
Where the data is in A1:B9, using a lookup table in D1:E10 with letters A-J in column D and numbers 0 to 9 in column E and the following formula in B11 referencing letters entered in A11 and A12:
=COUNTIFS(A1:A9,1,B1:B9,">="&VLOOKUP(A11,$D$1:$E$10,2,FALSE),B1:B9,"<="&VLOOKUP(A12,$D$1:$E$10,2,FALSE))
works, changing the letters in A11 and A12 gives the correct count according to what they correspond to in the looku in D1:E10.
When you say give third criteria range do you mean:
=COUNTIFS(A1:A9;1;B1:B9;"<="&9,B1:B9;">=1")
If so then try:
=COUNTIFS(A1:A9;1;B1:B9;AND("<="&9,;">=1"))
ie have two conditional ranges with the second range having both conditions combined with AND()
Maybe what you want(ed) is:
=COUNTIFS(A:A;1;B:B;">=1";B:B;"<=9")
Almost there. I noticed that three criteria ranges and conditions work only if I use "=" sign in a condition. As soon as I use
=COUNTIFS(A1:A9;1;B1:B9;"<="&9,B1:B9;">=1")
it returns 0. My goal is to eventualy replace the number in a condition with a VLOOKUP command, so the final equation should be smth like
=COUNTIFS(A1:A9;1;B1:B9;"<="&VLOOKUP(...),B1:B9;">=VLOOKUP(...)")
But the "<" and ">" signs mess with this. Still looking for a solution.
This is my entire line, if it offers any further indication. The AND() commands is at the end - and it still results in 0
=COUNTIFS(INDIRECT(CONCATENATE("baza!$";SUBSTITUTE(ADDRESS(1;MATCH("card_type_id";baza!$A$1:$AAA$1;0);4);"1";"");"$2:$";SUBSTITUTE(ADDRESS(1;MATCH("card_type_id";baza!$A$1:$AAA$1;0);4);"1";"");"$15000"));IF(C6="računska";1;0);INDIRECT(CONCATENATE("baza!$";SUBSTITUTE(ADDRESS(1;MATCH(IF($C$4="CC_SI_klasifikacija";"building_classification_id";0);baza!$A$1:$AAA$1;0);4);"1";"");"$2:$";SUBSTITUTE(ADDRESS(1;MATCH(IF($C$4="CC_SI_klasifikacija";"building_classification_id";0);baza!$A$1:$AAA$1;0);4);"1";"");"$15000"));AND("<="&VLOOKUP($C$5;$K$203:$N$223;4;FALSE);">="&VLOOKUP($C$5;$K$203:$N$223;3;FALSE)))

How to count number of matches between two columns in Excel?

How to count number of matches between two columns in Excel?
For example if we have:
1 1
2 1
3 2
4 4
5 3
I need to get either a column like this:
1
0
0
1
0
and then I can sum the ones in there to get the count of matches.
Option 1: IF
=IF(A1=B1;1;0)
This formula will put 1 in the cell if A1 = B1, and 0 otherwise.
Option 2: COUNTIF
Write =A1=B1 in C1, etc., in the column cells. This will fill the C column with TRUE and FALSE values.
At the bottom of that column, add a cell =COUNTIF(C1:C100;TRUE) so that you count the cells between C1 and C100 which have value TRUE.
You may find the TechRepublic article Use COUNTIFS() to compare two data sets in Excel of use. See also Microsoft's documentation on countifs().

Resources