Forum Discussion
split values into multiple rows
- 9 years ago
Add a custom column with this formula:
= Table.AddColumn(Source, "Custom", each Table.FromColumns({Text.Split([Column2], ";"), Text.Split([Column3], ";")}))and then expand the resulting table.
Where Column2 and Column3 are the names of the columns who have multiple values in them and Source is the name of the previous step or the name of your query that you're referencing.
Edit 2018-10-31: You can also use this more generic function, that saves some typing when using multiple columns:
(Table as table, Delimiter as text, ListOfColumnNames) => Table.AddColumn(Table,
"TableFromColumns",
each Table.FromColumns(List.Transform(ListOfColumnNames,
(x) => Text.Split(Record.Field(_, x),
Delimiter))))
Thanks for you suggestion it can help me a bit.
The thing is that the semicomma separated values (A;B;C) are not always three in each row (can be two, three, four, etc - theoretically any count):
1, A;B;C, X;Y;Z, 2, 3, 7
5, A;B;C;D, V;X;Y;Z, 5, 3, 6
2, A;B, Y;Z, 4, 1, 6
Add a custom column with this formula:
= Table.AddColumn(Source, "Custom", each Table.FromColumns({Text.Split([Column2], ";"), Text.Split([Column3], ";")}))
and then expand the resulting table.
Where Column2 and Column3 are the names of the columns who have multiple values in them and Source is the name of the previous step or the name of your query that you're referencing.
Edit 2018-10-31: You can also use this more generic function, that saves some typing when using multiple columns:
(Table as table, Delimiter as text, ListOfColumnNames) => Table.AddColumn(Table,
"TableFromColumns",
each Table.FromColumns(List.Transform(ListOfColumnNames,
(x) => Text.Split(Record.Field(_, x),
Delimiter))))
- fskhalasm9 years agoFrequent Visitor
Thanks Imke, this works perfectly :smileyhappy:
- powerbi_seek8 years agoFrequent Visitor
Hello Imkef,
After a while, I need to implement your solution, but don't know where and how.
I m on "Import Data", and I have only one multiple values column to split. Can you please help ?
Regards
- ImkeF8 years agoCommunity Champion
Please have a look at this video which shows how to integrate M-code into your solution:
- VEG_Admin7 years agoFrequent Visitor
ImkeF can you clarify how the generic solution below works. I don't see a way to identify the delimiter type, #(lf) in my case, and for whatever reason when I paste this into PBI it is hitting a syntax error in the middle of the first "delimiter". I have about 40 columns of data that this is the perfect solution for, would love any help you can provide.
Thanks!
- ImkeF7 years agoCommunity Champion
it shouldn't return errors. Please check this code:
let MyFunction = (Table as table, Delimiter as text, ListOfColumnNames) => Table.AddColumn(Table, "TableFromColumns", each Table.FromColumns(List.Transform(ListOfColumnNames, (x) => Text.Split(Record.Field(_, x), Delimiter)))), Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("DcinAQAwDAOwX4xDOnnnE3Fe8P+wFZQ7EpWpAsOgJrUQ5qhUo/rfTR3qIuIB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]), Custom1 = MyFunction(Source, "(#)#(lf)", {"Column1", "Column2"} ) in Custom1