Power Query Table.DemoteHeaders: A How-To Guide
In this article
Table.DemoteHeaders takes the current column headers of a table and pushes them down into the first row of data, then replaces the headers with generic names like Column1, Column2, and so on. You use it when the real headers are buried in the data itself—for example, when a CSV or web table imports with a title row, a blank row, or a report header above the actual field names. It is a Power Query M function, so you can call it from the formula bar, the Advanced Editor, or by using the Transform tab's "Use First Row as Headers" button twice (once to demote, once to promote). Nothing needs to be installed beyond Excel, Power BI, or another host that includes Power Query.
What You'll Need
- Excel (Power Query is on the Data tab), Power BI Desktop, or another host with Power Query.
- A table already loaded into the Power Query Editor—either from a file, a database, or a web page.
- Basic familiarity with the Power Query Editor and the formula bar.
Step-by-Step
- Load your data into Power Query. In Excel, select your range and choose Data > From Table/Range, or use Data > Get Data to import a CSV or other source. In Power BI Desktop, use Home > Get Data. The Power Query Editor opens with your table in the preview pane. Menu labels can differ slightly by version, device, and region.
- Inspect the first few rows. Look at the preview. If the top row contains a title, a date, or a blank line instead of field names, demoting the headers is appropriate. If the top row already holds the correct headers, skip this guide and use "Use First Row as Headers" instead.
- Apply Table.DemoteHeaders. The simplest route is the Transform tab: click Use First Row as Headers and choose Use Headers as First Row from the dropdown. That action writes Table.DemoteHeaders into the query. Alternatively, open the formula bar and change the step to
= Table.DemoteHeaders(PreviousStep), where PreviousStep is the name of the step before it. You can also use Home > Advanced Editor to edit the M code directly. - Check the result. The old headers should now appear as the first row of data, and the column headers should read Column1, Column2, Column3, and so on. If you see an error, the most common cause is referencing the wrong step name in the formula bar.
- Remove any junk rows. After demoting, the first row often contains a report title or a blank row rather than real field names. Use Home > Remove Rows > Remove Top Rows and enter the number of rows to drop (for example, 1 or 2). Do this before promoting headers so the correct row ends up on top.
- Promote the real headers. With the correct row now at the top, go to Transform > Use First Row as Headers. Power Query writes Table.PromoteHeaders and renames the columns to the values in that row.
- Clean up column types. Power Query may set every column to Any or Text after demoting and promoting. Click the type icon in each column header and choose the correct type—Whole Number, Date, Decimal Number, and so on. This prevents later steps from failing.
- Rename any remaining generic columns. If a column still shows Column1 or similar, double-click its header and type a meaningful name. This keeps the query readable and avoids confusion downstream.
- Close and load. Use Home > Close & Load (Excel) or Home > Close & Apply (Power BI) to send the cleaned table to your worksheet or data model.
Common Mistakes
- Demoting when you meant to promote. Table.DemoteHeaders moves headers down; Table.PromoteHeaders moves the first row up. Applying the wrong one doubles the problem. Check the preview before and after each step.
- Forgetting to remove title rows first. If row 1 is a report title and row 2 is blank, demoting once leaves the title in the data. Remove the extra rows before promoting.
- Editing the wrong step. In the formula bar, the function must reference the exact name of the previous step. A typo such as
Previous Stepwith a space causes an Expression.Error. - Assuming headers are permanent. Demoting and promoting are steps in the query; deleting or reordering them in the Applied Steps pane changes the result. Keep the steps in the order you need.
- Ignoring data types. After demoting, Power Query often resets types to Any. Skipping the type step leads to errors in calculated columns or when loading to the data model.
Tips
- Use the Applied Steps pane to rename steps (right-click > Rename) so the M code reads clearly, such as "Demote original headers" and "Promote real headers."
- If the source is a CSV with a fixed number of junk rows, consider using the Remove Top Rows button before demoting, or set the skip rows option in the source step where available.
- To see the M code for any step, click the step and read the formula bar. This is the fastest way to learn how Table.DemoteHeaders and Table.PromoteHeaders are written.
- When combining multiple files with Folder.Files, apply demote and promote inside the sample file transformation so every file is handled the same way.
- If the table has merged cells or subtotal rows, demoting alone will not fix the layout. Clean those rows first with Remove Rows or Filter.
Troubleshooting
If Table.DemoteHeaders returns an error, check the step name in the formula bar first—it must match the previous step exactly, including capitalization. If the table appears unchanged, confirm you are editing the correct query and that the step is not disabled. If column names still look wrong after promoting, the top row probably was not the real header row; remove additional rows and promote again. If types break after demoting, reset them manually. If the query is slow on large files, reduce columns early with Choose Columns before demoting. As a last resort, delete the demote and promote steps and rebuild them in order.
Frequently Asked Questions
What does Table.DemoteHeaders do in Power Query?
It takes the current column headers and moves them into the first row of data, replacing the headers with generic names such as Column1 and Column2.
When should I use Table.DemoteHeaders instead of Table.PromoteHeaders?
Use DemoteHeaders when the real headers are not in the top row—for example, when a title or blank row sits above them. Use PromoteHeaders when the top row already contains the correct field names.
Can I undo Table.DemoteHeaders?
Yes. Delete the step in the Applied Steps pane, or add a Table.PromoteHeaders step afterward to restore the previous row as headers.
Why do my column types change after demoting headers?
Demoting replaces typed headers with text values, so Power Query often resets columns to Any. Set the correct types again after promoting the real headers.
Does Table.DemoteHeaders work in Excel and Power BI?
Yes. Both use the same Power Query engine, so the function and the Transform tab buttons behave the same way, though menu labels can vary slightly by version.
Can I demote headers in the middle of a query?
Yes. The function works on any table step. Place it wherever the header row needs to move into the data, then promote the correct row afterward.