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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Skumar100
New Member

Left outer join by combing two tables

Hi All,
I am very new to power bi. I am trying to create a new output table using the calculated columns from the other table. I tried using the natural join function but I was un-able to create a new table sucessfully.

I know that this can be achieved easily in the sql but I am not quite familiar with the DAX. Any suggestions will be very helpful. Thanks 

 

Table 1 

Month Year Cat 
202401c1
202402c1
202403c1
202404c1
202405c1
202401c2
202402c2
202403c2

 

Table 2:

 

Month Year Cat CodeDate
202401c1123-Jan-24
202402c112-Feb-24
202403c2231-Mar-24
202405c1124-May-24
202405c1225-May-24

 

Output:

Month Year Cat CodeDate
202401c1123-Jan-24
202402c112-Feb-24
202403c1  
202404c1  
202405c1124-May-24
202405c1225-May-24
202401c2  
202402c2  
202403c2231-Mar-24
202404c2  
202405c2  
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Your expected output cannot be achieved with just a Left Outer Join. 

 

 

= Table.NestedJoin(#"Table 1", {"Month Year ", "Cat "}, #"Table 2", {"Month Year ", "Cat "}, "Table 2", JoinKind.LeftOuter)

lbendlin_0-1716233802839.png

 

Looks more like you wanted a cross join between [Month Year] and [Cat]  of Table 1 and then a left outer join with table 2.

 

= Table.NestedJoin(Table.ExpandTableColumn(Table.AddColumn(Table.Distinct(Table.SelectColumns(#"Table 1",{"Month Year "})), "Custom", each Table.Distinct(Table.SelectColumns(#"Table 1",{"Cat "}))), "Custom", {"Cat "}, {"Cat "}), {"Month Year ", "Cat "}, #"Table 2", {"Month Year ", "Cat "}, "Table 2", JoinKind.LeftOuter)

 

let
    Source = Table.NestedJoin(Table.ExpandTableColumn(Table.AddColumn(Table.Distinct(Table.SelectColumns(#"Table 1",{"Month Year "})), "Custom", each Table.Distinct(Table.SelectColumns(#"Table 1",{"Cat "}))), "Custom", {"Cat "}, {"Cat "}), {"Month Year ", "Cat "}, #"Table 2", {"Month Year ", "Cat "}, "Table 2", JoinKind.LeftOuter),
    #"Expanded Table 2" = Table.ExpandTableColumn(Source, "Table 2", {"Code", "Date"}, {"Code", "Date"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Table 2",{{"Cat ", Order.Ascending}, {"Month Year ", Order.Ascending}})
in
    #"Sorted Rows"

View solution in original post

7 REPLIES 7
lbendlin
Super User
Super User

Your expected output cannot be achieved with just a Left Outer Join. 

 

 

= Table.NestedJoin(#"Table 1", {"Month Year ", "Cat "}, #"Table 2", {"Month Year ", "Cat "}, "Table 2", JoinKind.LeftOuter)

lbendlin_0-1716233802839.png

 

Looks more like you wanted a cross join between [Month Year] and [Cat]  of Table 1 and then a left outer join with table 2.

 

= Table.NestedJoin(Table.ExpandTableColumn(Table.AddColumn(Table.Distinct(Table.SelectColumns(#"Table 1",{"Month Year "})), "Custom", each Table.Distinct(Table.SelectColumns(#"Table 1",{"Cat "}))), "Custom", {"Cat "}, {"Cat "}), {"Month Year ", "Cat "}, #"Table 2", {"Month Year ", "Cat "}, "Table 2", JoinKind.LeftOuter)

 

let
    Source = Table.NestedJoin(Table.ExpandTableColumn(Table.AddColumn(Table.Distinct(Table.SelectColumns(#"Table 1",{"Month Year "})), "Custom", each Table.Distinct(Table.SelectColumns(#"Table 1",{"Cat "}))), "Custom", {"Cat "}, {"Cat "}), {"Month Year ", "Cat "}, #"Table 2", {"Month Year ", "Cat "}, "Table 2", JoinKind.LeftOuter),
    #"Expanded Table 2" = Table.ExpandTableColumn(Source, "Table 2", {"Code", "Date"}, {"Code", "Date"}),
    #"Sorted Rows" = Table.Sort(#"Expanded Table 2",{{"Cat ", Order.Ascending}, {"Month Year ", Order.Ascending}})
in
    #"Sorted Rows"
Skumar100
New Member

Hi @lbendlin @v-kaiyue-msft , 

 

Thanks for the your note. 

 

Table 1 & table 2 are created using DAX. So I couldnt find a way to modify using the power query.  Thanks! 

Hi @Skumar100 ,

 

You can try to do this by creating a calculation table.

Table 3 = 
VAR _table1 = ADDCOLUMNS('Table',"Code",BLANK(),"Date",BLANK())
RETURN
UNION(_table1,'Table 2')

 

vkaiyuemsft_0-1716173909405.png

 

Best Regards,

Clara Gong

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

Hi @v-kaiyue-msft , 

 

Thanks for the quick update. 

 

for the record c1 - 202405 - I am getting one record from table 1 and 2 records from table 2. 

 

Table 1 - each Cat has a monthyear stamp ie it is a continuous

Hi @Skumar100 ,

 

Sorry, I don't quite understand what you mean, can you describe it in a more visual and detailed way?

 

Best Regards,

Clara Gong

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

v-kaiyue-msft
Community Support
Community Support

Hi @Skumar100 ,

 

Thanks for the reply from @lbendlin , please allow me to provide another insight: 

 

1. In the power query editor, select append queries.

vkaiyuemsft_0-1716169009174.png


2. In the pop-up window, set the settings as shown below.

vkaiyuemsft_1-1716169021013.png

 

3. Click the triangle next to the cat column to sort them.

vkaiyuemsft_2-1716169031577.png

 

vkaiyuemsft_3-1716169031577.png


For more details, please refer to the documentation: Append queries - Power Query | Microsoft Learn.

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

lbendlin
Super User
Super User

The preferred way in Power BI is to let the data model do the work for you. What's your reason for needing a materialized output?

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Top Kudoed Authors