Forum Discussion

samotfrt's avatar
samotfrt
Frequent Visitor
2 years ago
Solved

Table visual with both active and inactive relationship

Hello,

 

I have the following model

 

 

 

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

 

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)

 

 

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    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 )

    Best Regards

5 Replies

  • Anonymous's avatar
    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 )

    Best Regards

    • samotfrt's avatar
      samotfrt
      Frequent Visitor

      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's avatar
        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 )

        Best Regards