Forum Discussion

toplisek's avatar
toplisek
Helper I
1 year ago
Solved

How to add headers without columns elements?

How to add headers without columns elements? I am testing CSV file. I try to replace Column1, ColumnXXX with the header titles.
  • Elena_Kalina's avatar
    1 year ago

    Hi toplisek 

    1 Using "Use First Row as Headers"(what you're looking for)

    - Make sure your first row in the data contains the header titles you want

    - In the Home tab, click "Use First Row as Headers" (the table icon with 123 on it)

    - This will promote your first data row to become column headers

    2 Manual Renaming

    - Right-click on a column header (e.g., "Column1")

    - Select "Rename" from the context menu

    - Type your desired header name

    - Repeat this process for each column individually

    3 Using the Created Step from First Rename

    - First rename one column manually (this creates a step in the query)

    - In the formula bar, modify the generated code to rename all columns at once

    The formula should look like:

    = Table.RenameColumns(PreviousStep, {{"Column1", "NewName1"}, {"Column2", "NewName2"}, {"Column3", "NewName3"}})

    4 Inserting a New Step Before Renaming

    - Go to the "Add Step" button or right-click in the query steps pane

    - Insert a new custom step

    - Use the complete rename formula for all columns:

    = Table.RenameColumns(Source, {{"Column1", "Header1"}, {"Column2", "Header2"}, {"Column3", "Header3"}})

    Note: Replace "Source" with the name of your previous step if needed, and adjust the column names and new headers according to your data.

     

    If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

    Thank you.

  • Nasif_Azam's avatar
    1 year ago

    Hey toplisek ,

    To add headers from the first row of a CSV file in Power Query Editor especially when it's currently using default column names like Column1, Column2, etc. 

    Steps to Use First Row as Headers

    1. Open Power Query Editor (as shown in your screenshot).

    2. On the Home tab, locate the Transform section.

    3. Click on “Use First Row as Headers”.

      • This option will promote the first row of your data to become the column headers.

      • It is labeled: Use First Row as Headers (right beside the "Data Type: Text" and “Replace Values” buttons).

      • Shortcut: It corresponds to this M code:

        Table.PromoteHeaders(Source, [PromoteAllScalars=true])

     

    If "Use First Row as Headers" is Disabled or Missing

    • You may already have applied it once. In that case:

      • Click on “Advanced Editor” and remove or adjust the previous steps.

    • You can manually promote headers using this line in the Advanced Editor:

      #"Promoted Headers" = Table.PromoteHeaders(PreviousStepName, [PromoteAllScalars=true])

    Cleanup Steps

    After promoting headers:

    • You might still see rows with old header names like Column1, Column2.

      • Use the “Remove Rows” → “Remove Top Rows” option to delete the top row (if needed).

    • Rename any column manually by double-clicking the column name or using the “Transform → Rename” option.

     

    If you found this solution helpful, please consider accepting it and giving it a kudos (Like) it’s greatly appreciated and helps others find the solution more easily.


    Best Regards,
    Nasif Azam