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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Combining columns from different Tables but in same orders

Dear Community Members, 

 

Request your help with below query -

 

I have 14 tables with similar data and 5 columns per table

 

Example of two tables below:

 

Table 1

Cif IDName
1711None
6947Somoene
1276Noone
5645Anyone

 

Table 2

 

CRNName
2868Yum
6502dum
6498some
5362ton

 

I want to combine all the columns in order with each representing the subsequent value in a new table like below:

Cif IDName
1711None
6947Somoene
1276Noone
5645Anyone
2868Yum
6502dum
6498some
5362ton

 

 

PS - Please note that columns are not in exact order header wise hence cannot use Append query , also tried below function 

 

= Table.Combine({
Table.RenameColumns(
Table.SelectColumns(#"Table 1","CIF Id") ,{{"CIF Id","CIF ID"}})
,
Table.RenameColumns(
Table.SelectColumns(#"Table 2","CRN") ,{{"CRN","CIF ID"}})
,
Table.RenameColumns(
Table.SelectColumns(#"Table 1","Name") ,{{"Name","Name"}})
,
Table.RenameColumns(
Table.SelectColumns(#"Table 2","Name") ,{{"Name","Name"}})

})

 

But it give below result :

 

Cif IDName
1711null
6947null
1276null
5645null
2868null
6502null
6498null
5362null
nullNone
nullSomoene
nullNoone
nullAnyone
nullYum
nulldum
nullsome
nullton

 

Please help

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

This pattern should work:

let
    Source =
    Table.SelectColumns(
        Table.Combine(
            {
                Table.RenameColumns(Table1, {{"ID1", "ID_Output"}, {"Name1", "Name_Output"}}),
                Table.RenameColumns(Table2, {{"ID2", "ID_Output"}, {"Name2", "Name_Output"}}),
                Table.RenameColumns(Table3, {{"ID3", "ID_Output"}, {"Name3", "Name_Output"}})
            }
        ),
        {"ID_Output", "Name_Output"}
    )
in
    Source

Update the column names as appropriate for your situation.

View solution in original post

6 REPLIES 6
AlexisOlson
Super User
Super User

This pattern should work:

let
    Source =
    Table.SelectColumns(
        Table.Combine(
            {
                Table.RenameColumns(Table1, {{"ID1", "ID_Output"}, {"Name1", "Name_Output"}}),
                Table.RenameColumns(Table2, {{"ID2", "ID_Output"}, {"Name2", "Name_Output"}}),
                Table.RenameColumns(Table3, {{"ID3", "ID_Output"}, {"Name3", "Name_Output"}})
            }
        ),
        {"ID_Output", "Name_Output"}
    )
in
    Source

Update the column names as appropriate for your situation.

ImkeF
Super User
Super User

Hi @Anonymous ,
sorry, but I don't understand the requirement.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

ImkeF
Super User
Super User

Oh yes, sorry - my fault:

= Table.Combine({
Table.RenameColumns(
Table.SelectColumns(#"Table 1","CIF Id", "Name") ,{{"CIF Id","CIF ID"}})
,
Table.RenameColumns(
Table.SelectColumns(#"Table 2","CRN", "Name") ,{{"CRN","CIF ID"}})
})

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

I am troubling you..

so there are 14 tables, all dont have the header as "Name", so ultimately i have to convert the "Name" to "Name"

ImkeF
Super User
Super User

Hi @Anonymous ,
please try the following instead:

= Table.Combine({
Table.RenameColumns(
Table.SelectColumns(#"Table 1","CIF Id", "Name") ,{{"CIF Id","CIF ID", "Name"}})
,
Table.RenameColumns(
Table.SelectColumns(#"Table 2","CRN", "Name") ,{{"CRN","CIF ID", "Name"}})
})



Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Hi,

 

It give below error:

 

We cannot convert the value "Name" to type Number.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors
Top Kudoed Authors