Forum Discussion
Split and transform columns into rows
- 4 months ago
nok Please try with this PQ script:
(change the text YOURPATH, YOURBOOKNAME and SHEETNAME of the first two steps accordling to your file path, excelbookname and sheetname)
let Source = Excel.Workbook(File.Contents("YOURPATH\YOURBOOKNAME.xlsx"), null, true), SheetWithData = Source{[Item = "SHEETNAME", Kind = "Sheet"]}[Data], #"Filtered Rows" = Table.SelectRows(SheetWithData, each [Column1] <> null and [Column1] <> ""), #"Transposed Table" = Table.Transpose(#"Filtered Rows"), #"Trimmed Text" = Table.TransformColumns(#"Transposed Table", {{"Column1", Text.Trim, type text}}), #"Cleaned Text" = Table.TransformColumns(#"Trimmed Text", {{"Column1", Text.Clean, type text}}), #"Replaced Value" = Table.ReplaceValue( #"Cleaned Text", "[", "", Replacer.ReplaceText, {"Column2"} ), #"Replaced Value1" = Table.ReplaceValue( #"Replaced Value", "]", "", Replacer.ReplaceText, {"Column2"} ), #"Changed Type" = Table.TransformColumnTypes( #"Replaced Value1", {{"Column2", type date}, {"Column3", Int64.Type}} ), #"Pivoted Column" = Table.Pivot( #"Changed Type", List.Distinct(#"Changed Type"[Column1]), "Column1", "Column3", List.Sum ) in
You can do this with Unpivot then Pivot in Power Query. After loading the table and promoting headers if needed:
1. Select all the data columns and use Transform > Unpivot Columns. You will get an Attribute column (with values like Co. [01/01/2026]) and a Value column.
2. On the Attribute column, use Transform > Split Column > By Delimiter using " [". Rename the parts to Category and Date.
3. Clean the Date column by replacing "]" with empty, then change its type to Date.
4. Select the Category column and use Transform > Pivot Column with Value as the values column, and under Advanced options pick Don't Aggregate.
You will end up with one row per Date and three columns Co., Fo., Ac.
If this helped, a thumbs up and accepting the solution would be appreciated.
Best,
Shai Karmani