# Using Power Query to get List of column names



## cr731 (Jun 29, 2016)

Using Power Query, what's the simplest way to get a list of the column names of a table?

My approach currently is,

- Demote headers
- transpose table
- remove all but first column

This works but feels a bit messy. Is there a better way?

Thanks


----------



## anvg (Jun 29, 2016)

Hi


> what's the simplest way to get a list of the column names of a table?


Yes, please, read https://msdn.microsoft.com/en-us/library/mt260746.aspx
Regards,


----------



## OlaSa (Jul 2, 2016)

One way: 
1. Filter and keep just One unique row
2. Unpivot --> all column headers
3. Delete the unique row (or keep it as an example)
//Ola


----------



## JohnLingle (Aug 27, 2019)

OlaSa said:


> One way:
> 1. Filter and keep just One unique row
> 2. Unpivot --> all column headers
> 3. Delete the unique row (or keep it as an example)
> //Ola




This is a very useful technique. However, in PQ 365 if your unique row has a NULL in it, that column does not get listed after the 'unpivot'. You need to replace NULLS in that first row with some value and then convert it back to the NULL after the 'unpivot'.


----------



## cyborgski (Sep 1, 2019)

JohnLingle said:


> This is a very useful technique. However, in PQ 365 if your unique row has a NULL in it, that column does not get listed after the 'unpivot'. You need to replace NULLS in that first row with some value and then convert it back to the NULL after the 'unpivot'.



Same technique but filter and keep 0 rows. Demote headers and then transpose instead of unpivot. 

But Table.ColumnNames is a quicker way to get the names.


----------

