-
Notifications
You must be signed in to change notification settings - Fork 0
/
Unpivoter.pq
23 lines (23 loc) · 966 Bytes
/
Unpivoter.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
let
output = (t as table, keys as list) =>
let
schema = Table.Buffer(Table.Schema(t)),
UnpivotSchema = Table.SelectRows(schema, each not (List.Contains(keys, [Name]))),
TextColumns = Table.SelectRows(schema, each ([Kind] = "text"))[Name],
CleanEmptyTextColumns = Table.ReplaceValue(t, "", null, Replacer.ReplaceValue, TextColumns),
TypeToUnpivot = List.Distinct(UnpivotSchema[Kind]),
UnpivotFunction = (t, ty) =>
let
output = Table.UnpivotOtherColumns(
Table.SelectColumns(t, List.Combine({keys, Table.SelectRows(UnpivotSchema, each ([Kind] = ty))[Name]})),
keys,
"Attribute",
"Value" & Text.Proper(ty)
)
in
output,
LoopTypes = Table.Combine(List.Transform(TypeToUnpivot, each UnpivotFunction(CleanEmptyTextColumns, _)))
in
LoopTypes
in
output