VLOOKUP when criteria exists mutliple times in matrix - excel

I have the following Excel spreadsheet:
A B C D
1 Product A 500 Product A 500
2 Product B 800 Product A 700
3 Product C 450 Product A 300
4 Product A 700 Product B 800
5 Product A 300 Product B 400
6 Product C 300 Product B 250
7 Product B 400 Product C 450
8 Product B 250 Product C 300
In Column A and Column B the sales of differnt products are listed. A product can appear several times in Column A because each sale of the product is displayed.
In Column C the different products are sorted from A-C.
In Column D I want to use a VLOOKUP to get the sales from Column B for each of the products.
=VLOOKUP(C1,$A$1:$B$8,2)
However, since the products appear several times in Column A the VLOOKUP gives me only back one of the values.
How do I have to change the VLOOKUP to get each sale of the same product?

You cannot get desired result single VLOOKUP formula.
Use this array formula:
=INDEX($B$1:$B$8,SMALL(IF($A$1:$A$8=C1,ROW($A$1:$A$8)-ROW(INDEX($A$1:$A$8,1,1))+1),COUNTIF($C$1:C1,C1)))
Paste it into D1 and press CTRL+SHIFT+ENTER to change it into array formula, then pull formula down.

Another approach:
Insert one empty row above the data, then put this formula in column D (you can hide this column if you want to):
=MATCH(D2;INDIRECT("$A"& 2 + IF(D2=D1;E1;0) & ":$A$9");0)+IF(D2=D1;E1;0)
And this formula in column E:
=INDEX($B$2:$B$9;E2)
MATCH works similar to VLOOKUP but instead of the actual value returns the index of the result. INDIRECT("$A"& 2 + IF(D2=D1;E1;0) & ":$A$9") alters the searchmatrix based on the previous index of the search value (e.g. the first "Product A" is found at index 1 therefore the second "Product A" only looks in A3:A9, the second "Product A" is at index 4 thus the third "Product A" looks in A6:A9).
The second formula just extracts the value based on the matrix in column B and the index in column D.

Related

How to match up 2 columns with 2 other columns

In column A I have product id's and column B has the number of times the product in column A was quoted.
In column C I have the same product id's (but in different order) and column D has the number of times the product in column C was actually sold.
I want to match them up to add a final column in order to divide sales/quoted in order to get a value of efficiency in sales.
I believe it's an index/match/match but I'm not sure how to set it up.
Please help
Try
=B3/vlookup(A3,C:D,2,false)
In words: take the value in B3 and divide it by the value from column D where column C has the same text as A3.

Sort list by the difference between two values

I have the following Excel spreadsheet:
A B C D
1 Budget Actual Sort by Variancy (descending)
2 Product A 500 250 Product F
3 Product B 900 800 Product D
4 Product C 300 450 Product C
5 Product D 400 600 Product B
6 Product E 700 300 Product A
7 Product F 150 900 Product E
As you can see in Column A I have listed different products and in Column B I have their budget value and in Column C the actual value.
Now, I want to list those products based on their budget-actual-variancy in Column D in a descending order (starting from the highest positive variancy).
The only formula which comes in my mind is =LARGE(B2:B7,1) but it only sorts the products by the budget values (Column B) or actual values (Column C). Not by the difference between the two values.
Do you know any formula which I can use to sort the products in Column D based on their variancy?
Please note:
I know I could add a helper column in which I calculate the differences between Column B and Column C and then go with the LARGE function on this helper column but I am looking for a solution without such a helper column.
If one has SORTBY()(Currently only available with Office 365 insiders) then put this in D2 and it will spill automatically:
=SORTBY(A2:A7,B2:B7-C2:C7,1)
You can use the following (even when there are duplicate variances):
Formula in D2:
=INDEX($A$1:$A$7,LARGE(INDEX(($C$2:$C$7-$B$2:$B$7=AGGREGATE(14,3,$C$2:$C$7-$B$2:$B$7,ROW(1:1)))*($A$2:$A$7<>D1)*ROW($A$2:$A$7),),1))
Drag down.
In case of duplicate variances it will grab the last value in column A that represents that variancy and has not been featured in column D as yet.

List items based on criterias in two different columns

I have the following Excel spreadsheet:
A B C
1 Product Sales List
2 Product A 500 Product A
3 Product B Product C
4 Product C 400 Product D
5 Product E
6 ="" Product F
7 Product D 600 Product H
8 Product E 550
9 =""
10 Product F 200
11 Product G =""
12 Product H 800
In Column A and Column B different products with their sales are listed. As you can see it can either happen that there are empty cells or cells with ="" in both Column A or Column B.
In Column C I want to achieve now that only the products which do NOT have an empty cells or cells with ="" in Column A or Column B are inlcuded in the list.
I could already make it work for Column A with this formula:
={INDEX($A$2:$A$100,SMALL(IF(LEN($A$2:$A$100)=0,"",ROW($A$2:$A$100)-MIN(ROW($A$2:$A$100))+1),ROW(A1)))}
What do I have to change in this formula to also exclude the products wich have an empty cell or a cell ="" in Column B from my list in Column C?
When you have worked it out for Column A, it is very simple to do for B:
Each cell in Column D has the appropriate function: (Example for D2)
=VLOOKUP(D2, $A:$B, 2, 0)
NOTE: This assumes you don't have repeated values in Column A
doesn't have to be an array formula. use this formula in C instead.
=IF(AND(A:2<>"",B:2<>""),A:2,"")
Then autofill the formula. Then sort column C to get all product list.
or pivot the range by column C in row box to get the distinct product list in case A has duplicate products.

Sorting values of a selectable month

I have the following Excel spreadsheet:
A B C D E
1 January February March February
2 Product A 500 300 800 500
3 Product B 400 500 250 300
4 Product C 600 100 700 100
In Columns A:C you can see the sales of three different products.
In Column E the user can select a month in Cell E1.
Based on this month the sales should be listed ascending.
I think this requires something like a VLOOKUP combined with a LARGE function since the matrix from the LARGE function has to switch based on the month in Cell E1.
Do you have any idea how I could achieve this?
You could use HLOOKUP to locate the month in E1 in the range B1:D1, but this just gives the value of the month ("February") and you need the position of the month (from 1 to 3) to find the right column B,C or D so I suggest using Index and Match as follows
=IFERROR(LARGE(INDEX($B$2:$D$4,0,MATCH($E$1,$B$1:$D$1,0)),ROWS($1:1)),"")

Creating a new list and eliminate empty cells and cells with ="" from existing list

I have the following Excel spreadsheet:
A B C D
1 Product A 500 Product A 500
2 Product B 300 Product B 300
3 Product C 400 Product C 400
4 Product D 600
5 ="" Product E 550
6 Product D 600 Product F 200
7 Product E 550 Product G 800
8 =""
9 Product F 200
10 Product G 800
In Column A and Column B different products with their sales are listed. As you can see it can either happen that there are empty cells or cells with ="" in the list.
In Column C and Column D I want to achieve now that both the empty cells and the cells with ="" are deleted and the list of the product is shown without the empty cells and without ="".
In order to eliminate the empty cells I used this formula so far:
={INDEX(A:A,SMALL(IF(ISBLANK(A:A),"",ROW(A:A)-MIN(ROW(A:A))+1),ROW(A1)))}
How can I add the additional criteria exclude ="" to this formula in order to ignore the cells with ="" and get the list as seen in Column C and Column D.
Please try:
=INDEX(A:A,SMALL(IF(LEN(A:A)=0,"",ROW(A:A)-MIN(ROW(A:A))+1),ROW(A1)))
in C1 copied across one column and the pair down to suit, with CSE entry.

Resources