Forum Discussion
clemente
Mar 24, 2025Copper Contributor
Spliting rows in Excel with Power Query
Hello all,
I would like to know if there is a way to split rows depending on the value of one or more cells using DAX or Power Query instead of Visual Basic
Here's an example:
Line | ID | Date | Affected Units |
1 | CET-752 | 23-dez-2024 | GET5-SO |
2 | CET-763 | 24-dez-2024 | GET3-SE |
3 | CET-764 | 25-dez-2024 | GET4-SU, GET8-OE, GET5-SO |
Considering Line 3, I would like to create two additional rows splitting cell D3 using comma as a separating value. The results I would like to achieve is:
Line | ID | Date | Affected Units |
1 | CET-752 | 23-dez-2024 | GET5-SO |
2 | CET-763 | 24-dez-2024 | GET3-SE |
3 | CET-764 | 25-dez-2024 | GET4-SU |
4 | CET-764 | 25-dez-2024 | GET8-OE |
5 | CET-763 | 25-dez-2024 | GET5-SO |
Thank you in advance!
As variant
let Source = Excel.CurrentWorkbook(){[Name="DemoOne"]}[Content], RemoveBlankColumn = Table.RemoveColumns(Source,{"Column1"}), SplitText = Table.ReplaceValue( RemoveBlankColumn, each [Affected Units] , each Text.Split( [Affected Units], ", " ), Replacer.ReplaceValue,{"Affected Units"}), ExpandLists = Table.ExpandListColumn(SplitText, "Affected Units"), AdjustLine = Table.FromColumns( {{1..Table.RowCount( ExpandLists )}} & List.Skip( Table.ToColumns( ExpandLists ) ), Table.ColumnNames(ExpandLists) ), DeclareType = Table.TransformColumnTypes( AdjustLine, { {"Line", Int64.Type} , {"ID", type text} , {"Date", type date} , {"Affected Units", type text} }) in DeclareType