Forum Discussion
split values into multiple rows
Hi,
can you help me with following task?
I have data like this:
1, A;B;C, X;Y;Z, 2, 3, 7
and I need to get:
1, A, X, 2, 3, 7
1, B, Y, 2, 3, 7
1, C, Z, 2, 3, 7
Any suggestion is appreciated.
Thank.
Marian
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))))
10 Replies
- BaskarResident Rockstar
I have data like this:
1, A;B;C, X;Y;Z, 2, 3, 7
It was in Sinlge cell ?
- fskhalasmFrequent Visitor
No, not in one cell,
It is comma separated - each comma one cell:
- first cell contains 1
- second cell contains A;B;C
- third cell contains X;Y;Z
- fourth cell contains 2
- etc...
There are of course many rows, this is just one row example.
M.
- BaskarResident Rockstar
Cool,
We can do using Power Query, but am not sure it is better way.
My point is we can do everything . Folllow the images step by step .
Your Data etSplit the two column by ( ; )Merge two column like the Example.After merge the three column by ( , )Choose that three column and click Unpivot itRemove Attribute columnSplit the value by ( , )Final Output
Let me know if it is not helping u.
Note :
these all steps u have to do in Query Editor window