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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
samotfrt
Frequent Visitor

Table visual with both active and inactive relationship

Hello,

 

I have the following model

 

samotfrt_0-1709066402579.png

 

 

each table with the following values

 

 

media1_idmedia2_idrelation
12SEQUEL
21PREQUEL
34RETELLING
43RETELLING
67SIDE-STORY
76SIDE-STORY
28SEQUEL
82PREQUEL

 

mediaiduseridstatus 
11completed
21completed
41completed
61completed
62completed
73completed
81planning

 

mediaidname
1Godfather 
2Godfather 2
3The Mummy (1932 film)
4The Mummy (1999 film)
5Titanic
6Breaking Bad
7Better Call Saul
8godfather 3

 

Now, I am trying to make a table visual that would display the media related to the media that the user have completed , like the following for the user 1

samotfrt_1-1709066493223.png

 

I can make the following table but then i  cannot "vlookup" the name of the media2 neither can I filter out the rows in which the media2 was already completed by the user (first 2 rows)

samotfrt_2-1709066727399.png

 

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @samotfrt ,

I updated the pbix file(see the attachment), please check if that is what you want.

Flag = 
VAR _uids =
    ALLSELECTED ( 'userlist'[userid] )
VAR _media1 =
    SELECTEDVALUE ( 'relations'[media1_id] )
VAR _media2 =
    SELECTEDVALUE ( 'relations'[media2_id] )
VAR _tab1 =
    CALCULATETABLE (
        VALUES ( 'userlist'[mediaid] ),
        FILTER (
            ALLSELECTED ( 'userlist' ),
            'userlist'[userid]
                IN _uids
                    && 'userlist'[status] = "completed"
        )
    )
VAR _tab2 =
    CALCULATETABLE (
        VALUES ( 'userlist'[mediaid] ),
        FILTER (
            ALLSELECTED ( 'userlist' ),
            'userlist'[userid]
                IN _uids
                    && 'userlist'[status] <> "completed"
        )
    )
VAR _count =
    CALCULATE (
        COUNT ( 'relations'[media1_id] ),
        FILTER (
            ALLSELECTED ( 'relations' ),
            'relations'[media1_id] = _media1
                && 'relations'[media1_id] IN _tab1
        )
    )
RETURN
    IF ( NOT(_media2 in _tab1) &&( _count = 1 || ( _count >= 1  && _media2 IN _tab2 )), 1, 0 )

vyiruanmsft_0-1709171836884.png

Best Regards

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @samotfrt ,

I created a sample pbix file(see the attachment), please check if that is what you want.

media2_name = 
CALCULATE (
    MAX ( 'media'[name] ),
    FILTER (
        ALL ( 'media' ),
        'media'[mediaid] = SELECTEDVALUE ( 'relations'[media2_id] )
    )
)
Flag = 
VAR _uids =
    ALLSELECTED ( 'userlist'[userid] )
VAR _media1 =
    SELECTEDVALUE ( 'relations'[media1_id] )
VAR _media2 =
    SELECTEDVALUE ( 'relations'[media2_id] )
VAR _tab1 =
    CALCULATETABLE (
        VALUES ( 'userlist'[mediaid] ),
        FILTER (
            ALLSELECTED ( 'userlist' ),
            'userlist'[userid]
                IN _uids
                    && 'userlist'[status] = "completed"
        )
    )
VAR _tab2 =
    CALCULATETABLE (
        VALUES ( 'userlist'[mediaid] ),
        FILTER (
            ALLSELECTED ( 'userlist' ),
            'userlist'[userid]
                IN _uids
                    && 'userlist'[status] <> "completed"
        )
    )
VAR _count =
    CALCULATE (
        COUNT ( 'relations'[media1_id] ),
        FILTER (
            ALLSELECTED ( 'relations' ),
            'relations'[media1_id] = _media1
                && 'relations'[media1_id] IN _tab1
        )
    )
RETURN
    IF ( _count = 1 || ( _count >= 1 && _media2 IN _tab2 ), 1, 0 )

vyiruanmsft_0-1709102510578.png

Best Regards

Thank you  for the help.

 

However I noticed that when the _count = 1 it still displays relations to watched media. For example the first row shouldn't be displayed because media2_id = 2 was watched by the user.

Anonymous
Not applicable

Hi @samotfrt ,

I updated the pbix file(see the attachment), please check if that is what you want.

Flag = 
VAR _uids =
    ALLSELECTED ( 'userlist'[userid] )
VAR _media1 =
    SELECTEDVALUE ( 'relations'[media1_id] )
VAR _media2 =
    SELECTEDVALUE ( 'relations'[media2_id] )
VAR _tab1 =
    CALCULATETABLE (
        VALUES ( 'userlist'[mediaid] ),
        FILTER (
            ALLSELECTED ( 'userlist' ),
            'userlist'[userid]
                IN _uids
                    && 'userlist'[status] = "completed"
        )
    )
VAR _tab2 =
    CALCULATETABLE (
        VALUES ( 'userlist'[mediaid] ),
        FILTER (
            ALLSELECTED ( 'userlist' ),
            'userlist'[userid]
                IN _uids
                    && 'userlist'[status] <> "completed"
        )
    )
VAR _count =
    CALCULATE (
        COUNT ( 'relations'[media1_id] ),
        FILTER (
            ALLSELECTED ( 'relations' ),
            'relations'[media1_id] = _media1
                && 'relations'[media1_id] IN _tab1
        )
    )
RETURN
    IF ( NOT(_media2 in _tab1) &&( _count = 1 || ( _count >= 1  && _media2 IN _tab2 )), 1, 0 )

vyiruanmsft_0-1709171836884.png

Best Regards

Thanks.

 

I changed the final line to

 

IF ( NOT(_media2 in _tab1) &&(  _count >= 1 ), 1, 0 )

 

Because i think the (_media2 IN _tab2) only considers shows in the user list, that are not "completed". So, if for example media_id 8, that in the sample i provided is in the list of the user as "Planning",  were to not be in the user list, it wouldn't show up.

 

 

amitchandak
Super User
Super User

@samotfrt , Based on what I got. You have use userelationship in measure to use inactive relationship

 

calculate( countrows('realtion'),USERELATIONSHIP ('realtion'[media2_id], 'Media'[Mediaid]))

 

 

https://radacad.com/userelationship-or-role-playing-dimension-dealing-with-inactive-relationships-in...

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

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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