Forum Discussion
D_HL
3 years agoFrequent Visitor
Help with Excel Data in wide view, over multiple sheets
Good morning all, I hope you are well. I'm trying to work out the most effective way to tackle a data set I have been asked to produce visuals from. The excel sheet consists of separate sheets, ...
D_HL
3 years agoFrequent Visitor
Thanks Jing,
The tricky element to it is that I need to make the sheet name the column header for the values presented in the sheet. My end game would be something like this...
| Primary Sector | Secondary Sector | Date | Total | Outstanding | Good Quality | Bad Quality |
| A | A | 01/01/2023 | £8.5 | £4.5 | £4.0 | £0.5 |
| A | B | 01/01/2023 | £5.5 | £2.5 | £2.5 | £0 |
| A | C | 01/01/2023 | £2.1 | £2.0 | £0.0 | £2.0 |
| B | A | 01/01/2023 | £8.4 | £5.4 | £1.0 | £7.4 |
Thanks
Dan
v-jingzhang
3 years agoCommunity Support
Hi D_HL
You can try this query. Just replace the file path in the first Source step.
let
Source = Excel.Workbook(File.Contents("C:\Users\administrator\Desktop\Data.xlsx"), null, true),
#"Removed Other Columns" = Table.SelectColumns(Source,{"Name", "Data"}),
#"Added Custom" = Table.AddColumn(#"Removed Other Columns", "NewData", each Table.UnpivotOtherColumns(Table.PromoteHeaders([Data], [PromoteAllScalars=true]), {"Primary Sector", "Secondary Sector"}, "Attribute", "Value")),
#"Removed Other Columns1" = Table.SelectColumns(#"Added Custom",{"Name", "NewData"}),
#"Expanded NewData" = Table.ExpandTableColumn(#"Removed Other Columns1", "NewData", {"Primary Sector", "Secondary Sector", "Attribute", "Value"}, {"Primary Sector", "Secondary Sector", "Attribute", "Value"}),
#"Pivoted Column" = Table.Pivot(#"Expanded NewData", List.Distinct(#"Expanded NewData"[Name]), "Name", "Value"),
#"Renamed Columns" = Table.RenameColumns(#"Pivoted Column",{{"Attribute", "Date"}})
in
#"Renamed Columns"
I take only two sheets in my sample but never mind this query works with more sheets.
Steps are:
Add a custom column to transform the original Data column first (promote the first row to headers and unpivot).
Remove the original Data column, then expand the NewData column.
Pivot Name column.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.