Match function to match multiple values - excel

I have two columns
Column A Column B
Apple A
banana B
Grape C
Apple D
Banana F
Now I want to find the row number for row which has data Apple & D.
Is their a way to use Match function to get the row number?

You can use this one:
=LOOKUP(2,1/(A1:A5="Apple")/(B1:B5="D"),ROW(A1:A5))
or non-volatile version (if your ranges starts from first row):
=MATCH(2,1/(A1:A5="Apple")/(B1:B5="D"))
with array entry (CTRL+SHIFT+ENTER).

Alternate, does not require array entry:
=MATCH(TRUE,INDEX(A1:A5&B1:B5="Apple"&"D",),0)

Try this !!
=SUMPRODUCT((MATCH(1,(A1:A5="Apple")*(B1:B5="D"),0)))
Array formula CTRL+SHIFT+ENTER

Related

Matching multiple value in excel using index and match

I used index and match to identify the values of the table and matched it. However I am facing trouble when I try to get b and c, a is matched correctly
A. B C D.
1 a b c
2 fruit1 a
3 fruit0
4 fruit3
5 fruit5 a
E F
1 fruit1 a
2 fruit0 c
3 fruit3 b
4 fruit5 a
My formula is
=Iferror(if(index(($f$1:$f$4), match($A2,$e$1:$e$4,0),match(b$2,$f$1:$f$4,0)) = b$2,index(($f$1:$f$4), match($A2,$e$1:$e$4,0),match(b$2,$f$1:$f$4,0)), ""),"")
If your data table is in E1:F4, and you are trying to look up the fruit names that appear in column A starting at A2, and place the correct letter next to them in column B, then there's no need for the IF and the sequences of MATCHes.
All you need is this, pasted into cell B2 and copied down, is this:
=IFERROR(INDEX($F$1:$F$4,(MATCH(A2,$E$1:$E$4,0))),"")
An easier approach to this is just:
=VLOOKUP(A2,$E$1:$F$4,2,FALSE)
or to be safer:
=IFERROR(VLOOKUP(A2,$E$1:$F$4,2,FALSE),"")
And if you have access to O365 Excel and the newer XLOOKUP function, you can use the following examples. XLOOKUP incorporates the "not found" result so you don't have to do a separate IFERROR. Do do it on a cell-by-cell basis as you had before, put this in B2 and copy it down:
=XLOOKUP(A2,$E$1:$E$4,$F$1:$F$4,"",0)
If you want to go one step further, you can apply the XLOOKUP as an array or "spill" formula, you change the lookup_value to be the A1:A4 and it does the rest. Place this in B2 and it will fill B2 through B5:
=XLOOKUP(A2:A5,$E$1:$E$4,$F$1:$F$4,"",0)

Formula to Return Text in the Row of Largest Number

Column A Has Text & Columns B, C & D contain numbers.
For Ex.)
A... …B C D
John 4 6 2
Dave 4 6 4
Mike 4 5 1
Bill 2 5 9
I would like a cell to return the name in column A that has the Largest Number in Column B. And if there are similar numbers, go to the next column and determine which is highest, and if that is tied go to the next column and so on.
Any help would be appreciated.
We can de-conflict ties.In E1 enter:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))
and copy down. Then in another cell enter:
=INDEX(A:A,MATCH(MAX(E:E),E:E,0))
EDIT#1
This is only good for 3 columns of numbers, but it is very easy to add additional de-confliction terms if necessary:
=B1 + C1/(10*MAX(C:C))+D1/(100*MAX(D:D))+E1/(1000*MAX(E:E))
For an expandable number of rows/columns, use a helper row with the same number of columns as number columns in your data. The formulas below reference the following image (the data are in A1:G7):
B9-->=MAX(B1:B7)
C9 (fill over the remaining columns to G9)-->
=MAX(IF(MMULT(--($B1:B7=$B9:B9),--(ROW(INDIRECT("1:"&COLUMNS($B9:B9)))>0))=COLUMNS($B9:B9),C1:C7))
The following formula will give the answer (shown in A9 above):
=INDEX(A1:A7,MATCH(TRUE,(MMULT(--($B1:G7=$B9:G9),--(ROW(INDIRECT("1:"&COLUMNS($B9:G9)))>0))=COLUMNS($B9:G9)),0))
UPDATE WITH ALTERNATIVE METHOD
Using a helper column instead, again referencing the image below (the data are in A1:G7):
I1 (fill down to I7)-->
=SUM(--(MMULT(SIGN(B1:G1-$B$1:$G$7)*2^(COLUMN(G1)-COLUMN(A1:F1)),--(ROW(INDIRECT("1:"&COLUMNS(B1:G1)))>0))>0))
The following formula will give the answer (shown in J1 above):
=INDEX(A1:A7,MATCH(MAX(I1:I7),I1:I7,))
As a bonus, notice that the helper column corresponds to the order that you would get from sorting the data by each column left-to-right. In other words, you could use the helper column to perform a formula-based multi-column sort on strictly numeric data. For the last image, entering the following array formula into a range with the same dimensions as A1:G7 gives a descending sort on columns B through G:
=IF(A1:A7=A1:A7,INDEX(A1:G7,MATCH(ROW(A7)-ROW(A1:A7),I1:I7,0),))

How to Count the number of times a cell in one column matches a cell in another column?

I have two columns. Column A is a list of text values. Column B will be individual text values that may or may not match Column A. Across say 20 rows, I want to use something like COUNTIF at the bottom of Column B to count how many answers in Column B match the correct answer in Column A.
For example, if Column A reads:
1. Apple
2. Orange
3. Banana
4. Kumquat
5. Pineapple
Column B reads:
1. Apple
2. Guava
3. Pistachio
4. Kumquat
5. Pineapple
Essentially, rows 1, 4 & 5 all match, thus the sum at the bottom of column B would be 3.
Is there a way to do this with a formula?
You can use something like this:
{=SUM(IF(A1:A5=B1:B5,1,0))}
To use this formula, type in any cell "=SUM(IF(A1:A5=B1:B5;1;0))" and press CTRL+SHIFT+INTRO

Count with criteria for changing column in excel

I have a data looks like this:
a b c
1 3 4
2 3 3
4 1 2
2 4 2
In another worksheet, I want to do the following calculation:
whenever A1 returns a (header of data worksheet), count number of items that are smaller and equal to 2 in column "a". (result will be 2)
if A1 returns b, count number of items that are smaller and equal to 2 in column "b". (result will be 1).
A1 has already been preset with formula such that it will show a or b or c as conditions changed.
I need the formula to be lean... I actually have 6 headers, so if I keep on using if functions, I will probably have to set 6 if functions in one cell...that can be overwhelming. index match cannot provide a range to work on...Any suggestion? thanks
I don't know vba. If you could provide a workable vba code, i don't mind. but i don't know how to read it...>.< please provide user manual for that. lol, thank you~
If your data is found on Sheet1 and the a is found on column a, b is found on column b etc. enter this formula on then next sheet on b1 when a1 is the column value:
=COUNTIF(INDIRECT("Sheet1!"&a1&":"&a1),"<=2")
The Indirect is for adding text to your reference.
If your data sheet is Sheet1, you could try the array formula:-
=SUM((Sheet1!A1:C1=$A$1)*(Sheet1!A2:C5<=2))
Must be entered with CtrlShiftEnter
(actually there are 3 items less than or equal to 2 in column A)
Or you can use the SUMPRODUCT version if you prefer not to use an array formula:-
=SUMPRODUCT((Sheet1!A1:C1=$A$1)*(Sheet1!A2:C5<=2))
Or you can use this INDEX/MATCH method which is probably more efficient:-
=COUNTIF(INDEX(Sheet1!A2:C5,,MATCH(A1,Sheet1!A1:C1,0)),"<="&2)

How do you add two COUNTIF equations together?

How do i add two COUNTIF equations together to get a total
I assume you only want to count when the list contains both items in the same position.
Example
A1: =a B1: =a
A2: =a B2: =b
A3: =a B3: =c
COUNTIF(A1:A3,"a") returns 3
COUNTIF(B1:B3,"b") returns 1
to count where first list =a and second list =b you can use SUMPRODUCT, which would return 1.
SUMPRODUCT((A1:A3="a")*(B1:B3="b"))
Or you could use an array formula. You need to use CTRL+SHIFT+ENTER when commiting the formula rather than a simple ENTER. This will automatically add { } around the formula.
=SUM((A1:A3="a")*(B1:B3="b"))
Working on Andy Pope's example (if this is what you want):
=COUNTIFS(A11:A13,"a",B11:B13,"b")
Combining this with your other question, do you mean?
=(COUNTIF(B3:L3,"X")*20)+(COUNTIF(N3:O3,"X")*2.5)
That would add 20 for every X between B3 and L3 and 2.5 for every X in N3 or O3.
If you want to add the count of two different occurences in one column or row...for example:
How often did customers call my store looking for either flour or sugar, where flour and sugar are typed into the cell.
Here is the formula:
=SUM((COUNTIF([Cell Range],"flour")),(COUNTIF([Cell Range],"sugar")))
The cell range can also be an entire column (that's what I did). I just clicked on the column when it asked for range.
If you count particular value, you can use COUNTIF function,
Example,
A B
0-5 A
6-10 B
11-15 C
0-5 D
16-20 E
21-25 D
0-5 A
21-25 D
=COUNTIF(A1:A8,"0-5")
If you count Multiple function,
=COUNTIFS(A1:A8,"0-5",B1:B8,"A")
=SUMPRODUCT(COUNTIF(A:A,{"Text1","text2","text3","text"}))
You can extend this by adding more csv and it will add up the count of all values if exist in column A. Change the range according to your requirement.

Resources