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
cjd72consulting
Frequent Visitor

Generating a sports schedule

Background - lots of programming experience - but new to Power BI. Playing around with some sports data just to get my feet wet.

 

I'm assuming this should be easy, but I've banged my head against it for a couple of days.

 

I have two tables:

 

Teams

-----

TeamID

TeamName

 

Games

--------

GameID

GameDate

HomeTeamID

AwayTeamID

 

How would you go about creating a visualization that represents a schedule in the form of:

GateDate HomeTeamName  AwayTeamName

 

I don't need every detail explained, just the major steps.  

 

 

 

 

2 ACCEPTED SOLUTIONS

Yes, indeed, like all rookies to DAX, you do miss something simple. I wish you were able to understand this simple solution.

CNENFRNL_0-1678228103166.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

View solution in original post

thats many way but i get solution from below method

 

 

  EVALUATE 
     SUMMARIZECOLUMNS('games'[game date],

                      "HomeTeamname",CALCULATE(VALUES(team[teamname]),

             TREATAS(VALUES(games[hometeam id]),team[team id])

                  ),

                  "awayTeamname", CALCULATE(VALUES(team[teamname]),

            TREATAS(VALUES(games[awayteam id]),team[team id])

            )

          )  

 

Screenshot 2023-08-17 111449.pngScreenshot 2023-08-17 111545.png


             Screenshot 2023-08-17 112433.png

 

 

         

we need to use Treats to Change Data lineage of game's table  to Team Table

which create Virtual Relationship and through it we able to filter Team table

If you Want to know more about it please visit Here .

 

 

View solution in original post

10 REPLIES 10
CNENFRNL
Community Champion
Community Champion

Simple enough

  1. Unpivot HomeTeamID and AwayTeamID
  2. Create relationship

Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!


@CNENFRNL wrote:

Simple enough

  1. Unpivot HomeTeamID and AwayTeamID
  2. Create relationship

That's what I thought the answer was.  But I still can't get from there to a visualization in the form of a table with the columns:

   GameDate HomeTeamName AwayTeamName

 

Can you help me get from the unpivoted table to that visualization?  I know I'm probably missing something simple,  but I keep getting stuck.

 

 

 

 

 

Yes, indeed, like all rookies to DAX, you do miss something simple. I wish you were able to understand this simple solution.

CNENFRNL_0-1678228103166.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

thats many way but i get solution from below method

 

 

  EVALUATE 
     SUMMARIZECOLUMNS('games'[game date],

                      "HomeTeamname",CALCULATE(VALUES(team[teamname]),

             TREATAS(VALUES(games[hometeam id]),team[team id])

                  ),

                  "awayTeamname", CALCULATE(VALUES(team[teamname]),

            TREATAS(VALUES(games[awayteam id]),team[team id])

            )

          )  

 

Screenshot 2023-08-17 111449.pngScreenshot 2023-08-17 111545.png


             Screenshot 2023-08-17 112433.png

 

 

         

we need to use Treats to Change Data lineage of game's table  to Team Table

which create Virtual Relationship and through it we able to filter Team table

If you Want to know more about it please visit Here .

 

 

Can I ask a followup question?  I've played around with the solution you provided, and I'm still struggling to understand how the CALCULATE FUNCTION works in this expression.

 

Specifically I'm unclear on where the context comes from such that this measure returns the correct team.  Does the table visual create a context for each row that the measure runs inside of?

 

 

 

 

 

Em.... impossible to explain it in several sentences. CALCULATE() is the grail of DAX. Crack down on it, then you (almost) master DAX. Your DAX journey starts from CALCULATE() and the ultimate goal is also CALCULATE().

CALCULATE – DAX Guide

 

Tricky thing is that CALCULATE() functions like a 10-layer wrapper; and above all, the most annoying thing is that, up till now, there's no handy debug tool allowing DAX user to debug step-by-step. Tons of abstract details like context transition, filters modification, filtering propagation etc. happen in a sandbox.

 

Enjoy DAX!


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Sahir_Maharaj
Super User
Super User

Hello @cjd72consulting,

 

1. Create a relationship between the Teams table and the Games table based on the TeamID.

2. Create a new measure in the Games table that concatenates the HomeTeamName and AwayTeamName columns with a hyphen (-) separator.

Matchup = CONCATENATE(Games[HomeTeamName], " - ", Games[AwayTeamName])

3. Create a new table visual and add the following columns in this order:

  • GameDate column from the Games table
  • HomeTeamName column from the Teams table
  • AwayTeamName column from the Teams table

4. For the HomeTeamName and AwayTeamName columns, expand the Teams table and select the TeamName column.

5. In the Values section of the visual, add the Matchup measure from the Games table.

 

Hope this helps.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Thanks Sahir,

 

I may very well be missing something, but I don't think this works.

My Games Table has Team ID's, not Team Names, so your step 2 doesn't seem to make sense?

 

@cjd72consulting, I might have misinterpretted your tables. Can you please provide more detail on:

 

  • HomeTeamID
  • AwayTeamID

 

Are these additional tables or do they relate to the Teams table?


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution?
➤ Lets connect on LinkedIn: Join my network of 13K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

@Sahir_Maharaj 

 

HomeTeamID and AwayTeamID are foreign keys referencing the Primary key TeamID in the Teams table

 

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.