Lookup if two conditions are met!

MASOODAHMAD

Board Regular
Joined
Mar 28, 2012
Messages
105
Platform
  1. MacOS
Hello,

I'm trying to get this to work. I tried the vlookup, combination of Match & Index, but none helped me to achieve the desired output. I'm missing something.

Here is my lookup table1 with "Holiday" details in the third column. Instead of "Holiday", the column might contains other text/value.

Table1:
EcodeDateDay
EKCS-12471/5/2018, Tuesday
EKCS-11411/5/2018, Tuesday
EKCS-03661/5/2018, Tuesday
EKCS-13171/5/2018, Tuesday
EKCS-1247
7/5/2018, Monday
Holiday
EKCS-11417/5/2018, Monday
Holiday
EKCS-03667/5/2018, Monday
Holiday
EKCS-13177/5/2018, MondayHoliday
EKCS-12478/5/2018, Tuesday
EKCS-11418/5/2018, Tuesday
EKCS-03668/5/2018, Tuesday
EKCS-13178/5/2018, Tuesday
EKCS-12478/5/2018, Tuesday

<tbody>
</tbody>
<style>table { }td { padding-top: 1px; padding-right: 1px; padding-left: 1px; color: black; font-size: 12pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; vertical-align: bottom; border: medium none; white-space: nowrap; }.xl63 { text-align: left; border: 0.5pt solid windowtext; }.xl64 { border: 0.5pt solid windowtext; }.xl65 { font-weight: 700; }.xl66 { text-align: left; border: 0.5pt solid windowtext; background: yellow none repeat scroll 0% 0%; }.xl67 { border: 0.5pt solid windowtext; background: yellow none repeat scroll 0% 0%; }</style>

Below is the table2 where I want to extract the values from the table1 above.

If values in column A and B (table2) matches with the values in column A and B (table1), then the corresponding column C (table2) should get the value from column C of table 1. Also note that Ecode is repeated in column A.

For example, in the table below, the Red highlighted needs to have the "Holiday" data in column C.

Table2:
EcodeDateDayEcodeDateDay
EKCS-01232/6/2018, SaturdayEKCS-01232/6/2018, Saturday
EKCS-124613/5/2018, SundayEKCS-124613/5/2018, Sunday
EKCS-048221/5/2018, MondayEKCS-048221/5/2018, Monday
EKCS-022929/5/2018, TuesdayEKCS-022929/5/2018, Tuesday
EKCS-036215/5/2018, TuesdayEKCS-036215/5/2018, Tuesday
EKCS-03668/5/2018, TuesdayEKCS-03668/5/2018, Tuesday
EKCS-1317
7/5/2018, Monday



EKCS-13177/5/2018, MondayHoliday
EKCS-13178/5/2018, TuesdayEKCS-13178/5/2018, Tuesday
EKCS-106223/5/2018, WednesdayEKCS-106223/5/2018, Wednesday
EKCS-12478/5/2018, TuesdayEKCS-12478/5/2018, Tuesday
EKCS-118825/5/2018, FridayEKCS-118825/5/2018, Friday
EKCS-068331/5/2018, ThursdayOUTPUT >>EKCS-068331/5/2018, Thursday
EKCS-13066/6/2018, WednesdayEKCS-13066/6/2018, Wednesday
EKCS-03661/5/2018, TuesdayEKCS-03661/5/2018, Tuesday
EKCS-12478/5/2018, TuesdayEKCS-12478/5/2018, Tuesday
EKCS-1141
7/5/2018, Monday



EKCS-11417/5/2018, MondayHoliday
EKCS-03319/5/2018, WednesdayEKCS-03319/5/2018, Wednesday
EKCS-135811/5/2018, FridayEKCS-135811/5/2018, Friday
EKCS-12354/6/2018, MondayEKCS-12354/6/2018, Monday
EKCS-13171/5/2018, TuesdayEKCS-13171/5/2018, Tuesday
EKCS-12473/5/2018, ThursdayEKCS-12473/5/2018, Thursday
EKCS-11411/5/2018, TuesdayEKCS-11411/5/2018, Tuesday
EKCS-0366
7/5/2018, Monday



EKCS-03667/5/2018, MondayHoliday
EKCS-12477/5/2018, Monday



EKCS-12477/5/2018, MondayHoliday
EKCS-09497/5/2018, MondayEKCS-09497/5/2018, Monday
EKCS-091127/5/2018, SundayEKCS-091127/5/2018, Sunday

<tbody>
</tbody>
<style>table { }td { padding-top: 1px; padding-right: 1px; padding-left: 1px; color: black; font-size: 12pt; font-weight: 400; font-style: normal; text-decoration: none; font-family: Calibri, sans-serif; vertical-align: bottom; border: medium none; white-space: nowrap; }.xl63 { text-align: left; border: 0.5pt solid windowtext; }.xl64 { border: 0.5pt solid windowtext; }.xl65 { font-weight: 700; }.xl66 { text-align: left; border: 0.5pt solid windowtext; background: yellow none repeat scroll 0% 0%; }.xl67 { border: 0.5pt solid windowtext; background: yellow none repeat scroll 0% 0%; }.xl68 { border: 0.5pt solid windowtext; }</style>

Thanks in advance.
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Try


A
B
C
D
E
F
G
1
Ecode​
Date​
Day​
Ecode​
Date​
Day​
2
EKCS-1247​
1/5/2018, Tuesday​
EKCS-0123​
2/6/2018, Saturday​
3
EKCS-1141​
1/5/2018, Tuesday​
EKCS-1246​
13/5/2018, Sunday​
4
EKCS-0366​
1/5/2018, Tuesday​
EKCS-0482​
21/5/2018, Monday​
5
EKCS-1317​
1/5/2018, Tuesday​
EKCS-0229​
29/5/2018, Tuesday​
6
EKCS-1247​
7/5/2018, Monday​
Holiday​
EKCS-0362​
15/5/2018, Tuesday​
7
EKCS-1141​
7/5/2018, Monday​
Holiday​
EKCS-0366​
8/5/2018, Tuesday​
8
EKCS-0366​
7/5/2018, Monday​
Holiday​
EKCS-1317​
7/5/2018, Monday​
Holiday​
9
EKCS-1317​
7/5/2018, Monday​
Holiday​
EKCS-1317​
8/5/2018, Tuesday​
10
EKCS-1247​
8/5/2018, Tuesday​
EKCS-1062​
23/5/2018, Wednesday​
11
EKCS-1141​
8/5/2018, Tuesday​
EKCS-1247​
8/5/2018, Tuesday​
12
EKCS-0366​
8/5/2018, Tuesday​
EKCS-1188​
25/5/2018, Friday​
13
EKCS-1317​
8/5/2018, Tuesday​
EKCS-0683​
31/5/2018, Thursday​
14
EKCS-1247​
8/5/2018, Tuesday​
EKCS-1306​
6/6/2018, Wednesday​
15
EKCS-0366​
1/5/2018, Tuesday​
16
EKCS-1247​
8/5/2018, Tuesday​
17
EKCS-1141​
7/5/2018, Monday​
Holiday​
18
EKCS-0331​
9/5/2018, Wednesday​
19
EKCS-1358​
11/5/2018, Friday​
20
EKCS-1235​
4/6/2018, Monday​
21
EKCS-1317​
1/5/2018, Tuesday​
22
EKCS-1247​
3/5/2018, Thursday​
23
EKCS-1141​
1/5/2018, Tuesday​
24
EKCS-0366​
7/5/2018, Monday​
Holiday​
25
EKCS-1247​
7/5/2018, Monday​
Holiday​
26
EKCS-0949​
7/5/2018, Monday​
27
EKCS-0911​
27/5/2018, Sunday​
28

<tbody>
</tbody>


Array formula in G2 copied down
=IFERROR(""&INDEX($C$2:$C$14,MATCH(1,IF($A$2:$A$14=E9,IF($B$2:$B$14=F9,1)),0)),"")
Ctrl+Shift+Enter

M.
 
Upvote 0
If you're good with using VBA, I've got a code for that, it's pretty simple.

Code:
Public Function MyVlookup2(Mycrit As Variant, Searchit() As Variant, Mycrit2 As Variant, Searchit2() As Variant, Myresult() As Variant)

For i = 1 To UBound(Searchit)
If Searchit(i, 1) = Mycrit And Searchit2(i, 1) = Mycrit2 Then MyVlookup2 = Myresult(i, 1)
Next i


End Function

Think of it similar to a sumifs formula. MyVlookup2(1st column to search,1st criteria,2nd column to search, 2nd criteria, result column)

Very useful :)

Otherwise, you could combine the 2 columns of your criteria into one with an & and do a vlookup against that.

Hope that helps!
 
Upvote 0
oops...

Disregard my formula in post 2 - i pasted the wrong formula

Try in G2 copied down
=IFERROR(""&INDEX($C$2:$C$14,MATCH(1,IF($A$2:$A$14=E2,IF($B$2:$B$14=F2,1)),0)),"")
Ctrl+Shift+Enter

M.
 
Upvote 0
Thanks Marcelo Branco, that's great. I need to learn more about Index and Match.
@GhostEcho, thanks for the code too. I'll give it a try someday. In the meantime, I'm trying to enhance my formula's skills.

Thanks again for your contributions.
 
Upvote 0
oops...

Disregard my formula in post 2 - i pasted the wrong formula

Try in G2 copied down
=IFERROR(""&INDEX($C$2:$C$14,MATCH(1,IF($A$2:$A$14=E2,IF($B$2:$B$14=F2,1)),0)),"")
Ctrl+Shift+Enter

M.

No issues, I figured it out.

Once again, thanks for all your help.
 
Upvote 0
Table1 is in Sheet1
Formula in Table2 in Sheet2 in C2 then drag down

=IF(COUNTIFS(Sheet1!$A$2:$A$14,A2,Sheet1!$B$2:$B$14,B2,Sheet1!$C$2:$C$14,"Holiday")>=1,"Holiday","")
 
Upvote 0
@kvsrinivasamurthy, thanks for the inputs. Your formula indeed worked well for this data, when the third condition is a "Holiday". But the formula by Marcelo is much robust as it extracts the data from the third column without looking at its content. As said earlier, "Holiday" is just an example, there could be wide variety of data in column C, and I would like to extract the same.

Thanks once again for all your inputs.
 
Upvote 0
oops...

Disregard my formula in post 2 - i pasted the wrong formula

Try in G2 copied down
=IFERROR(""&INDEX($C$2:$C$14,MATCH(1,IF($A$2:$A$14=E2,IF($B$2:$B$14=F2,1)),0)),"")
Ctrl+Shift+Enter

M.

Hi Marcelo,

Just wondering what the ""& does right before the INDEX function? I assume concatenating something, but not sure.

Thanks,
James
 
Upvote 0

Forum statistics

Threads
1,213,557
Messages
6,114,287
Members
448,562
Latest member
Flashbond

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top