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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Cado_one
Resolver III
Resolver III

DAX RELATED function with many to many relationship

Hi all,

 

I know there are already many topics on this subject but I don't understand the explanations given and solutions.

I have to tables with a many to many relationship between the "code projet" columns as you can see in the following screenshot 

Cado_one_0-1620219809704.png

 

I need then to compare "date_insert_rpa" from first table to "DateMEX" from the second table but here comes the troubles :

RatioMW = 

CALCULATE(

SUM(rpa[nb_heure_rpa]) / (DISTINCTCOUNT(rpa[jours_date_rpa].[Year]) * [PuissanceMW]),

FILTER(rpa, 'rpa'[jours_date_rpa].[Year] > RELATED(descriptionActifsInfos[DateMEX].[Year]))

)

 

This error is returned : The column 'descriptionActifsInfos[DateMEX].[Year]' either doesn't exist or doesn't have a relationship to any table available in the current context.

 

I think other topics advise to use RELATEDTABLE instead of RELATED function but I don't understand how to use it.

 

If anyone have the solution I'd be very glad to try it.

 

Thanks in advance.

Regards,

Cado

1 ACCEPTED SOLUTION

Hi @Cado_one ,

 

 If you need to get value from many side table , you need to use RELATEDTABLE function .RELATEDTABLE function needs to be used with aggregation function in your situation:

 

RatioMW =
CALCULATE (
    SUM ( rpa[nb_heure_rpa] )
        / ( DISTINCTCOUNT ( rpa[jours_date_rpa].[Year] ) * [PuissanceMW] ),
    FILTER (
        rpa,
        'rpa'[jours_date_rpa].[Year]
            > YEAR (
                MAXX (
                    RELATEDTABLE ( descriptionActifsInfos ),
                    descriptionActifsInfos[DateMEX]
                )
            )
    )
)

 

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

 

Best Regards,

Dedmon Dai

 

 

 

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@Cado_one , Try year functions

 

CALCULATE(

SUM(rpa[nb_heure_rpa]) / (DISTINCTCOUNT(year(rpa[jours_date_rpa])) * [PuissanceMW]),

FILTER(rpa, 'rpa'[jours_date_rpa].[Year] > RELATED(descriptionActifsInfos[DateMEX].[Year]))

)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hello @amitchandak 

 

YEAR function can't be used inside a DISTINCTCOUNT or RELATED functions because it doesn't return a column.

Hi @Cado_one ,

 

 If you need to get value from many side table , you need to use RELATEDTABLE function .RELATEDTABLE function needs to be used with aggregation function in your situation:

 

RatioMW =
CALCULATE (
    SUM ( rpa[nb_heure_rpa] )
        / ( DISTINCTCOUNT ( rpa[jours_date_rpa].[Year] ) * [PuissanceMW] ),
    FILTER (
        rpa,
        'rpa'[jours_date_rpa].[Year]
            > YEAR (
                MAXX (
                    RELATEDTABLE ( descriptionActifsInfos ),
                    descriptionActifsInfos[DateMEX]
                )
            )
    )
)

 

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

 

Best Regards,

Dedmon Dai

 

 

 

@v-deddai1-msft 

 

Thank you very much, this works perfectly !

 

Regards,

Cado

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.