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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Power BI - Merge queries as new - More than 2 tables

Hello,

 

Is there any feature in Power BI making it possible to merge quickly various tables with a left join ?

 

Example

 

Table A contains [ID] and [Field_1]

Table B contains [ID] and [Field_2]

Table C contains [ID] and [Field_3]

Table D contains [ID] and [Field_4]

Table E contains [ID] and [Field_5]

 

I want a table F containing those [ID] and the 5 fields.

At the moment I know only one solution: Merge A and B into a first table, then merge this new table with C, and then with D and then with E.

 

Thanks.

 

 

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

There might be an easier solution to this, but this is all I can come up with currently:

 

let
    TableA = #table({"ID", "Column1"}, {{"A", 10}, {"B", 20}}),
    TableB = #table({"ID", "Column2"}, {{"A", 100}, {"B", 200}}),
    TableC = #table({"ID", "Column3"}, {{"A", 1000}, {"B", 2000}}),
    ListOfTables = {TableA, TableB, TableC},
    DynamicLeftOuterJoin = List.Accumulate(List.Skip(ListOfTables,1),
                            [x = ListOfTables{0}, Counter=0], 
                            (state, current) => [x = let 
                                                        Join = Table.NestedJoin(state[x],{"ID"},current,{"ID"},"Result" & Text.From(state[Counter]),JoinKind.LeftOuter), 
                                                        Expand = Table.ExpandTableColumn(Join, "Result" & Text.From(state[Counter]), {List.Difference(Table.ColumnNames(current), {"ID"}){0}}
                                                        )
                                                    in 
                                                        Expand,
                                                Counter = state[Counter]+1])[x]
in
    DynamicLeftOuterJoin

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

View solution in original post

1 REPLY 1
ImkeF
Super User
Super User

There might be an easier solution to this, but this is all I can come up with currently:

 

let
    TableA = #table({"ID", "Column1"}, {{"A", 10}, {"B", 20}}),
    TableB = #table({"ID", "Column2"}, {{"A", 100}, {"B", 200}}),
    TableC = #table({"ID", "Column3"}, {{"A", 1000}, {"B", 2000}}),
    ListOfTables = {TableA, TableB, TableC},
    DynamicLeftOuterJoin = List.Accumulate(List.Skip(ListOfTables,1),
                            [x = ListOfTables{0}, Counter=0], 
                            (state, current) => [x = let 
                                                        Join = Table.NestedJoin(state[x],{"ID"},current,{"ID"},"Result" & Text.From(state[Counter]),JoinKind.LeftOuter), 
                                                        Expand = Table.ExpandTableColumn(Join, "Result" & Text.From(state[Counter]), {List.Difference(Table.ColumnNames(current), {"ID"}){0}}
                                                        )
                                                    in 
                                                        Expand,
                                                Counter = state[Counter]+1])[x]
in
    DynamicLeftOuterJoin

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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