Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
H_insight
Helper V
Helper V

Can this multi-level header be transformed by PQ dynamically?

Hi,

 

I have a spreadsheet (attached) that holds multi-level headers. I need to have the data transformed into a tabular format, so I can do some anaylsis.

 

H_insight_0-1652523812439.png

 

May thanls

 

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Below are the steps. Solution file uploaded to https://1drv.ms/x/s!Akd5y6ruJhvhuXVNE1rq8ooZx1rc?e=Mi2OhC 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each not Text.Contains(Text.From([Column1]),"Total")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Region", each try if Text.Contains([Column1],"Region") then [Column1] else null otherwise null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Department", each try if Text.Contains([Column1],"Department") then [Column1] else null otherwise null),
    #"Filled Down" = Table.FillDown(#"Added Custom1",{"Region", "Department"}),
    #"Removed Top Rows" = Table.Skip(#"Filled Down",2),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
    #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",{{"Region 1", "Region"}, {"Department 1", "Department"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Region", "Department", "#", "Name", "id", "date", "value", "Notes"}),
    #"Filtered Rows1" = Table.SelectRows(#"Reordered Columns", each ([Name] <> null) and ([#"#"] <> "#")),
    #"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows1",{{"Region", type text}, {"Department", type text}, {"#", Int64.Type}, {"Name", type text}, {"id", Int64.Type}, {"date", type datetime}, {"value", Int64.Type}, {"Notes", type text}})
in
    #"Changed Type"

 

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Below are the steps. Solution file uploaded to https://1drv.ms/x/s!Akd5y6ruJhvhuXVNE1rq8ooZx1rc?e=Mi2OhC 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Filtered Rows" = Table.SelectRows(Source, each not Text.Contains(Text.From([Column1]),"Total")),
    #"Added Custom" = Table.AddColumn(#"Filtered Rows", "Region", each try if Text.Contains([Column1],"Region") then [Column1] else null otherwise null),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Department", each try if Text.Contains([Column1],"Department") then [Column1] else null otherwise null),
    #"Filled Down" = Table.FillDown(#"Added Custom1",{"Region", "Department"}),
    #"Removed Top Rows" = Table.Skip(#"Filled Down",2),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
    #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers",{{"Region 1", "Region"}, {"Department 1", "Department"}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Renamed Columns",{"Region", "Department", "#", "Name", "id", "date", "value", "Notes"}),
    #"Filtered Rows1" = Table.SelectRows(#"Reordered Columns", each ([Name] <> null) and ([#"#"] <> "#")),
    #"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows1",{{"Region", type text}, {"Department", type text}, {"#", Int64.Type}, {"Name", type text}, {"id", Int64.Type}, {"date", type datetime}, {"value", Int64.Type}, {"Notes", type text}})
in
    #"Changed Type"

 

Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors