-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathTable.RowsCombination2.pq
30 lines (27 loc) · 1.51 KB
/
Table.RowsCombination2.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(tables as list) =>
let
// tables = { Table1, Table2, Table3, Table4, Table5 },
add_tables = List.Last(
List.Generate( ()=>
[i=0, T=tables{0}],
each [i] <= List.Count( tables ) - 1,
each [i=[i]+1,
T= Table.AddColumn( [T], "Custom." & Text.From( i ), each tables{ i } ) ],
each [T] ) ),
expand_tables = List.Last(
List.Generate( ()=>
[i=0, T=add_tables],
each [i] <=List.Count( tables ) - 1,
each [i=[i]+1,
T= Table.ExpandTableColumn( [T],
"Custom." & Text.From( i ),
Table.ColumnNames( tables{0} ),
List.Transform( Table.ColumnNames( tables{0} ), each Text.From(_) & "." & Text.From( i ) ) ) ],
each [T] ) ),
#"Added Index" = Table.AddIndexColumn(expand_tables, "Index", 1, 1),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "NewValue"),
#"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns","Attribute",Splitter.SplitTextByEachDelimiter({"."}, QuoteStyle.Csv, false),{"Attribute.1", "Attribute.2"}),
#"Pivoted Column" = Table.Pivot(#"Split Column by Delimiter", List.Distinct(#"Split Column by Delimiter"[Attribute.1]), "Attribute.1", "NewValue"),
#"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Attribute.2"})
in
#"Removed Columns"