How to apply COUNTIFS Formula against cells on same row within a range - excel

I am trying to count the number of occurences in a range based on 2 criteria. The first criteria is based on Text, the second criteria is based on 2 cells in the repsective row of a range. I cannot get the count to work - it counts incorrectly.
Example....
COL A COL B COL C
ROW 1 Eggs 2 3
ROW 2 Eggs 3 1
ROW 3 Eggs 4 9
ROW 4 Eggs 1 2
ROW 5 Bacon 2 1
ROW 6 Eggs 4 1
The formula being applied is:
=COUNTIFS($A$1:$A$6,"Eggs",$B$2:$B$6,">"&$C$2:$C$6)
It doesnt work correctly......
I would expect the result to be a count of 2, as there are 2 occurences of Eggs where column B is greater than column C

Your ranges are not the same size and you should likely be using SUMPRODUCT instead of COUNTIFS.
If you have a header row in row 1,
=SUMPRODUCT(--($A$2:$A$7="eggs"), --($B$2:$B$7>$C$2:$C$7))
If there is no header row and your data starts in row 1,
=SUMPRODUCT(--($A$1:$A$6="eggs"), --($B$1:$B$6>$C$1:$C$6))

Related

Formula to Find if Number between a Range in 2 Columns and then Offset 1 column

I would like to write an Excel formula that looks at 3 columns and grabs value of the 1st column based on if the search value is in columns 2 or columns 3.
1st Column 2nd Column 3rd Column
a 1 5
b 6 10
c 11 15
Search Value 1: 13 Result: c
Search Value 2: 6 Result: b
Try below formula-
=INDEX($A$1:$A$3,MAX(($B$1:$B$3<=B6)*($C$1:$C$3>=B6)*(ROW($A$1:$A$3))))

Product of cells with changing row number

I'd like to get the product of the last three cells in the certain column. The row numbers will change as the data increases. For example,
ColA
2
4
1
6
5
The product of the last three cells in ColA will be 30 (1*6*5).
ColA
2
4
1
6
5
7
3
Now the product of the last three cells in ColA becomes 105(5*7*3).
Is there a function in Excel (not =Product) that will do the calculation above?
Try this:
=PRODUCT(INDEX(A:A,MATCH(1E+99,A:A)-2):INDEX(A:A,MATCH(1E+99,A:A)))

Return list of matching rows

Sheet1
A B C D
1 2 3 4
2 4 5 6
3 3 5 6
4 7 3 1
5 4 6 7
Sheet 2
A B C D
1 4
2 1
3 1 3 4
4 1 2 5
5 2 3
6 2 3 5
7 4 5
Column A of Sheet 2 has a non repeating listing of all values in Sheet 1. I would like a forumla so Col B of Sheet 2 lists the value of Sheet 1 Col A for each row where the Sheet 2 Col A lookup value is found. Either giving me a comma sep list or putting the results in sheet 2 Col B,C,D,...
I came up with a solution, but it involves a handful of formulas, not just one. Hopefully, you will still find it useful.
Your Sheet2 would basically look like this:
Here are the formulas you need to enter:
B1: =IFERROR(SMALL($G4:$U4,COLUMN()-1),"") [drag down and across to D7]
G1: =IF(F2=$W2,F1+1,MAX(1,F1)) [drag across to U1]
G2: =IF(F2=$W2,1,F2+1) [drag across to U2]
G3: =INDEX(Sheet1!B$1:D$5,G1,G2) [drag across to U3]
G4: =IF(G$3=$F4,G$1,"") [drag down and across to U10]
What this does is organize the Sheet1 data into rows, where each row corresponds to a lookup value. Then, it grabs the smallest value, the second smallest value (if one exists), and third smallest value (if one exists) from each row.
This should be easy to scale to as large a spreadsheet as you need (as long as you don't run out of columns).

Numbering/sequencing sets of same column values

How to do numbering/sequencing for sets of same column values? For example:
Col1 Col2
Andy 1
Chad 1
Bill 1
Andy 2
Bill 2
Bill 3
Chad 2
Bill 4
Since Andy got 2 values, I want to number it 1 and 2 in Column 2. For Bill, I want to number it 1, 2, 3 and 4 and so on.
You can accomplish this with countif and a sliding range :
A B
1 val1 =COUNTIF($A$1:A1, A1)
2 valx =COUNTIF($A$1:A2, A2)
and so on.
The formula in column B can be dragged down / autofilled in the column. It anchors to the start of the range and only looks as far down as the value we are numbering; COUNTIF is tallying up the matching values in the preceding set this way.
That is kind of slow when your list is really long. I've found sorting the column A to Z or small to larger and then using this formula is much faster:
=IF(A2=A1, A1+1,1)
Basically
if the value above is the same then add one to the count else start over at 1

Filtering values based on comparisons with adjacent columns

I want to compare column A in sheet 1 with column A in sheet 2, and only return matches from sheet 2.
I then, want to use the matching column A rows as a basis for a second comparison. The second comparison is to compare column B in sheet 1 with column B in sheet 2 and only return non matches from sheet 2.
Assume this is the data on sheet 1:
A B
2 4
2 4
2 3
3 3
and this is the data on sheet 2:
A B
2 4
3 3
2 4
3 3
So, only the third row will pass on both conditions. Any ideas how this can be done?
I want to compare column A in sheet 1 with column A in sheet 2 and only return matches from sheet 2
Type on cell C1, on sheet 1:
=IF(A1=Sheet2!A1,"True","")
Drag the formula to all rows on column A, which contain non blank cells.
The second comparison is to compare column B in sheet 1 with column B in sheet 2 and only return non matches from sheet 2.
Type on cell D1, on Sheet 1:
=IF(AND(C1="True",B1<>Sheet2!B1),"True","")
Drag the formula down.
Output on Sheet 1 should be like that:
A B C D
2 4 True
2 4
2 3 True True
3 3 True
Filter column C by True to observe the "first" condition's returns. Do the same to column D to retrieve the data which satisfies the "second" condition.

Resources