Forum Discussion
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/2026] | Co. [01/08/2026] | Co. [01/09/2026] | Co. [01/10/2026] | Co. [01/11/2026] | Co. [01/12/2026] | Fo. [01/01/2026] | Fo. [01/02/2026] | Fo. [01/03/2026] | Fo. [01/04/2026] | Fo. [01/05/2026] | Fo. [01/06/2026] | Fo. [01/07/2026] | Fo. [01/08/2026] | Fo. [01/09/2026] | Fo. [01/10/2026] | Fo. [01/11/2026] | Fo. [01/12/2026] | Ac. [01/01/2026] | Ac. [01/02/2026] | Ac. [01/03/2026] | Ac. [01/04/2026] | Ac. [01/05/2026] | Ac. [01/06/2026] | Ac. [01/07/2026] | Ac. [01/08/2026] | Ac. [01/09/2026] | Ac. [01/10/2026] | Ac. [01/11/2026] | Ac. [01/12/2026] |
| 10 | 20 | 30 | 40 | 50 | 60 | 100 | 200 | 300 | 700 | 900 | 1000 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 1000 | 1100 | 1200 | 1300 | 1400 | 100 | 150 | 200 | 250 | 300 | 350 | 400 | 450 | 500 | 550 | 600 | 650 |
As you can see, the Excel columns follow the format "Text. [date]" for every possible date. In my Power BI, I want to transform it into this format:
| Date | Co. | Fo. | Ac. |
| 01/01/2026 | 10 | 300 | 100 |
| 01/02/2026 | 20 | 400 | 150 |
| 01/03/2026 | 30 | 500 | 200 |
| 01/04/2026 | 40 | 600 | 250 |
| 01/05/2026 | 50 | 700 | 300 |
| 01/06/2026 | 60 | 800 | 350 |
| 01/07/2026 | 100 | 900 | 400 |
| 01/08/2026 | 200 | 1000 | 450 |
| 01/09/2026 | 300 | 1100 | 500 |
| 01/10/2026 | 700 | 1200 | 550 |
| 01/11/2026 | 900 | 1300 | 600 |
| 01/12/2026 | 1000 | 1400 | 650 |
How can I do this?
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
5 Replies
- danextianSuper 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.
- Shai_KarmaniSuper User
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
- Ashish_MathurSuper User
Hi,
Text.Date appear in 2 rows (not a single one) when pasted in MS Excel. Is that how the raw data is arranged?
- AhmedxSuper User
- pcoleySuper User
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