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
jaryszek
Post Patron
Post Patron

Left join and fulfill all columns

Hi Guys,

 

i have 2 tables:

1) Soure Table:

Screenshot_18.png

2) Table which i want to left join:

Screenshot_19.png

3) and what i want to achevie:

 

Screenshot_16.png

 

as you can see i only Added "Funct3" to column Function and populate with the same data "VolemuID" and "ComponentInstance". 

But i do not know how to do this in PQ:

 

Screenshot_15.png

 

Can anybody help?

https://drive.google.com/file/d/1lbbqB3IPMIPUvIZLifM_iojdSP3Nw7Ge/view?usp=sharing

 

Best,

Jacek

 

 

2 ACCEPTED SOLUTIONS

Hi @jaryszek ,

please check if this is giving you the desired results:

 

// t_Source
let
    Source = Excel.CurrentWorkbook(){[Name="t_Source"]}[Content],
    #"Merged Queries" = Table.NestedJoin(Source, {"Topology", "Tier"}, t_LeftJoin, {"Topology", "Tier"}, "t_LeftJoin", JoinKind.LeftOuter),
    #"Expanded t_LeftJoin" = Table.ExpandTableColumn(#"Merged Queries", "t_LeftJoin", {"Function"}, {"t_LeftJoin.Function"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded t_LeftJoin",{"Function"}),
    Joined = Table.RenameColumns(#"Removed Columns",{{"t_LeftJoin.Function", "Function"}}),
    Custom1 = Joined & Source,
    #"Removed Duplicates" = Table.Distinct(Custom1)
in
    #"Removed Duplicates"

 

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

Hi @jaryszek ,

 

You also could try this:

let
    Source = Excel.Workbook(File.Contents("C:\Users\xueding\Downloads\Temp testing only\LeftJoinExample.xlsx"), null, true),
    t_Source_Table = Source{[Item="t_Source",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(t_Source_Table,{{"Topology", type text}, {"Tier", type text}, {"Function", type text}, {"VolumeID", Int64.Type}, {"ComponentInstance", Int64.Type}}),
    #"Appended Query" = Table.Combine({#"Changed Type", t_LeftJoin}),
    #"Removed Duplicates" = Table.Distinct(#"Appended Query", {"Topology", "Tier", "Function"}),
    #"Sorted Rows1" = Table.Sort(#"Removed Duplicates",{{"Topology", Order.Ascending}, {"Tier", Order.Ascending}, {"Function", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows1", "Index", 1, 1, Int64.Type),
    #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 0, 1, Int64.Type),
    #"Renamed Columns" = Table.RenameColumns(#"Added Index1",{{"Index.1", "Previous Index"}}),
    #"Merged Queries" = Table.NestedJoin(#"Renamed Columns", {"Previous Index"}, #"Renamed Columns", {"Index"}, "Renamed Columns", JoinKind.LeftOuter),
    #"Expanded Renamed Columns" = Table.ExpandTableColumn(#"Merged Queries", "Renamed Columns", {"Topology", "Tier", "VolumeID", "ComponentInstance"}, {"Renamed Columns.Topology", "Renamed Columns.Tier", "Renamed Columns.VolumeID", "Renamed Columns.ComponentInstance"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Renamed Columns", "Custom", each if [Topology] = [Renamed Columns.Topology] and [Tier] = [Renamed Columns.Tier] and [VolumeID] = null then [Renamed Columns.VolumeID] else [VolumeID]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Topology] = [Renamed Columns.Topology] and [Tier] = [Renamed Columns.Tier] and [ComponentInstance] = null then [Renamed Columns.ComponentInstance]else [ComponentInstance]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"VolumeID", "ComponentInstance", "Index", "Previous Index", "Renamed Columns.Topology", "Renamed Columns.Tier", "Renamed Columns.VolumeID", "Renamed Columns.ComponentInstance"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns",{{"Custom", "VolumeID"}, {"Custom.1", "ComponentInstance"}})
in
    #"Renamed Columns1"

v-xuding-msft_0-1600245831576.png

 

 

Best Regards,
Xue Ding
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

7 REPLIES 7
Greg_Deckler
Super User
Super User

@jaryszek - In PQ, I believe you can select multiple columns to join on:

Greg_Deckler_0-1599129226869.png

Use the Ctrl/Shift key to select multiple columns.


@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Thank you Greg, i am doing this. But still i have problem with getting result lin in picture above, 

can you please help? 

I added new Topo to show you:

Screenshot_20.png

 

and please use my example from google drive:

https://drive.google.com/file/d/1lbbqB3IPMIPUvIZLifM_iojdSP3Nw7Ge/view?usp=sharing

 

you see what is happening?

I am using Topolgoy and Tier as key but want to pupulate with values from table1...

 

Jacek

Anyone? 

Hi @jaryszek ,

 

You also could try this:

let
    Source = Excel.Workbook(File.Contents("C:\Users\xueding\Downloads\Temp testing only\LeftJoinExample.xlsx"), null, true),
    t_Source_Table = Source{[Item="t_Source",Kind="Table"]}[Data],
    #"Changed Type" = Table.TransformColumnTypes(t_Source_Table,{{"Topology", type text}, {"Tier", type text}, {"Function", type text}, {"VolumeID", Int64.Type}, {"ComponentInstance", Int64.Type}}),
    #"Appended Query" = Table.Combine({#"Changed Type", t_LeftJoin}),
    #"Removed Duplicates" = Table.Distinct(#"Appended Query", {"Topology", "Tier", "Function"}),
    #"Sorted Rows1" = Table.Sort(#"Removed Duplicates",{{"Topology", Order.Ascending}, {"Tier", Order.Ascending}, {"Function", Order.Ascending}}),
    #"Added Index" = Table.AddIndexColumn(#"Sorted Rows1", "Index", 1, 1, Int64.Type),
    #"Added Index1" = Table.AddIndexColumn(#"Added Index", "Index.1", 0, 1, Int64.Type),
    #"Renamed Columns" = Table.RenameColumns(#"Added Index1",{{"Index.1", "Previous Index"}}),
    #"Merged Queries" = Table.NestedJoin(#"Renamed Columns", {"Previous Index"}, #"Renamed Columns", {"Index"}, "Renamed Columns", JoinKind.LeftOuter),
    #"Expanded Renamed Columns" = Table.ExpandTableColumn(#"Merged Queries", "Renamed Columns", {"Topology", "Tier", "VolumeID", "ComponentInstance"}, {"Renamed Columns.Topology", "Renamed Columns.Tier", "Renamed Columns.VolumeID", "Renamed Columns.ComponentInstance"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Renamed Columns", "Custom", each if [Topology] = [Renamed Columns.Topology] and [Tier] = [Renamed Columns.Tier] and [VolumeID] = null then [Renamed Columns.VolumeID] else [VolumeID]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Topology] = [Renamed Columns.Topology] and [Tier] = [Renamed Columns.Tier] and [ComponentInstance] = null then [Renamed Columns.ComponentInstance]else [ComponentInstance]),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"VolumeID", "ComponentInstance", "Index", "Previous Index", "Renamed Columns.Topology", "Renamed Columns.Tier", "Renamed Columns.VolumeID", "Renamed Columns.ComponentInstance"}),
    #"Renamed Columns1" = Table.RenameColumns(#"Removed Columns",{{"Custom", "VolumeID"}, {"Custom.1", "ComponentInstance"}})
in
    #"Renamed Columns1"

v-xuding-msft_0-1600245831576.png

 

 

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

Hi @jaryszek ,

please check if this is giving you the desired results:

 

// t_Source
let
    Source = Excel.CurrentWorkbook(){[Name="t_Source"]}[Content],
    #"Merged Queries" = Table.NestedJoin(Source, {"Topology", "Tier"}, t_LeftJoin, {"Topology", "Tier"}, "t_LeftJoin", JoinKind.LeftOuter),
    #"Expanded t_LeftJoin" = Table.ExpandTableColumn(#"Merged Queries", "t_LeftJoin", {"Function"}, {"t_LeftJoin.Function"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded t_LeftJoin",{"Function"}),
    Joined = Table.RenameColumns(#"Removed Columns",{{"t_LeftJoin.Function", "Function"}}),
    Custom1 = Joined & Source,
    #"Removed Duplicates" = Table.Distinct(Custom1)
in
    #"Removed Duplicates"

 

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

Hi @jaryszek ,

have you been able to make this work?

 

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
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