Excel lookup for single and multiple criteria together - excel

I have 10000 rows of data in excel in column A & B and a new sheet with all data from column A. What i want to do a VLOOKUP from sheet 1 to sheet 2. But there are few examples in column A with 2 values in B.
Example:
Sheet 1
In sheet 2 if VLOOKUP is done for orange I am expecting 20,30
I have tried single criteria =VLOOKUP(A2,sheet2!a1,false) which worked for apple
Any suggestions how both the expected results can be done together

Not sure if it helps, but here's a solution with the formula:
Array formula in cell E2 (Ctrl+Shift+Enter):
=SUMPRODUCT(LARGE((--(IF(LEN($A$2:$A$6),$A$2:$A$6,OFFSET($A$2:$A$6,-1,0))=$D2))*($B$2:$B$6),1))
In column F you need to replace "1" (at the very end of the formula) with number "2".
A few notes:
your data set cannot start in row 1, otherwise OFFSET formula won't work.
both formulas (columns E & F) are looking for the 1st and 2nd largest number which matches the argument (column D). If the second one doesn't exist, it returns 0.
However, given the size of your data set, it is worth considering a VBA solution.
Edit: adjusted for column B = text
Use the following Array formula in cell E2 (Ctrl+Shift+Enter):
=IFERROR(INDEX($B$2:$B$6,SUMPRODUCT(LARGE((--(IF(LEN($A$2:$A$6),$A$2:$A$6,OFFSET($A$2:$A$6,-1,0))=$D2))*(ROW($B$2:$B$6)),1)-1)),"")
Similar Array formula in cell F2 (Ctrl+Shift+Enter):
=IFERROR(INDEX($B$2:$B$6,SUMPRODUCT(LARGE((--(IF(LEN($A$2:$A$6),$A$2:$A$6,OFFSET($A$2:$A$6,-1,0))=$D2))*(ROW($B$2:$B$6)),2)-1)),"")
Result:

Related

Using VLOOKUP to match 2 cells sheet2 to sheet1 and return the 3rd cell

I have been using VLOOKUP() to populate worksheets with Inventories, however I'm stuck with an issue where one column has the same value in multiple cells, I need to match 2 cells from sheet 2 with sheet 1 and have it return the 3rd cell from sheet 1 into sheet 2.
I'm working with about 350 rows in both sheets, and in some cells the same/different values repeat it self hence needing it to match with 2 cells in the same row.
This is the formula I currently use:
=VLOOKUP(A1&L1,'Sheet1'!$A$1:$E$351,3,FALSE)
I'm expecting it to return the value that's in the 3rd column on sheet 1 in the row that matched the values of Cell A1 and L1 in sheet 2. and the same going on A2 & L2 then A3 & L3 and so forth.
Unless you have values in Column A of your 'Sheet1' that are the equal to to concatenation of your values in Columns A and L in 'Sheet2', the formula will not work.
Instead, I'd try FILTER if you have the newest version of Excel. Something like:
=FILTER('Sheet1'!$C$1:$C$351,
(('Sheet1'!$A$1:$A$351=A1)*('Sheet1'!$L$1:$L$351=L1)))
Another option is INDEX. Something like:
=INDEX('Sheet1'!$C$1:$C$351,
MATCH(A1&L1, 'Sheet1'!$A$1:$A$351&'Sheet1'!$L$1:$L$351,0),
3)
The only way to do this task is to use a helper column
Go to Sheet one where the data table is, insert a column at the starting point of data e.g your Data set starting in SHEET1 from the column A. so insert new column in A
use this formula in A1
=CONCATENATE(B1,C1,D1,E1,F1) Press Enter, Drag the formula down to A351
now go to sheet2 and use this formula in the result cell
=VLOOKUP(A1&L1,'Sheet1'!$A$1:$F$351,4,0)

Excel: How do I efficiently condition a cell so that I can identify a cell with observation counts less than a certain number?

Basically I wanted to only extract the top 2 rows for every Entry #, but if the Entry # does not have 2 rows it is not used.
I tried IF statements and eliminating blanks and whatnot, but if this is a large data I would not be able to handle it.
If you don't mind adding a few columns, here's one method. Arrange how you wish.
Column's B and F are your original data.
Column C, in cell C2, input your first value manually (1 in this case).
Then here's the formula for Cell C3:
=IF(ISBLANK(B3),C2,B3)
Cell D2 formula:
=IF(C2=C1,D1+1,1)
Cell E2 formula:
=IF(COUNTIF(C:C,C2)>1,"Yes","No")
Drag down your formulas.
Then you can filter on column E for YES, and filter on column D for 1 & 2.

How to refer to multiple adjacent cells

I have a work sheet in which there are several cells with a specific entry - let's say "A". These are not all in the same rows/columns. After each cell is a date.
I need to count the number of cells containing "A" which also have a specific date in the cell immediately to its right. I've tried combinations of Countifs and Indirect, with no success. How can I achieve this?
This counts the number of times that there is A in column A and 1 in column B
=SUMPRODUCT(($A$1:$A$5="A")*($B$1:$B$5=1))
This outputs in cell D1
Not too difficult.
I have created a sample sheet with 8 rows and 5 columns of data.
See below, the formula in cell C12 counts the number of occurrences where the a cell with a date of October 31, 2017 is directly to the right of a cell that contains the text A.
If you want more info as to how this works, read on:
When searching for cells that contain A, you don't search in the last column of the data (in this case, column E) because it is impossible for a column to the right to have any date in it. This is why a portion of the formula says A1:D8="A" instead of A1:E8="A". This is the same reasoning why we start searching for a date in column B rather than column A in the formula.
You can achieve this with a helper row. Add additional row on top of your Worksheet. In cell "A1" enter formula below.
=COUNTIFS(A2:A2000,"A",B2:B2000,"YourDate")
Drag this formula to the rightmost of where you have data, then simply sum all values returned by formula.

Using INDEX-MATCH to look for values in two columns and returning a third value

I am creating a matrix of sorts, where column A has a list of parts and the Row 1 is populated with weeks of the year in yyyy/mm format. What I am trying to do is populate this matrix with quantity data from an aggregate sheet, where the demand quantities for each part is listed by week of the year. In this aggregate sheet, column A lists the parts, column B lists the weeks, and column C lists the quantities.
I've been trying to write an =INDEX(MATCH(),MATCH()) type of formula in order to fetch the value of column C if the values from Columns A & B match the values in Column A and Row 1 respectively on the matrix sheet, but have been only getting #REF errors in return. At this point I need a second pair of eyes. Here is the formula:
=INDEX(MRP!$C$1:$C$6400,MATCH(A2,MRP!$A$2:$A$6400,0),MATCH(B1,MRP!$B$2:$B$6400,0))
Am I going about this the right way, or is another method needed instead?
Cell B2
=SUMIFS(MRP!$C:$C,MRP!$A:$A,Sheet1!$A3,MRP!$B:$B,Sheet1!B$1)
You can then copy these down and across.
You are getting the #REF error because you are out of range of the array you are trying to match. The index function takes two arguments and one optional argument.
INDEX(array, row_num, [column_num])
Looking at your formula,
=INDEX(MRP!$C$1:$C$6400,MATCH(A2,MRP!$A$2:$A$6400,0),MATCH(B1,MRP!$B$2:$B$6400,0))
MRP!$C$1:$C$6400 is the array to be matched
MATCH(A2,MRP!$A$2:$A$6400,0) gets the row number. Maybe it should be MATCH(A1....)?
MATCH(B1,MRP!$B$2:$B$6400,0) gets the column number.
But since your matching array only have one column, the column number from the match function is greater than 1, which is outside the range of the array.
If you need to match both values in column A and B, you can use this formula to match
=MATCH(lookup_value_1 & lookup_value_2, lookup_array_1 & lookup_array_2, match_type)
For you case, it would be
=MATCH(A1 & B1, MRP!$A$2:$A$6400 & MRP!$B$2:$B$6400, 0)
you'll need to commit your formula using Ctrl+Shift+Enter rather than just pressing Enter. This will get you the row number where both col A and B matches cell A1 and B1.
Finally, you can index it
=INDEX(MRP!$C$1:$C$6400,Result from above match,0)
I would use SUMIFS. Create a helper column in your second sheet with the month number in and then use
=SUMIFS(sheet2!column C, sheet 2!helper column, month(sheet1!A$1),sheet2! column A, sheet1!$A1)

search for 2 parameters in column and returning a third column

I am trying to search from inside spreadsheet 1 into spreadsheet 2 for 2 things that must be true and if so, pull back another column row.
I want to search column A for the number 12345 and column B for the string "GBP" but I do not know what row 12345 and "GBP" will occur on. If found (there can only ever be 1 result returned so don't worry about multiple results) I need to return the value in column C.
The thing is - I am finding this tricky. Can you help me please?
Create a column C where each cell to the right of data contains the formula
=IF(AND(A2=12345,B2="GBP"),1,0)
When you have copied that formula into each cell down the entire column, search that column for a "1". The "1" is what you are looking for.
As long as there is 1 row matching the criteria, you can use SUMIFS function to get the value from the matching cell:
assuming A2=12345 and B2="GBP" on the current sheet,
sum all values on Sheet 1 column C where both columns A and B match the specified criteria:
=SUMIFS(Sheet1!C:C,
Sheet1!A:A, A2,
Sheet1!B:B, B2)

Resources