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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
paterke
New Member

Promote headers except a few columns

In power query I want to promote the first row to headers except 2 columns. 

Any suggestions?

1 ACCEPTED SOLUTION
v-linhuizh-msft
Community Support
Community Support

Thanks for the reply from aduguid.


Hi @paterke ,


Here l provide another idea, please follow the steps below:


1. Duplicate the original table in Power Query Editor:

 

vlinhuizhmsft_0-1723186943496.png

 

2. Select Year and Name and remove these columns:

vlinhuizhmsft_1-1723187094163.png

 

3. Use first row of the duplicated table as headers:

 

vlinhuizhmsft_3-1723187307219.png

 

4. Merge Table and Table(2).

vlinhuizhmsft_2-1723187239533.png

vlinhuizhmsft_4-1723187469909.png

 

5. Click on the button and select Year and Name to expand the table:

 

vlinhuizhmsft_5-1723187633301.png

 

6.The final result is as follows:

 

vlinhuizhmsft_6-1723188927203.png

 

Best Regards,
Zhu
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

5 REPLIES 5
v-linhuizh-msft
Community Support
Community Support

Thanks for the reply from aduguid.


Hi @paterke ,


Here l provide another idea, please follow the steps below:


1. Duplicate the original table in Power Query Editor:

 

vlinhuizhmsft_0-1723186943496.png

 

2. Select Year and Name and remove these columns:

vlinhuizhmsft_1-1723187094163.png

 

3. Use first row of the duplicated table as headers:

 

vlinhuizhmsft_3-1723187307219.png

 

4. Merge Table and Table(2).

vlinhuizhmsft_2-1723187239533.png

vlinhuizhmsft_4-1723187469909.png

 

5. Click on the button and select Year and Name to expand the table:

 

vlinhuizhmsft_5-1723187633301.png

 

6.The final result is as follows:

 

vlinhuizhmsft_6-1723188927203.png

 

Best Regards,
Zhu
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

aduguid
Super User
Super User

You you use something like this

let
    Source = /* Your data source step here */,
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
    #"Reverted Headers" = Table.RenameColumns(#"Promoted Headers",{
        {"NewColumn1Name", "Column1"},
        {"NewColumn2Name", "Column2"}
    })
in
    #"Reverted Headers"

Thx

the problem is that the value promoted to a header can change. 

My table looks like this. But after promoting the row to headers I won't have a Year column anymore. I can change the column 2023 back to Year, but this could change to 2024 on the next refresh. 

Column1Column2Year
ClientProduct2023
AA2023

Taking that into consideration try this

let
    // Load your data
    Source = Excel.Workbook(File.Contents("your_file_path.xlsx"), null, true),

    // Promote the first row to headers
    #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),

    // Get the column names
    columnNames = Table.ColumnNames(#"Promoted Headers"),

    // Identify the column that contains the year
    yearColumnName = List.First(List.Select(columnNames, each Text.IsNumeric(_))),

    // Rename the identified year column to "Year"
    #"Renamed Columns" = Table.RenameColumns(#"Promoted Headers", {{yearColumnName, "Year"}})
in
    #"Renamed Columns"

"Expression.Error: The name 'Text.IsNumeric' wasn't recognized. Make sure it's spelled correctly." 😞

And this is a solution for 1 column. What if I have multiple columns: Year, Name, ...

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!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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