Matching values in two tables with multiple conditions - excel

I have 2 Tables in Excel from SQL that I need to match.
Table 1:
Table 2
I would need to look up in Table 2 for date in column B where category is Relevant and return it into Table 1 where in Table 1 category is first visit.
I have tried all different formulas and it doesn't work.
Combination of INDEX() and MATCH() generally does not work.For example:
=INDEX(Table2B:B,MATCH(MAX(IF(Visitors number="AAAA",Order_Date)),Order_Date,0))
I get error.
The data set can be messy and too big, so I can not predefine that I am searching for second or third value.
Large with multiple criteria does not work either. I just get 0 or error. For example:
=LARGE(IF((Table2A2=Table2B:B)*(Table2B2>=Table1A:A);Table2C:C);1)
neither does SUMPRODUCT():
=SumProduct(LARGE((Table2A:A=Table1B2)*(Table2B2>=Table1A2*(Table2C:C);1))
Any kind advice of solution?
Thankful in advance.

Use the following ARRAY FORMULA:
=IF(C2="First Visit",INDEX(Table2!A:C,MATCH(A2&B2,Table2!B:B&Table2!A:A,0),3))
To make it work confirm it with CTRL+SHIFT+ENTER instead of ENTER to get the brackets {}:
{=IF(C2="First Visit",INDEX(Table2!A:C,MATCH(A2&B2,Table2!B:B&Table2!A:A,0),3))}

Related

How can I find the code I need based on multiple lookup values in my table, based on data in a reference table

I'm trying to find the code for the best match in a table using 4 lookup values.
In the image below the left table A to E is a static table and is the reference table
The right table normally on a separate sheet has multiple lines of varying data, where I need to find the correct code based matching the Name, Age and Age Calc from, using the information in the reference table.
I have tried VLOOKUP and INDEX/MATCH, but I'm struggling with the multiple lookup values.
The answers I need in J are: 5678, 7654, 4679, 7654, 1234.
What would be my best method of achieving my code results?
You can do this with a SUMIFS:
=SUMIFS(E:E,A:A,G2,B:B,"<="&H2,C:C,">="&H2,D:D,I2)
Assuming there can be only one match, then do something like:
=SUMIFS($E$2:$E$6,$A$2:$A$6,G2,$B$2:$B$6,"<="&H2,$C$2:$C$6,">="&H2,$D$2:$D$6,I2)
This is the formula that worked for me.
=INDEX(E:E,AGGREGATE(15,6,ROW(E$2:E$6)/(A$2:A$6=G2)/(B$2:B$6<=H2)/(C$2:C$6>=H2)/(D$2:D$6=I2),1))

How to specify multiple ranges in excel filter formula

I would like to be able to use Excel's filter formula and get only specific columns as a result.
For example, I tried the below formula and failed.
=FILTER((A:B,D:D),A:A=3475,"")
How can I get this working? I want to get the filtered result where any value in column A equals 3475, and only get columns A,B and D
You could use a single one formula like:
=TRANSPOSE(CHOOSE({1,2,3},FILTER(A:A,A:A=3475),TRANSPOSE(FILTER(B:B,A:A=3475)),TRANSPOSE(FILTER(D:D,A1:A4=3475))))
But considering performance, I'd go with two seperate formulas as proposed in the comments.
You need use the proper array for the array argument to the filter function.
I used a Table since using whole-column references is inefficient.
For example, if you want to return only columns 1,2 and 4 of a table, you can use:
=INDEX(Table1,SEQUENCE(ROWS(Table1)),{1,2,4})
So your filter function might be:
=FILTER(INDEX(Table1,SEQUENCE(ROWS(Table1)),{1,2,4}),Table1[colA] = myVar)
IF, for some reason you don't want to use Tables, the following formula should also work:
=FILTER(INDEX($A:$D,SEQUENCE(LOOKUP(2,1/(LEN($A:$A)>0),ROW($A:$A))),{1,2,4}),myVar=INDEX($A:$A,SEQUENCE(LOOKUP(2,1/(LEN($A:$A)>0),ROW($A:$A)))))
as would, the less efficient:
=FILTER(INDEX($A:$D,SEQUENCE(ROWS($A:$A)),{1,2,4}),myVar=$A:$A)

How to use Countif and Vlookup togther

I am trying to combine COUNTIF and VLOOKUP function so that I can use it to formulate my work and increase my efficiency.for better understanding suppose a column A has 4 people name like 1.jay 2.harry 3.ray . So i have assign them randomly "0" and "1" . SO ray might get multiple "0" and "1" and these can happen with everyone. So I want to know how may "0" and "1" each one get.
I have tried everything I know but its giving me wrong data
=COUNTIF(VLOOKUP(A2,A:B,2,0),"0")
after using the above code its giving me wrong output .
use COUNTIFS()
=COUNTIFS(A:A,$D2,B:B,E$1)
Method 1
Using the following SUMPRODUCT formula suppose you have named values in Column A as NameList and named values in Column B as Value:
=SUMPRODUCT((NameList=$D2)*(Value=E$1))
If you want to use formula, I would recommend the COUNTIFS function suggested by Scott Craner as it is faster than SUMPRODUCT in a large scale.
Method 2
You can quickly insert a pivot table and set up as shown above to get the count per value per name with a few clicks. Pro is that you do not even need to find the names from the list first, Con is that it is not that flexible to do further calculations from the values within a pivot table.

Excel Formula Vlookup the value by referring Row and Column

In the sheet1 i have a table called working days of the countries as shown in the below image.
In the Sheet2 i have 10 columns in that based on the country and month by referring the this table i am trying to populate the values, When i tried doing by Vlookup the first row alone getting populated, but in the second row the header from F1:T1 is getting changed to F2:T2 so rest of the cells showing as #NA.
Anyone can you please give a solution for my issue. Here is the formula i have used.
=VLOOKUP(I1,Sheet1!F2:T7,MATCH(Sheet2!M1,Sheet1!F1:T1,0))
Thanks in Advance.
You are missing the symbol $ to lock the ranges, and the false condition to match exact values in the VLOOKUP.
It should be like:
=VLOOKUP(I1,Sheet1!$F$2:$T$7,MATCH(M1,Sheet1!$F$1:$T$1,0),0)
Or instead of VLOOKUP use HLOOKUP like:
=HLOOKUP(M1,Sheet1!$F$1:$T$7,MATCH(I1,Sheet1!$F$2:$F$7,0),0)
In general, combining the INDEX and MATCH functions is a superior option to VLOOKUP. For example, =INDEX(Sheet1!F:F,MATCH(Sheet2!M1,Sheet1!F1:T1,0)). This allows you to go left-to-right or right-to-left as well.
Snip for Index Match functions Using Vlookup won't work here because in the 2nd table you are repeating the country, unlike the first table. Use a combination of index match function, this is little trickier than the vlookup but it will fulfill your requirements.
Since I don't have the exact table you shared so I created a table on my end and sharing the snip here.

Searching for an excel entry with 2 conditions to be met

I have a dataset on excel with more than 40k entries, and there are 2 columns.
I want to find if there exists an entry for example with 1 in the first column and 1687 in the second column, I tried using this following IF function:
=IF(COUNTIF(B2:B178,"1687"),"Yes","No)
where A1:A178 have 1 in the first column.
This function works perfectly alright, however in terms of selecting the range for Countif, it requires much work as sometimes the range i have is more than 3 to 4k. This is way too time consuming as I have to repeat this search for many pairs of numbers.
I then tried by adding a helper column, where the 1st entry would be "=A2&B2"
My plan was to search this entire helper column for "11687" instead, however this fails to identify entries where it has 1 in the first column, 1687 in the second, and 11 in the first column, and 687 in the second column.
Ideally if the "find" function (Ctrl+F) could find 2 columns for different values it will be exactly what I need.
Could anyone please advise me on how to do this search?
Thank you very much!
Try this formula and fill it all the way down, should be more efficient than COUNTIF:
=IF(AND($A1="1",$B1="1687"),TRUE,FALSE)
Then you have a column of TRUE/FALSE that you can use to do what you want.
Change your range into a table and use built in Excel filtering capabilities. See http://office.microsoft.com/en-001/excel-help/filter-data-in-a-range-or-table-HP010073941.aspx#BMfilter_text

Resources