Transposing data vertically to horizontally for duplicate vs non duplicate data

lizsunnysideup

New Member
Joined
Jun 29, 2019
Messages
36
Hello there. I was given a task that has 40k rows of member data and drugs. Column D has member ID numbers but the report includes duplicate member who have filled different medications so the report looks like this:

Column D Column O
0001 VIAGRA 50MG
0001 LISINOPRIL 10MG
0001 VIAGRA 50MG
0001 SEVERVENT INHALER
0002 FINASTERIDE 5MG
0003 ELIQUIS 10MG
0003 LISINIOPRIL 20MG

How do I remove the duplicates from Column D and O AND how do I go from listing each individual drug for people that filled more than 1 drug horizontally in Column P, Q, R, etc with each drug moving to the next column to the right? So for instance:

Column D Column O Column P Column Q
0001 VIAGRA 50MG LISINORPIL 10MG SEREVENT INHALER
0002 FINASTERIDE 5MG
0003 ELIQUIS 10MG LISINOPRIL 20MG
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
I would use Power Query to get the expected results

Book6
ABCDEFGH
21VIAGRA 50MG1VIAGRA 50MGLISINOPRIL 10MGVIAGRA 50MGSEVERVENT INHALER
31LISINOPRIL 10MG2FINASTERIDE 5MG
41VIAGRA 50MG3ELIQUIS 10MGLISINIOPRIL 20MG
51SEVERVENT INHALER
62FINASTERIDE 5MG
73ELIQUIS 10MG
83LISINIOPRIL 20MG
Sheet1


Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Column1"}, {{"Count", each _, type table [Column1=number, Column2=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1,1)),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Column1", "Column2", "Index"}, {"Column1", "Column2", "Index"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Expanded Custom", {{"Index", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Expanded Custom", {{"Index", type text}}, "en-US")[Index]), "Index", "Column2")
in
    #"Pivoted Column"
 
Upvote 0
Solution

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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