Vlookup/Index that returns all distinct values, but returns in a row?

Dogboydan

New Member
Joined
Aug 27, 2015
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
I'm looking for help setting up a formula that will allow me to have all distinct values for a lookup value in a vertical dataset, but I need the output to be in a horizontal output. The lookup range is a vertical set of emails, with the same email appearing multiple times, but potentially having the same or different results in the columns next to it. What I need is all distinct values related to that email from a column next to it, but returned in a single row.

I have found two array based formulas that accomplish to parts of this, but I can't seem to figure out a way to get it to do it together.

Distinct Values formula:
=IFERROR(INDEX('BL Department'!$G$2:$G$10000,MATCH(0,COUNTIF($M$4:M4,'BL Department'!$G$2:$G$10000)+('BL Department'!$A$2:$A$10000<>$A$5),0)),"")
or
IFERROR(INDEX(return_range, MATCH(0,COUNTIF(column_range, return_range)+(lookup_range<>lookup_value),0)),"")

This formula does what I want in that it returns only the distinct values, but it returns them in a column format.

Row All Results formula:
=IFERROR(INDEX('BL Department'!$G$2:$G$10000,SMALL(IF($A5='BL Department'!$A$2:$A$10000,ROW('BL Department'!$G$2:$G$10000)- MIN(ROW('BL Department'!$G$2:$G$10000))+1,""),COLUMN()-6)), "")
or
IFERROR(INDEX(return_range, SMALL(IF(lookup_value = lookup_range, ROW(lookup_range) - MIN(ROW( lookup_range))+1,""),COLUMN() - n)), "")

This formula returns the values in a row, but returns all of them.

Is there a way to modify the distinct values formula so that it returns on a row rather than a column?
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
What version of Excel are you using?

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
What version of excel are you using? Please update your profile so the forum can give an answer suitable to the version you have.
Also, if you can provide a small sample of data and an expected output, it would be of help.

Mr. Excel has a tool called xl2bb add in that allows you to post mini worksheets of your workbook. Liink below. If you cannot use the add in, then please post a table.
 
Upvote 0
Sorry! I'm using Excel 2016. I reminded myself to include that in the post, but then spaced.
 
Upvote 0
Thanks for that.
If you put your 1st formula in N4 & drag across, it should work.
 
Upvote 0
Hmm, that didn't seem to work sadly. I think because technically the formula is in M5 and N5 as for some reason it needs a to look above or it errors. I can't install the add-in due to restrictions, but I've made a sample table below of what the source data kinda looks like (Assume A1-A3 for headers).

EmailDepartmentDivision
sampleemail@gmail.comSalesAppliances
sampleemail@gmail.comSalesTech
sampleemail@gmail.comRepairComputer
anotheremail@gmail.comSalesVacuums
anotheremail@gmail.comManagementFloor
anotheremail@gmail.comManagementWarehouse

Expected output results would be something like:
EmailDepartment 1Department 2Division 1Division 2Division 3
sampleemail@gmail.comSalesRepairAppliancesTechComputer
anotheremail@gmail.comSalesManagementVacuumsFloorWarehouse
 
Upvote 0
If the formula is in M5 change the $M$4:M4 to $L$5:L5
 
Upvote 0
Solution
If the formula is in M5 change the $M$4:M4 to $L$5:L5
Thank you, that worked! I always am amazed at how simple the solutions are after smashing my head against it for so long haha.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,073
Messages
6,122,970
Members
449,095
Latest member
Mr Hughes

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