Excel formula to count the number of matches in col A and col B - excel-formula

I have a table of data (below) in column A(ID) and B(Name). I would like help on creating a formula to count the number of consecutive occurrences in both A and B. The result column shows what I'm trying to create.
I can do it for one column using =IF(A1<>A2,COUNTIF($A1:A$1,A1),"")
I just can't get it to work using both columns
ID
NAME
RESULT
3
A Sapphire
1
3
B Diamond
3
B Diamond
3
B Diamond
3
3
C Ruby
3
C Ruby
3
C Ruby
3
14
B Diamond
14
B Diamond
2
19
A Sapphire
1
19
B Diamond
1
25
A Sapphire
1
25
B Diamond
25
B Diamond
2
25
C Ruby
25
C Ruby
2
34
A Sapphire
1
34
C Ruby
1
39
A Sapphire
1
39
C Ruby
1
40
C Ruby
1
42
C Ruby
1

Join data in A and B | Adding formula to C2: =A2&" "&B2
Then add formula to D1 =IF(C1<>C2,COUNTIF($C1:C$1,C1),"")
Copy formulas down

You can use COUNTIFS which allows multiple ranges and criteria.
COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
=COUNTIFS(B:B;B2;A:A;A2)

Related

Excel Determine Ascending Rank Based on Each Date

Here is the raw data:
Date Name Score
25/2/2021 A 10
25/2/2021 B 8
25/2/2021 C 8
25/2/2021 D 4
25/2/2021 E 1
24/2/2021 A 0
24/2/2021 B 20
24/2/2021 C 7
24/2/2021 D 10
24/2/2021 E 4
I would love to assign consecutive rank (preferably ascending order) to the students by each date, as follows:
Date Name Score Rank
25/2/2021 A 10 1
25/2/2021 B 8 2
25/2/2021 C 8 2
25/2/2021 D 4 3
25/2/2021 E 1 4
24/2/2021 A 0 5
24/2/2021 B 20 1
24/2/2021 C 7 3
24/2/2021 D 10 2
24/2/2021 E 6 4
I've tried customised rank function but it's hard to output this result, how could I do that? Thanks in advance!
You can try below formula with Excel365. It will also work on unsorted data.
=XMATCH(C2,SORT(FILTER($C$2:$C$11,$A$2:$A$11=A2),1,-1))
In D2 use:
=COUNTIFS(A$2:A$11,A2,C$2:C$11,">"&C2)+1
EDIT: Based on your comment, try:
Formula in D2:
=SUM(--(UNIQUE(FILTER(C$2:C$11,A$2:A$11=A2))>C2))+1

Using IF and AND function

I am trying to use the IF and AND function in excel for values in two different cells. I have 25 conditions.
Below is the formula I've created but it keeps on saying there's an error.
IF(AND(A10=“A”,B10=1),11,IF(AND(A=“A”,B10=2),16,IF(AND(A10=“A”,B10=3),20,IF(AND(A10=“A”,B10=4),23,IF(AND(A10=“A”,B10=5),25,IF(AND(A10=“B”,B10=1),7,IF(AND(A10=“B”,B10=2),12,IF(AND(A10=“B”,B10=3),17,IF(AND(A10=“B”,B10=4),21,IF(AND(A10=“B”,B10=5),24,IF(AND(A10=“C”,B10=1),4,IF(AND(A10=“C”,B10=2),8,IF(AND(A10=“C”,B10=3),13,IF(AND(A10=“C”,B10=4),18,IF(AND(A10=“C”,B10=5),22,IF(AND(A10=“D”,B10=1),2,IF(AND(A10=“D”,B10=2),5,IF(AND(A10=“D”,B10=3),9,IF(AND(A10=“D”,B10=4),14,IF(AND(A10=“D”,B10=5),19,IF(AND(A10=“E”,B10=1),1,IF(AND(A10=“E”,B10=2),3,IF(AND(A10=“E”,B10=3),6,IF(AND(A10=“E”,B10=4),10,15))))))))))))))))))))))))))))))))))))))))))))))))
I expected the output to be, for example; if cell1 is "A" and cell2 is 1 the result should be 11.
I would highly advise a lookup table. Simply have all of your options listed out with their desired results and find them with a criteria search, such as the use of sumifs function.
For example, if you paste J1:L25 your possibilities:
A 1 11
A 2 16
A 3 20
A 4 23
A 5 25
B 1 7
B 2 12
B 3 17
B 4 21
B 5 24
C 1 4
C 2 8
C 3 13
C 4 18
C 5 22
D 1 2
D 2 5
D 3 9
D 4 14
D 5 19
E 1 1
E 2 3
E 3 6
E 4 10
E 5 15
You can then place the formula =SUMIFS($L$1:$L$25,$J$1:$J$25,$A$10,$K$1:$K$25,$B$10) to return your desired value.
That is, =SUMIFS(range_of_results, criteria_range_of_A-E, A10, criteria_range_of_1-5, B10)

How to find a value in one column in another column and return cells in row where value was found

I want to find a value in column E, then get values from same row from columns B, C, and D. So I want to find 1 in column E, and the values from B, C, and E, then find 2 in column E and values from B, C, and D and all the way through 18.
I have tried VLOOKUP, INDEX/MATCH
B C D E
1 4 365 3
2 5 464 2
3 3 151 15
4 4 417 1
5 4 284 7
F G H I
1 4 4 417
2 2 5 464
3 1 4 365
G2: =INDEX($B$2:$E$6,MATCH($F2,$E$2:$E$6,0),1)
H2: =INDEX($B$2:$E$6,MATCH($F2,$E$2:$E$6,0),2)
I2: =INDEX($B$2:$E$6,MATCH($F2,$E$2:$E$6,0),3)
and fill down as far as needed, adjusting the array address as required.

Excel macro replace cell in A by other cell in B

I have a excel document where I have something like this
A B C
1 1 45 a
2 2 32 b
3 3 34 H
4 3 37
5 4 49 i
5 5 76 H
Note that 3c is combined but 3b isn't.
I need to do a macro to change the content of B with the content of C but only those that don't have a letter H. so the document would look like this
A B C
1 1 a a
2 2 b b
3 3 34 H
4 3 37
5 4 i i
5 5 76 H
Here a image
Just use this simple formula in column C,
=IF(B1="H",A1,B1)
and drag it throughout the range. Once done, copy paste all of the data in column C to A (paste special)

Sum number according to date and name in excel

To sum the third column (numbers o companies) I've used this
=SUM(1/COUNTIF(Names;Names))
Names is name of array in C column and CTRL+SHIFT+ENTER and it works perfectly.
Now I'd like to sum earnings but only for each company once and with the latest data. For example, the result shoud be like this
=C4+C6+C7+C8+C9+C10
(93)
Thanks
A B C D
1 # company earnings date
2 1 ISB 12 10/11/2011
3 2 DTN 15 11/11/2011
4 3 ABC 13 12/11/2011
5 4 ISB 17 13/11/2011
6 5 RTV 18 14/11/2011
7 6 DTN 22 15/11/2011
8 7 PVS 11 16/11/2011
9 8 ISB 19 17/11/2011
10 9 ANH 10 18/11/2011
Sum 6 93
Assuming ascending dates, you could try with CTRL+SHIFT+ENTER in C11:
=SUM((MAX(A2:A10)-MATCH(B2:B10,LOOKUP(MAX(A2:A10)-A2:A10,A2:A10-1,B2:B10),0)=A2:A10-1)*C2:C10)
I'd suggest using a helper column as the easiest approach. In E2 use this formula
=IF(COUNTIF(B2:B$1000,B2)=1,C2,"")
and copy down the column. Now sum column D for the required answer.
Note that the above formula assumes 1000 rows of data maximum, increase if required.

Resources