|
| 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