Skip to content

Commit d9ccf74

Browse files
authored
Create 2024-10 - 2023-03 - Split nested Csv into dimensions.pq
1 parent ebe852a commit d9ccf74

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
let
2+
/*
3+
input: (A,B), (A,B,C), D
4+
outputs the table:
5+
[
6+
{ "Name": "A,B", "Id":0 },
7+
{ "Name": "A,B,C", "Id":1 },
8+
{ "Name": "D", "Id":2 }
9+
]
10+
11+
*/
12+
SplitNestedNames = ( value ) as any =>
13+
let
14+
delim = "),",
15+
splitFunc = Splitter.SplitTextByDelimiter( delim, QuoteStyle.Csv ),
16+
segments = splitFunc( value ),
17+
cleaned = List.Transform( segments, each Text.TrimStart( Text.Trim(_), "(" ) ),
18+
unique = List.Sort( List.Distinct( cleaned ) ),
19+
asTable = Table.FromList(
20+
unique, Splitter.SplitByNothing(),
21+
type table [ Name = text ], null, ExtraValues.Error ),
22+
23+
indexed = Table.AddIndexColumn( asTable, "Id", 0, 1, Int64.Type )
24+
in indexed,
25+
26+
string = "(A,B), (A,B,C), D ", // your column
27+
28+
asJson = Text.FromBinary( Json.FromValue( Final ) ),
29+
30+
Final = SplitNestedNames( string )
31+
in
32+
Final

0 commit comments

Comments
 (0)