Power Query: Get Column Names Fast
In this article
To get column names in Excel Power Query, load your data into the Power Query Editor, then use the formula bar or the Advanced Editor to read the header row, or add a step that converts the table's column names into a list with Table.ColumnNames. The quickest no-code method is to click any column header and read its name in the formula bar, but for a reusable list you need a custom step or a small M query.
What You'll Need
- Excel for Windows or Mac with Power Query (built in from Excel 2016 onward; on older versions it is the Power Query add-in).
- A data source already connected in Power Query — an Excel table, CSV, database, or web table.
- Basic familiarity with the Power Query Editor window: the ribbon, the Queries pane on the left, and the formula bar.
Step-by-Step
- Load your data into Power Query. Select a cell in your table, then go to Data > From Table/Range (or Data > Get Data for external sources). The Power Query Editor opens. Menu labels can differ slightly by Excel version and region.
- Confirm headers are promoted. On the Home tab, check that Use First Row as Headers has been applied if your first row contains names. If the headers still show as Column1, Column2, click Use First Row as Headers once.
- Read a single column name. Click any column header. The formula bar shows the current step, and the column name appears in the step's code, for example
Table.SelectColumns(Source, {"Customer ID"}). This is the fastest way to confirm the exact spelling and capitalization. - Get all column names as a list. Go to Home > Advanced Editor. At the end of the query, add a step such as
ColumnNames = Table.ColumnNames(PreviousStep)and change the final output line toColumnNames. Close and load; the query returns a one-column list of every header. - Or use a custom column to capture names. In the Editor, go to Add Column > Custom Column and enter a formula like
Table.ColumnNames(Source). This creates a column containing the list, which you can then expand. This is useful when you want to compare headers across multiple files. - Combine files and keep headers. If you are appending or combining files, use Home > Combine > Combine Files. In the sample file dialog, ensure the correct sheet or table is selected and that Use First Row as Headers is ticked. The resulting query keeps the header row from the sample file; mismatched headers in other files will appear as extra columns.
- Rename or clean headers. Double-click a header to rename it. To bulk clean, select all columns with Ctrl+A (or Cmd+A on Mac), then use Transform > Format > Trim and Clean. Renaming here changes the output table headers.
- Load the result. Go to Home > Close & Load to send the table (or the column-name list) to a worksheet. If you only need the names for reference, load to a new worksheet and delete the query connection afterward if desired.
Common Mistakes
- Forgetting to promote headers. If the first row is data, Power Query names columns Column1, Column2, and so on. Always apply Use First Row as Headers when the source has a header row.
- Typing column names by hand. A single extra space or different capitalization breaks references. Copy the name from the formula bar or use
Table.ColumnNamesto avoid typos. - Assuming column order is fixed. Column order can change when the source file changes. Reference columns by name in steps rather than by position.
- Editing the wrong step. Changes apply to the selected step and all later steps. If a rename does not appear, check that you are on the last step or that a later step is not overriding it.
- Mixing up query name and column name. The Queries pane lists query names, not column names. Click inside the data preview to see column names in the formula bar.
Tips
- Use
Table.ColumnNamesinside a custom function to make a reusable header checker for many files. - Keep a dedicated query that outputs only column names; it is handy for documentation and for comparing schema changes over time.
- If you need column names as text for labels, wrap the list with
Text.Combine(Table.ColumnNames(Source), ", "). - Rename columns early in the query so later steps are easier to read and less likely to break.
- Use the Applied Steps pane to click back through steps and see how the column list changes at each stage.
Troubleshooting
- Column names show as Column1, Column2. Promote the first row as headers. If the source has no header row, add one in the source file or rename columns manually.
Table.ColumnNamesreturns an error. Check that the argument is a table, not a list or a record. Use the exact name of the previous step as shown in the Applied Steps pane.- Headers change after refresh. The source file's headers may have changed. Open the query, review the steps, and update any hard-coded column names. Prefer dynamic references where possible.
- Combined files show extra columns. Headers differ between files. Standardize headers in the source files, or use Transform > Use First Row as Headers consistently and remove unneeded columns after combining.
- Cannot find Advanced Editor. It is on the Home tab in the Power Query Editor. If it is missing, you may be in the wrong window; close the dialog and reopen the query.
Frequently Asked Questions
Can I get column names without writing M code?
Yes. Click each column header and read the name in the formula bar, or use Add Column > Custom Column with Table.ColumnNames(Source) to generate a list without editing the Advanced Editor.
Does Table.ColumnNames work on any table?
It works on any table value in Power Query, including the result of a previous step. It returns a list of text values, one per column, in the table's current order.
Why do my column names have extra spaces?
Source data often contains leading or trailing spaces. Select the columns and use Transform > Format > Trim, then Clean to remove non-printing characters before renaming.
Can I output column names to a worksheet?
Yes. Build a query whose final step returns the list, then convert it to a table with Transform > To Table and load it with Close & Load.
Do column names need to be unique?
Power Query will rename duplicates automatically (for example, adding a suffix). Unique names are safer because steps that reference a column by name can behave unpredictably with duplicates.
Will this work in Excel for Mac?
Yes, the Power Query Editor and Table.ColumnNames are available in modern Excel for Mac. Menu locations are similar, though some labels and shortcut keys differ from Windows.