Unique Values in Array Vlookup Function

rpm567

New Member
Joined
Jun 29, 2016
Messages
9
I've been trying to understand the array vlookup approach and have not been successful. If I have a list of item codes and I want to return a list of the unique items horizontally

If starting in B2, I enter this table:

CategoryItem
CoffeeEspresso
CoffeeEspresso
CoffeeCappuccino
SodaCoke
OtherWater
CoffeeEspresso
CoffeeAmericano

<tbody>
</tbody>

Then I want to list out, horizontally, the Coffee orders, I use the array formula:

{=IFERROR(INDEX($B$2:$C$9,SMALL(IF($B$2:$B$9=$E2,ROW($B$2:$B$9)-1),COLUMNS($F2:F2)),2),"")}

Where cell E2 is Coffee (or could be one of the other categories).

My issue is that there are a ton of orders and I would like to edit this so that I only return unique values.

It takes all of my excel skill and brain power to understand the equation I wrote, if someone can offer the solution for unique values and also a brief explanation as to how it works, it would be greatly appreciated. Thanks in advance!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hi rpm,

Well, firstly, if you are looking for an easier way to do this, you could copy down the items and paste them in a separate column, then remove duplicates, and then copy the range then paste special 'transpose' the data.

But if you are set on a formula, the I think a helper column could be useful (I use them all the time). Try the below setup.

How my formulas work are by:

D2: Counts how many Items are within the range. It locks on Cell C2 that way it increments as it is copied down. I think it'll make sense if you take a look at it.

F2: Counts how many 1's are in the helper column. Because we only want to extract the names with a one next to them, since those are the first of the numbers for the names, anything name with a number higher than 1 next to it is a duplicate and should be ignored in our final formula.

G4: IF(COLUMNS($G$4:J$4)>$F$2,"" <--- means, if the number of columns the formula copies over to is greater than the count of 1's in the helper column, then blank, ELSE

INDEX($C$2:$C$8,SMALL(IF($D$2:$D$8=1,ROW($C$2:$C$8)-ROW($C$2)+1),COLUMNS($G$4:J$4))) <---- means, well, i think you should evaluate this formula (Alt, T, U, F) and take a look for yourself and then reply with specific questions about it. Sorry, I actually have to go eat. Hope this has helped....

Excel Workbook
BCDEFGHIJKL
1CategoryItemHelperCount of 1's
2CoffeeEspresso15
3CoffeeEspresso2
4CoffeeCappuccino1FormulaEspressoCappuccinoCokeWaterAmericano
5SodaCoke1
6OtherWater1
7CoffeeEspresso3
8CoffeeAmericano1
Sheet2
 
Last edited:
Upvote 0
I think I can help a bit. Check out this thread in the Forum, especially the video, for some ideas on how to extract a unique list based on criteria.

http://www.mrexcel.com/forum/excel-...ws-based-numerous-conditions.html#post4643968

Also this: http://www.mrexcel.com/forum/excel-questions/942043-data-validation-list.html#post4525625

Here I've done the report in rows, but you could shift to columns if necessary. Copy A17 down as far as or farther than indicated by the unique count indicated in B13.

ABC
1CategoryItem
2CoffeeEspresso
3CoffeeEspresso
4CoffeeCappuccino
5SodaCoke
6OtherWater
7CoffeeEspresso
8CoffeeAmericano
9
10
11
12
13Coffee (unique)3
14
15Coffee
16Coffee (unique)
17Espresso
18Cappuccino
19Americano
20
21
22
23
24

<tbody>
</tbody>
Sheet22

Array Formulas
CellFormula
B13{=SUM(IF(FREQUENCY(IF($B$2:$B$8<>"",IF($B$2:$B$8=$A$15,MATCH($B$2:$B$8&$C$2:$C$8,$B$2:$B$8&$C$2:$C$8,0))),ROW($B$2:$B$8)-ROW($B$2)+1),1))}
A17{=IF(ROWS(A$17:A17)>$B$13,"",INDEX($C$2:$C$8,SMALL(IF(FREQUENCY(IF($B$2:$B$8<>"",IF($B$2:$B$8=$A$15,MATCH($B$2:$B$8&$C$2:$C$8,$B$2:$B$8&$C$2:$C$8,0))),ROW($B$2:$B$8)-ROW($B$2)+1),ROW($B$2:$B$8)-ROW($B$2)+1),ROWS(A$17:A17))))}

<tbody>
</tbody>
Entered with Ctrl+Shift+Enter. If entered correctly, Excel will surround with curly braces {}.
Note: Do not try to enter the {} manually yourself.

<tbody>
</tbody>
 
Last edited:
Upvote 0
Another similar way.

With a drop down (or just type in the category) in E1 and this helper formula in D2 copied down.

Code:
=IF(B2="","",IF(COUNTIFS($B$2:B2,$E$1,$C$2:C2,C2)=1,ROWS($2:2),""))

Enter this in F3 and fill across.

Code:
=IFERROR(INDEX($C$2:$C$100,SMALL($D$2:$D$100,COLUMNS($F:F))),"")

Row\Col
B​
C​
D​
E​
F​
G​
H​
I​
J​
K​
1​
CategoryItemCoffee
2​
CoffeeEspresso
1​
3​
CoffeeEspressoEspressoCappuccinoAmericano
4​
CoffeeCappuccino
3​
5​
SodaCoke
6​
OtherWater
7​
CoffeeEspresso
8​
CoffeeAmericano
7​
9​
10​
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,071
Messages
6,128,622
Members
449,460
Latest member
jgharbawi

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