List items based on criterias in two different columns - excel

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.

Related

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.

Get the column number of a search criteria in a defined range

I have the following Excel spreadsheet:
A B C D E F G H
1 Search Criteria: Prod.D
2 Column: 4
3 Prod.A Prod.B Prod.C Prod.D Prod.E
4
5
In Range D3:H4 I have Product A to Product E listed.
Now, I want to achieve that when I put a product name into Cell C1 I will get back the Column Number of the product in the range.
In the example above I want to search for Prod.D within the Range D3:H4 and therefore the result in Cell C2 should be 4 since the search criteria appears in the fourth column within the defined range.
What formula do I need to achieve this?
Try this formula in cell C2:
=MATCH(C1,D3:H3,0)

Create a unique list even if original list contains cells with =""

I have the following Excel spreadsheet:
A B
1 Original List Unique List
2 Product A Product A
3 Product A Product B
4 Product B Product C
5 =""
6 Product A
7 Product C
8 Product B
9 =""
10 Product C
In Column A I have list which contains several products multiple times. My goal is now to create a list of all unique items in Column B.
To achive this I used the formula from this post in Cells B2:B10:
B2:B10 =IFERROR(INDEX($A$2:$A$10,MATCH(SUM(COUNTIF(B$1:B1,$A$2:$A$10)),COUNTIF($A$2:$A$10,"<"&$A$2:$A$10),0)),"")
and I get the following result:
A B
1 Original List Unique List
2 Product A
3 Product A Product A
4 Product B Product B
5 ="" Product C
6 Product A
7 Product C
8 Product B
9 =""
10 Product C
This result comes pretty close to the list I want. The only issue is that the formula cannot handle the formula ="" which is in some cells in Column A. Instead of starting the list in Cell B2 it starts the list in Cell B3.
How do I have to mody the formula so it also works in case there are cells with ="" in the original list?
Could you use excel's built in 'Remove Duplicates' function?:
Range("$A$2:$A$10").RemoveDuplicates Columns:=1, Header:=xlNo
We can use a "helper" column. In C2 enter:
=IF(A2="","",IF(COUNTIF($A$2:A2,A2)>1,"",1+MAX($C$1:C1)))
and copy down. Column C assigns a simple sequential value to each item in column A from which data will be extracted. Then in B2 enter:
=IFERROR(INDEX($A$2:$A$10,MATCH(ROWS($1:1),$C$2:$C$10,0)),"")
and copy down:
Note:
This method uses normal formulas rather than array formulas.
You could use the Advanced Filter.
Use a Formula criteria such as =LEN(A5)>0 where A5 is the first cell with data. And then check the Unique Records Only in the Advanced Filter dialog. You can either filter in place, or to a new location

VLOOKUP when criteria exists mutliple times in matrix

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.

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