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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
sa34techer
Helper II
Helper II

Pivot rows as Columns

I get header dates in my excel extract on the first 4 rows.   Please help me pivot the row names and dates as columns into the bottom table using power query.  I have included a sample and data.

sample.png

 

 

Property NameExport Dates              
Period From9-Aug-24              
Period Upto19-Aug-24              
Exported On19-Aug-24              
                
BIG SourceTotal Volume RatingPrevious  RatingUP/DownPromoteFoodBunnyGPSSingle RatingPrevious Single RatingHFTYoggyBedGrondBP
Duck3243.884.04 4443115745.413.874.04 3351412544.3
1 ACCEPTED SOLUTION

@sa34techer 

Below m code will work for this requirement.

let
    Source = Excel.Workbook(File.Contents("C:\Users\Violent Gandhi\Downloads\Test.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    Table_1_filtered = Table.SelectRows(Sheet1_Sheet, each ([Column3] = null) and ([Column2] <> null)),
    RemovedOtherColumns = Table.SelectColumns(Table_1_filtered,{"Column1", "Column2"}),
    PromotedHeaders = Table.PromoteHeaders(RemovedOtherColumns, [PromoteAllScalars=true]),
    TransposedTable = Table.Transpose(PromotedHeaders),
    PromotedHeaders1 = Table.PromoteHeaders(TransposedTable, [PromoteAllScalars=true]),
    Table_2_filtered = Table.SelectRows(Sheet1_Sheet, each ([Column3] <> null)),
    PromotedHeaders3 = Table.PromoteHeaders(Table_2_filtered, [PromoteAllScalars=true]),
    Addcolumn = Table.AddColumn(PromotedHeaders3,"Exported On",each PromotedHeaders1[Exported On]{0}),
    JoinedTables = Table.Join(Addcolumn,"Exported On",PromotedHeaders1,"Exported On",JoinKind.Inner)
in
    JoinedTables


Attached PBIX has a table named single sheet for your reference.

If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!

Follow me on LinkedIn!!!


View solution in original post

3 REPLIES 3
NaveenGandhi
Super User
Super User

Hi @sa34techer 

Attached PBIX has solution for this. 

Let me know if this helps.

If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!

Follow me on LinkedIn!!!

Both tables come into the same excel sheet.  I need them combined at the final step in power query.

 

This what the final output should be.

Period FromPeriod UptoExported OnTotal Volume RatingPrevious  RatingUP/DownPromoteFoodBunnyGPSSingle RatingPrevious Single RatingHFTYoggyBedGrondBP
9-Aug-2419-Aug-2419-Aug-243243.884.04 4443115745.413.874.04 3351412544.3

@sa34techer 

Below m code will work for this requirement.

let
    Source = Excel.Workbook(File.Contents("C:\Users\Violent Gandhi\Downloads\Test.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    Table_1_filtered = Table.SelectRows(Sheet1_Sheet, each ([Column3] = null) and ([Column2] <> null)),
    RemovedOtherColumns = Table.SelectColumns(Table_1_filtered,{"Column1", "Column2"}),
    PromotedHeaders = Table.PromoteHeaders(RemovedOtherColumns, [PromoteAllScalars=true]),
    TransposedTable = Table.Transpose(PromotedHeaders),
    PromotedHeaders1 = Table.PromoteHeaders(TransposedTable, [PromoteAllScalars=true]),
    Table_2_filtered = Table.SelectRows(Sheet1_Sheet, each ([Column3] <> null)),
    PromotedHeaders3 = Table.PromoteHeaders(Table_2_filtered, [PromoteAllScalars=true]),
    Addcolumn = Table.AddColumn(PromotedHeaders3,"Exported On",each PromotedHeaders1[Exported On]{0}),
    JoinedTables = Table.Join(Addcolumn,"Exported On",PromotedHeaders1,"Exported On",JoinKind.Inner)
in
    JoinedTables


Attached PBIX has a table named single sheet for your reference.

If this post helps, then please consider Accept it as the solution to help the others find it more quickly. Appreciate you kudos!!

Follow me on LinkedIn!!!


Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.