Change the format of some data from a table to a list

rpg1966

New Member
Joined
Mar 12, 2015
Messages
19
Hello everyone,
I have a requirement to change the format of some data from a table to a list.

The data I have at the moment looks like this:

6 Jan 20185 Jan 20184 Jan 20183 Jan 20182 Jan 20181 Jan 2018
Group1
Group2Location1
Group3Location1
Group4
Group5Location2
Group6Location5
Group7Location6Location3
Group8Location2
Group9

<tbody>
</tbody>

The required list looks like this (the column ordering is not important):

DateLocationGroup
1 Jan 2018Location1Group2
1 Jan 2018Location2Group5
2 Jan 2018Location3Group7
3 Jan 2018Location1Group3
4 Jan 2018Location6Group7
4 Jan 2018Location2Group8
6 Jan 2018Location5Group6

<tbody>
</tbody>


I'd have thought I'd be able to find something I could use in the forum, but my searches based on words like "table" and "list" don't seem to bring up anything relevant.

Any help is greatly appreciated!
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Power Query makes quick work of this kind of task. Formulas would be too tough.

Here is the M-code to unpivot that kind of data (using your data as one called Table3). I hope it helps you, but I will include here for everyone's benefit.

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Group", type text}, {"06-Jan-18", type text}, {"05-Jan-18", type any}, {"04-Jan-18", type text}, {"03-Jan-18", type text}, {"02-Jan-18", type text}, {"01-Jan-18", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Group"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Columns",{{"Attribute", "Date"}, {"Value", "Location"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Date", "Location", "Group"}),
    #"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"Date", Order.Ascending}, {"Group", Order.Ascending}, {"Location", Order.Ascending}})
in
    #"Sorted Rows"
 
Last edited:
Upvote 0
Cheers! I have to learn about Power Query and how to run your code first, so apologies for not replying immediately with a "Thanks, that works!", but thanks in advance for when I get it working :)
 
Upvote 0
Power Query is powerful. Go to youtube to the ExcelIsFun channel and search through the vids for PQ basics. You will learn at a geometric rate by watching videos. Feed your head.
 
Upvote 0
Mate, you're a genius. I've got it running after a couple of tiny tweaks to my source data.

The only issue I can see so far is that the date ordering of the results table isn't correct, as there's no year included. My data spans more than one year, so I guess I need to change all the {"9-Jun", type text} entries to {"9-Jun-2018", type text}.
 
Upvote 0
Right. I believe that In Excel all date-like things should be converted to Excel Date Serial Numbers. Always. Data analysis is so much simpler that way and errors are less likely.
 
Upvote 0
Ah, I just had to change the formatting of the date row, and all is well. Thank you so much!!
 
Upvote 0
Good show! I'm glad it worked. You're welcome.

Now, make sure to regularly watch the vids on ExcelIsFun and subscribe to the channel.
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,600
Members
449,038
Latest member
Arbind kumar

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