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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
ngocnguyen
Helper IV
Helper IV

Mapping between 2 table with Many to many relationship in POWERBI

hI

I have 2 table 1 and 2 as belows. They are connecting with each other by many-to-many relationship

So, I wanna create a Output table with logic:

Mapping table 1 and 2 , in which the 1st posting date will be the 1st Running date.

Is there any way to do it with Dax measure?

 

ngocnguyen_0-1713272481052.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ngocnguyen ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can create two measures as below to get it:

NRun date = 
VAR _dealer =
    SELECTEDVALUE ( 'Table 1'[Dealer] )
VAR _postdate =
    SELECTEDVALUE ( 'Table 1'[Post date] )
VAR _prepdate =
    CALCULATE (
        MAX ( 'Table 1'[Post date] ),
        FILTER ( ALLSELECTED ( 'Table 1' ), 'Table 1'[Dealer]=_dealer&&'Table 1'[Post date] <_postdate )
    )
RETURN
    CALCULATE (
        MIN ( 'Table 2'[Run date] ),
        FILTER (
            'Table 2',
            'Table 2'[Run date] < _postdate
                && 'Table 2'[Run date] > _prepdate
        )
    )
NAmount = 
CALCULATE (
    SUM ( 'Table 2'[Amount] ),
    FILTER ( 'Table 2', 'Table 2'[Run date] = [NRun date] )
)

vyiruanmsft_0-1713321684127.png

Best Regards

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Write this calculated column formula in Table 2

Post date = calculate(min('Table 1'[Post date]),filter('Table 1','Table 1'[Dealer]=earlier('Table 2'[Dealer])&&'Table 1'[Post date]>earlier('Table 2'[Run date])))

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @ngocnguyen ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can create two measures as below to get it:

NRun date = 
VAR _dealer =
    SELECTEDVALUE ( 'Table 1'[Dealer] )
VAR _postdate =
    SELECTEDVALUE ( 'Table 1'[Post date] )
VAR _prepdate =
    CALCULATE (
        MAX ( 'Table 1'[Post date] ),
        FILTER ( ALLSELECTED ( 'Table 1' ), 'Table 1'[Dealer]=_dealer&&'Table 1'[Post date] <_postdate )
    )
RETURN
    CALCULATE (
        MIN ( 'Table 2'[Run date] ),
        FILTER (
            'Table 2',
            'Table 2'[Run date] < _postdate
                && 'Table 2'[Run date] > _prepdate
        )
    )
NAmount = 
CALCULATE (
    SUM ( 'Table 2'[Amount] ),
    FILTER ( 'Table 2', 'Table 2'[Run date] = [NRun date] )
)

vyiruanmsft_0-1713321684127.png

Best Regards

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

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.