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

Did you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now

Reply
Anonymous
Not applicable

Data model join issue

I have two tables that join where two columns equal or one column is null.  In SQL I would construct the join as such:

 

Select * 

From Table_A

     join Table_B

        on (Table_A.column1 = Table_B.column1

            or Table_A.column1 is null)

             and Table_A.column2 = Table_B.column2

 

Is there a similar way to handle this in Power BI?  Or do I need to join these tables together through the Advanced Options with a sql statement?

 

 

1 ACCEPTED SOLUTION
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

You may get the table in query editor with 'Merge Queries' Function or new a table with dax. Show the sample file here for your reference.

First way in Query Edtior.

let
    Source = Table.NestedJoin(TableA,{"Column2"},TableB,{"Column2"},"TableB",JoinKind.LeftOuter),
    #"Expanded TableB" = Table.ExpandTableColumn(Source, "TableB", {"Column1", "Column2"}, {"TableB.Column1", "TableB.Column2"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded TableB", "Custom", each if [Column1] = [TableB.Column1] then [Column1] else if [Column1] = null then null else "delete"),
    #"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each ([Custom] <> "delete")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"})
in
    #"Removed Columns"

Second way in Dax.

TableA (2) =
VAR t =
    ADDCOLUMNS (
        TableA,
        "column1_B", LOOKUPVALUE ( TableB[Column1], TableB[Column2], TableA[Column2] ),
        "column2_B", LOOKUPVALUE ( TableB[Column2], TableB[Column2], TableA[Column2] )
    )
RETURN
    FILTER ( t, TableA[Column1] = [column1_B] || TableA[Column1] = BLANK () )

Regards,

Cherie

 

Community Support Team _ Cherie Chen
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

1 REPLY 1
v-cherch-msft
Microsoft Employee
Microsoft Employee

Hi @Anonymous

 

You may get the table in query editor with 'Merge Queries' Function or new a table with dax. Show the sample file here for your reference.

First way in Query Edtior.

let
    Source = Table.NestedJoin(TableA,{"Column2"},TableB,{"Column2"},"TableB",JoinKind.LeftOuter),
    #"Expanded TableB" = Table.ExpandTableColumn(Source, "TableB", {"Column1", "Column2"}, {"TableB.Column1", "TableB.Column2"}),
    #"Added Conditional Column" = Table.AddColumn(#"Expanded TableB", "Custom", each if [Column1] = [TableB.Column1] then [Column1] else if [Column1] = null then null else "delete"),
    #"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each ([Custom] <> "delete")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Custom"})
in
    #"Removed Columns"

Second way in Dax.

TableA (2) =
VAR t =
    ADDCOLUMNS (
        TableA,
        "column1_B", LOOKUPVALUE ( TableB[Column1], TableB[Column2], TableA[Column2] ),
        "column2_B", LOOKUPVALUE ( TableB[Column2], TableB[Column2], TableA[Column2] )
    )
RETURN
    FILTER ( t, TableA[Column1] = [column1_B] || TableA[Column1] = BLANK () )

Regards,

Cherie

 

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.