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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Anonymous
Not applicable

How to join multiple columns in a single query? (M language)

Hello,

 

I have several tables with the same structure, from different months. The structure is as follows:

Column 1: Active

Column 2: Month (January, February, ....)

What I want is a new query, with the following structure:

Column 1: Active

Column 2: January

Column 2: February

Column 3: March

....

Is it possible to do it in a single combination?

Thank you very much and best regards.

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

Not exactly what you are going for but maybe gets you close? What value is supposed to go into the month columns?

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJKzCtNLKpUitWJVjIC8t1Sk4rgAsZAAd/EouQMMM8EyHMsKMrMUYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Active = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Active", Int64.Type}, {"Month", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Month]), "Month", "Active", List.Sum)
in
    #"Pivoted Column"

You would need to append your tables together. If you could post sample data that would be helpful. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

The Active columns in different tables are same, or have some common values? If it is, you can merge the different tables into one. For example, merge the Table1 and Table2.

Table1Table1Table2Table2

I clieck Merge in Query Editor as follows.

3.png

I expand all columns and remove the Table2.Active, I get the followsing result.

4.PNG

This is my Query statement.

let
    Source = Table.NestedJoin(Table1,{"Active"},Table2,{"Active"},"Table2",JoinKind.FullOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Active", "Month"}, {"Table2.Active", "Table2.Month"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"Table2.Active"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Month", "Jan"}, {"Table2.Month", "Feb"}})
in
    #"Renamed Columns"


For merging or appending, please see detailed steps here: 
Append vs. Merge in Power BI and Power Query.

Best Regards,
Angelia

View solution in original post

4 REPLIES 4
v-huizhn-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous,

The Active columns in different tables are same, or have some common values? If it is, you can merge the different tables into one. For example, merge the Table1 and Table2.

Table1Table1Table2Table2

I clieck Merge in Query Editor as follows.

3.png

I expand all columns and remove the Table2.Active, I get the followsing result.

4.PNG

This is my Query statement.

let
    Source = Table.NestedJoin(Table1,{"Active"},Table2,{"Active"},"Table2",JoinKind.FullOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Active", "Month"}, {"Table2.Active", "Table2.Month"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"Table2.Active"}),
    #"Renamed Columns" = Table.RenameColumns(#"Removed Columns",{{"Month", "Jan"}, {"Table2.Month", "Feb"}})
in
    #"Renamed Columns"


For merging or appending, please see detailed steps here: 
Append vs. Merge in Power BI and Power Query.

Best Regards,
Angelia

Anonymous
Not applicable

Hello @v-huizhn-msft,

 

It is great.

 

Thank you very much and best regards.

Greg_Deckler
Community Champion
Community Champion

Not exactly what you are going for but maybe gets you close? What value is supposed to go into the month columns?

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfJKzCtNLKpUitWJVjIC8t1Sk4rgAsZAAd/EouQMMM8EyHMsKMrMUYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Active = _t, Month = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Active", Int64.Type}, {"Month", type text}}),
    #"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[Month]), "Month", "Active", List.Sum)
in
    #"Pivoted Column"

You would need to append your tables together. If you could post sample data that would be helpful. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hello @Greg_Deckler,

 

It is great.

 

Thank you very much and best regards.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.