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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
sneem
Frequent Visitor

Measure using linked table

Hi !

 

I have a problem with my dax measure which doesn't seem to be complicated ...
I have two tables : Match (with columns team_1_id and team_2_id) and Details (of the match) linked by match_id, and a slicer to select the team.

I would like to get the number of victories if the team is playing at home.

No problem to get the selected team with SELECTEDVALUE.
I have to use CALCULATE function with FILTER but I don't know how to check if the selected team is playing home.

I tried this but that doesn't work correcly :

 

Win =
VAR Match_Team_Id_Home = ALLSELECTED('public match'[team_1_id])
RETURN
CALCULATE (
    COUNTROWS ( 'details' ),
    FILTER ( 'details', 'details'[team_1_final_score] > 'details'[team_2_final_score] && [SelectedTeamId] in Match_Team_Id_Home)
)


Thanks in advance !

1 ACCEPTED SOLUTION
sneem
Frequent Visitor

I finally found the solution which was simple.

I made the two relations inactive, and then I was able to access to the team_1_id and team_2_id like this:

Win_Home =
CALCULATE (
    COUNTROWS ( details ),
    FILTER (
        details,
        details[team_1_final_score] > details[team_2_final_score]
            &&  RELATED ( match[team_1_id] ) == [SelectedTeamId]
    )
)
 
and 
 
Win_Away =
CALCULATE (
    COUNTROWS ( details ),
    FILTER (
        details,
        details[team_2_final_score] > details[team_1_final_score]
            &&  RELATED ( match[team_2_id] ) == [SelectedTeamId]
    )
)

View solution in original post

3 REPLIES 3
sneem
Frequent Visitor

I finally found the solution which was simple.

I made the two relations inactive, and then I was able to access to the team_1_id and team_2_id like this:

Win_Home =
CALCULATE (
    COUNTROWS ( details ),
    FILTER (
        details,
        details[team_1_final_score] > details[team_2_final_score]
            &&  RELATED ( match[team_1_id] ) == [SelectedTeamId]
    )
)
 
and 
 
Win_Away =
CALCULATE (
    COUNTROWS ( details ),
    FILTER (
        details,
        details[team_2_final_score] > details[team_1_final_score]
            &&  RELATED ( match[team_2_id] ) == [SelectedTeamId]
    )
)
amitchandak
Super User
Super User

@sneem , try like

 


Win =
VAR Match_Team_Id_Home = ALLSELECTED('public match'[team_1_id])
RETURN
CALCULATE (
COUNTROWS ( 'details' ),
FILTER ( 'details', 'details'[team_1_final_score] > 'details'[team_2_final_score] && 'public match'[team_1_id] in Match_Team_Id_Home)
)

 

If this does not help
Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

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

hi @amitchandak 

 

Thank you for your help.

After investigation the relation between match.team_1_id and team.id was inactive (another relation was active instead).

This works after activation of the relation:

Win_Home =
CALCULATE (
    COUNTROWS ( details ),
    FILTER (
        details,
        details[team_1_final_score] > details[team_2_final_score]
            && RELATED ( match[team_1_id] ) == [SelectedTeamId]
    )
)
 
But, of course, this doesn't work if the team is playing away because the relation between match.team_2_id and team.id is still inactive:
Win_Away =
CALCULATE (
    COUNTROWS ( details ),
    FILTER (
        details,
        details[team_2_final_score] > details[team_1_final_score]
            && RELATED ( match[team_2_id] ) == [SelectedTeamId]
    )
)
 
I tried do use USERELATIONSHIP to activate the relation for this mesure but that doesn't work. Have you got an idea ?
 
This is the model (simplified):
sneem_0-1667603341248.png

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.