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
Poovarasan
Frequent Visitor

DAX Many to Many

I have a two tables with Many-To-Many relationship, Here's the screenshot for two tables

Table1:

Poovarasan_0-1629378960714.png

Table2:

Poovarasan_1-1629378983891.png

I need to create measure like this 
Sum of rate = Sumx(Table1,IF(Table1'Year&month'>=Table2'Year&Month',Table1'Rate',0)

I have tried to use RELATED function here but not helping for this senario

10 REPLIES 10
NidhiBhusari
Helper IV
Helper IV

Hi @Poovarasan try changing the relationship between the two table to Many - To - One.

Hi, @NidhiBhusari  

Yeah, I tried but both table ID column has duplicate value when i try to change it Power BI will not accept Many-To-One relationship

 

Thanks 

Poovarasan

@Poovarasan Try to create a bridging table between two tables and then set relationship many - to - one.
or can you share sample file? Let me try once

Hi, @NidhiBhusari 
Yeah, Sure 
Unable to attach file here. I have uploaded in OneDrive.
Please find pbi file in below link,
https://swiftant0-my.sharepoint.com/:u:/g/personal/sapowerbi_swiftant_com/EYTINAUftwVPpoYpeM0Ny-8Bjw...


Thanks 
Poovarasan

Hi @Poovarasan , please use the link attached to access the file with solution - https://nicesoftwaresolutions1-my.sharepoint.com/:u:/g/personal/nbhusari_nicesoftwaresolutions_com/E...

NidhiBhusari_0-1629446267221.png

 

Hi @Poovarasan ,

Is this the expected output you are looking for, if not then could you please share expected output as well?

image.png

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Hi, @Samarth_18@NidhiBhusari  ,

Here is my excepted output.

Poovarasan_0-1629517349307.png


Thanks
Poovarasan

Hi @Poovarasan , 

 

Based on provided data total sum of rate is 149.56, how it could be 333.68, if the output which you have provided is not based on provided data then you can try below code:-

Sum of Rate =
VAR result =
    CALCULATE (
        SUM ( 'Table1'[Rate] ),
        FILTER ( Table2, Table2[Year&Month] <= MAX ( Table1[Year&Month] ) )
    )
RETURN
    IF ( result = 0, 0, result )

Output:-

image.png

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Poovarasan
Frequent Visitor

Hello @Samarth_18,

 

Yes, Your correct

 

Thanks

Poovarasan

 

 

 

 

 

 

 

 

 

 

Samarth_18
Community Champion
Community Champion

Hi @Poovarasan ,

 

Your relation between both table is with ID colum right?

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

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.

Top Solution Authors