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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Vidhyashree153
New Member

Inner join with condition

Hello,
I have a problem about joining two tables with condition.
Please help.

Eg.
Table : Sheet1
field : Defectnumber, CreateDate

Table : Sheet2
field : MonthStart, MonthEnd

 

i have to join both the sheets and get the inventory data of defects


with condition likes this :
Sheet1 inner join Sheet2
where sheet1.CreateDate <= Sheet2.MonthEnd

 

Below screenshot is from Tableau is there any way i can replicate this in PowerBI

Vidhyashree153_0-1725877221467.png

 


Please help me


Thank you.

1 ACCEPTED SOLUTION
v-junyant-msft
Community Support
Community Support

Hi @Vidhyashree153 ,

You can try this way:
Here is my sample data:

vjunyantmsft_0-1725935725250.png

vjunyantmsft_1-1725935733911.png

Use this M code to create a Blank Query:

vjunyantmsft_2-1725935779671.png

let
    FindDefectnumber = (MonthStart as date, MonthEnd as date) =>
    let
        FilteredRows = Table.SelectRows(Sheet1, each [CreateDate] >= MonthStart and [CreateDate] <= MonthEnd),
        DefectnumberCol = Table.Column(FilteredRows, "Defectnumber")
    in
        DefectnumberCol
in
    FindDefectnumber

vjunyantmsft_3-1725935806256.png

Then back to Sheet2 and create a Invoke Custom Function:

vjunyantmsft_4-1725935911144.png

vjunyantmsft_5-1725935922408.png
Expand columns:

vjunyantmsft_6-1725935994136.png

Output:

vjunyantmsft_7-1725936009958.png


Then you can inner join Sheet1 and Sheet2 with column Defectnumber and Related Number:

vjunyantmsft_8-1725936150083.png

 

Best Regards,
Dino Tao
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

5 REPLIES 5
v-junyant-msft
Community Support
Community Support

Hi @Vidhyashree153 ,

You can try this way:
Here is my sample data:

vjunyantmsft_0-1725935725250.png

vjunyantmsft_1-1725935733911.png

Use this M code to create a Blank Query:

vjunyantmsft_2-1725935779671.png

let
    FindDefectnumber = (MonthStart as date, MonthEnd as date) =>
    let
        FilteredRows = Table.SelectRows(Sheet1, each [CreateDate] >= MonthStart and [CreateDate] <= MonthEnd),
        DefectnumberCol = Table.Column(FilteredRows, "Defectnumber")
    in
        DefectnumberCol
in
    FindDefectnumber

vjunyantmsft_3-1725935806256.png

Then back to Sheet2 and create a Invoke Custom Function:

vjunyantmsft_4-1725935911144.png

vjunyantmsft_5-1725935922408.png
Expand columns:

vjunyantmsft_6-1725935994136.png

Output:

vjunyantmsft_7-1725936009958.png


Then you can inner join Sheet1 and Sheet2 with column Defectnumber and Related Number:

vjunyantmsft_8-1725936150083.png

 

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

Omid_Motamedise
Impactful Individual
Impactful Individual

Add a new column and sued Table.SelectRows to filter the rows on sheet 2 with the below condition

where sheet1.CreateDate <= Sheet2.MonthEnd

Vidhyashree153
New Member

There are no common columns between both sheets so i need to add condition for the join itself

You can first apply the inner join using the merge queries in power query and then create an additional column to filter it out on that basis.
if [CreateDate] >= [MonthStart] and [CreateDate] <= [MonthEnd] then "Include" else "Exclude"


You can first apply the inner join using the merge queries in power query and then create an additional column to filter it out on that basis.
if [CreateDate] >= [MonthStart] and [CreateDate] <= [MonthEnd] then "Include" else "Exclude"


Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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

Top Solution Authors