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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Count Number of Times Players Play Together in Games

New to Power BI and been doing a bit of research on the product.  Making good progress on my project but ran into brick wall on one calculation.  I would like to see how many times two players have played together in a game.  Here is my table layout:

GameIdPlayerName
1QB
1WR1
1WR2
1RB1
1TE
2QB
2WR1
2RB2
2WR3
2RB3
3QB
3WR1
3RB3
3K
3WR4

 

Here are the results I expect to get.

Combo - TimesPlayedTogher
QB/WR1 - 2
QB/RB1  - 1
QB/WR2  - 1
QB/K - 1
QB/TE  - 1
QB/WR3  - 2
QB/RB2  - 1
QB/RB3  - 2
QB/WR4  - 1

 

I just can't seem to output this result with two players for the same game counted as one unit.  Been playing around with several different measured formulas.  Any thoughts?

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thank you good sir.  I had all my data in a single table and when I tried mimic what you had done I got some bizaare results.  I tried breaking up the data but no luck.  But I was able to take my data and build off template you created.  I'm still learning so maybe one day I'll figure out why my source data didn't work.

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

Hi @Anonymous 

 

I had an initial look at this and it fits the Basket Analysis pattern:

https://www.daxpatterns.com/basket-analysis/

 

I created up a sample PBIX here showing how you could handle this:

  1. Create a data model looking like this, with the table you posted being called Games, and dimension tables for Player and Player Secondaryimage.png

     

  2. Note that there is an inactive relationship between Games[PlayerName] and 'Player Secondary'[PlayerName Secondary].

  3.  

     Create these measures:

    Times Played Together = 
    CALCULATE ( 
        DISTINCTCOUNT ( Games[GameId] ),
        CALCULATETABLE ( 
            SUMMARIZE ( Games, Games[GameId] ),
            ALL ( Player ),
            USERELATIONSHIP ( Games[PlayerName], 'Player Secondary'[PlayerName Secondary] )
        )
    )
    PlayerName < PlayerName Secondary = 
    INT ( SELECTEDVALUE ( Player[PlayerName] ) < SELECTEDVALUE ( 'Player Secondary'[PlayerName Secondary] ) )
    Combo = 
    SELECTEDVALUE ( Player[PlayerName] ) & "/" & SELECTEDVALUE ( 'Player Secondary'[PlayerName Secondary] )
  4. Then create visuals with fields Player[PlayerName], 'Player Secondary'[PlayerName Secondary], [Combo] and [Times Played Together].
  5. Include a visual level filter [PlayerName < PlayerName Secondary] = 1
  6. In my example PBIX I created a table with PlayerName & PlayerName Secondary hidden, so you can see Times Played Together by Combo.image.png

     

  7. Note - you could also create a table containing the Combo values and use this to drive the filtering. This might complicate the data model & formulas a little (in my opinion) but could be done.

 

Hopefully that's useful as a start.

 

Regards,

Owen


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
Twitter
LinkedIn
Anonymous
Not applicable

Thank you good sir.  I had all my data in a single table and when I tried mimic what you had done I got some bizaare results.  I tried breaking up the data but no luck.  But I was able to take my data and build off template you created.  I'm still learning so maybe one day I'll figure out why my source data didn't work.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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