Moving data from multiple rows into multiple columns for the same ID number

Malkavian694

New Member
Joined
Apr 3, 2019
Messages
1
The data I have looks like
ID. Date. Status
1. 1/1/18. Complete
1. 6/30/18. Complete
1. 12/31/18. Refused
2. 1/15/18. Refused
3. 4/30/18. Complete
4. 2/1/18. Refused
4. 4/1/18. Complete

I want to get it to look like this
ID. Complete 1 Complete 2. Refused
1. 1/1/18. 6/30/18. 12/31/18
2. 1/15/18
3. 4/30/18
4. 4/1/18. 2/1/18

Does anyone have any suggestions?
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
if this is just an excel sheet a vlookup would work for you
 
Upvote 0
I do not know how many "refused" can exist with the same ID....so, i assumed that can be more than one "Refused" with the same ID.
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Tabela1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Date", type date}, {"Status", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"ID", "Status"}, {{"tbl", each _, type table [ID=number, Date=date, Status=text]}, {"Count", each Table.RowCount(_)  }}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "AddIdx", (x) => Table.TransformColumns(Table.AddIndexColumn(x[tbl], "Idx", 1, 1), {{"Idx", each x[Status] & " " & Text.From(_)}}  )  ),
    MaxComplete = List.Max(Table.SelectRows(#"Added Custom", each ([Status] = "Complete"))[Count]),
    MaxRefused = List.Max(Table.SelectRows(#"Added Custom", each ([Status] = "Refused"))[Count]),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"AddIdx"}),
    Combine = Table.Combine(#"Removed Other Columns"[AddIdx]),
    #"Removed Columns" = Table.RemoveColumns(Combine,{"Status"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Transform({1..MaxComplete}, each "Complete " & Text.From(_)) & List.Transform({1..MaxRefused}, each "Refused " & Text.From(_)), "Idx", "Date")
in
    #"Pivoted Column"
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,520
Members
448,968
Latest member
Ajax40

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