Forum Discussion
nok
3 months agoAdvocate II
Split and transform columns into rows
Hi! I have a table in Excel that follows this format: Co.[01/01/2026] Co. [01/02/2026] Co. [01/03/2026] Co. [01/04/2026] Co. [01/05/2026] Co. [01/06/2026] Co. [01/07/...
- 3 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
danextian
3 months agoSuper User
Without promoting the first row to headers, you can simply transpose the whole table and then either replace [ and ] with nothing or use Text.BetweenDelimiters to extract the date. Rename and change the column type as appropriate.