'Power Query - formatting - Adding Intermediate "summary" text row
I am transforming some data from a database, and at the end of one of the step, I need to reformat it for sending it as a document to a client. the usual template for this document has intermediate row with a sort of summary of one of the column (just text, no numbers). It would means going from first to second table here under. Is it possible ?
value 1 | value metadata1 | value's metadata 2 | grouping |
---|---|---|---|
First | 1st M1 | 1st M2 | group 1 |
Second | 2nd M1 | 2nd M2 | group 2 |
Third | 3rd M1 | 3rd M2 | group 3 |
Fourth | 4th M1 | 4th M2 | group 1 |
value 1 | value metadata1 | value's metadata 2 |
---|---|---|
group 1 | ||
First | 1st M1 | 1st M2 |
Fourth | 4th M1 | 4th M2 |
group2 | ||
Second | 2nd M1 | 2nd M2 |
group 3 | ||
Third | 3rd M1 | 3rd M2 |
Solution 1:[1]
In powerquery, try below
It groups on grouping and copies that into a new row in value 1 column before expanding
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"grouping"}, {{"data", each #table( {"value 1"}, {{_[grouping]{0}}}) & _, type table }}),
ColumnsToExpand = List.RemoveLastN(List.Distinct(List.Combine(List.Transform(Table.Column(#"Grouped Rows", "data"), each if _ is table then Table.ColumnNames(_) else {}))),1),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data",ColumnsToExpand ,ColumnsToExpand ),
#"Removed Columns" = Table.RemoveColumns(#"Expanded data",{"grouping"})
in #"Removed Columns"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | horseyride |