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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
glyn1997
New Member

How to Extract just column headers from a table in Power BI?

Basically, I have 2 identical tables. 1 table contains old product data and the other contains new product data.

The first column contains the products and has the header 'Products'. The other columns contain sales data by month and have headers such as '202201', '202202', '202203' etc all the way up to '202405'...

Although, the old data table month range is -1 compared to the new data table. So the 2 tables have a couple of monthly columns that do not match.

 

I want to be able to extract the column headers from both tables, and create an inner join so that only MATCHING column names between the 2 tables are returned.

I want this to be done using DAX ideally, as I need it to be an automated process each month, so that I dont have to go into PowerQuery and extract them manually every single month.

 

Next month, there will be new data and the current new data table will then be the old data table if that makes sense. So I need this to be an automated process so I dont have to do anything manually each month. 

 

If anyone knows how I can achieve this, would be amazing. Thank you 😊

2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

The data structure is the opposite of what Power BI likes.  Your requirement cannot be fulfilled in DAX as there is no way in DAX to dynamically address columns of a table.

 

You have to use Power Query to bring the data into a usable format by unpivoting the year columns.  After that the inner join will be very easy.

View solution in original post

Anonymous
Not applicable

Thanks for the reply from @lbendlin , please allow me to complement the solutions you offer and offer additional insights:


HI,@glyn1997 
May I ask whether the post from lbendlin solves your problem? If it does, please accept his post as the solution.

 

Here are my additions to how to get column names:

First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1718691369727.png

vlinyulumsft_2-1718691392266.png

1.The first is the method lbendlin offers:
First select all the columns in the powerquery and then perform the reversal operation:

vlinyulumsft_3-1718691411225.png

Next, use the "append query" for the two tables:

vlinyulumsft_4-1718691429600.png

Finally, perform a deduplication operation in m language:

 

distinct1=Table.Distinct(Source),

 

 

2.Another method:

First you need to create two new queries with refrence and then in the two new tables, execute the following m language:

vlinyulumsft_6-1718691526745.png

 

let
    Source = new,
    names=Table.ColumnNames(Source),
    output1=Table.FromList(names,Splitter.SplitByNothing(),{"column name"})
in
    output1
let
    Source = old,
    names1=Table.ColumnNames(Source),
    output2=Table.FromList(names1,Splitter.SplitByNothing(),{"column name"})
in
    output2

 

Then click New Blank Query and enter the following m language in Advanced Editor:

vlinyulumsft_7-1718691584535.png

 

let
   combinee=Table.Combine({#"new (2)",#"old (2)"}),
   distinct1=Table.Distinct(combinee)
in
 distinct1

 

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_8-1718691617520.png

4.Here is the relevant documentation:

Table.ColumnNames - PowerQuery M | Microsoft Learn

Table.FromList - PowerQuery M | Microsoft Learn

Table.Distinct - PowerQuery M | Microsoft Learn


Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thanks for the reply from @lbendlin , please allow me to complement the solutions you offer and offer additional insights:


HI,@glyn1997 
May I ask whether the post from lbendlin solves your problem? If it does, please accept his post as the solution.

 

Here are my additions to how to get column names:

First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1718691369727.png

vlinyulumsft_2-1718691392266.png

1.The first is the method lbendlin offers:
First select all the columns in the powerquery and then perform the reversal operation:

vlinyulumsft_3-1718691411225.png

Next, use the "append query" for the two tables:

vlinyulumsft_4-1718691429600.png

Finally, perform a deduplication operation in m language:

 

distinct1=Table.Distinct(Source),

 

 

2.Another method:

First you need to create two new queries with refrence and then in the two new tables, execute the following m language:

vlinyulumsft_6-1718691526745.png

 

let
    Source = new,
    names=Table.ColumnNames(Source),
    output1=Table.FromList(names,Splitter.SplitByNothing(),{"column name"})
in
    output1
let
    Source = old,
    names1=Table.ColumnNames(Source),
    output2=Table.FromList(names1,Splitter.SplitByNothing(),{"column name"})
in
    output2

 

Then click New Blank Query and enter the following m language in Advanced Editor:

vlinyulumsft_7-1718691584535.png

 

let
   combinee=Table.Combine({#"new (2)",#"old (2)"}),
   distinct1=Table.Distinct(combinee)
in
 distinct1

 

3.Here's my final result, which I hope meets your requirements.

vlinyulumsft_8-1718691617520.png

4.Here is the relevant documentation:

Table.ColumnNames - PowerQuery M | Microsoft Learn

Table.FromList - PowerQuery M | Microsoft Learn

Table.Distinct - PowerQuery M | Microsoft Learn


Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

lbendlin
Super User
Super User

The data structure is the opposite of what Power BI likes.  Your requirement cannot be fulfilled in DAX as there is no way in DAX to dynamically address columns of a table.

 

You have to use Power Query to bring the data into a usable format by unpivoting the year columns.  After that the inner join will be very easy.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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