Blog Post

Power BI Community Blog
3 MIN READ

Advanced Sport Visualisations in Power BI

RayWu's avatar
RayWu
Icon for Memorable Member rankMemorable Member
4 years ago
  • Animation based on time sequence
  • Visualising over 1000 metrics e.g., xG, shot direction, pass, goal,etc
  • Potential machine learning e.g., predict the next 10/20 second.

In this blog, we will cover how to build interactive graphs for sports analytics in Power BI, and I believe every sports data analyst should use BI tool over custom software as it's a lot better.

Why Power BI?
- Easy to maintain, modify and understand.
- No coding require (python, matplotlib, D3, etc)

- Use multiple data sources e.g., video, football data providers (statsbomb,opta,etc)

- AutoML

- User-friendly platform: Mobile, iPad (Power App), dashboard/report (Power BI)

Here is my basic football visualisation demonstrating the potential it has within Power BI.  Always start with the basic charts and understand how the SQL queries make up the visualisation as things can get tricky, once we start looking at the neural networks. 

https://community.powerbi.com/t5/Data-Stories-Gallery/Basic-Shot-Pass-Convex-Hull/td-p/2657544

 


In any BI tools, we cannot simply drag and drop x1, x2, y1, and y2 values into a chart to visualise a line between two scatter points. This is because a line chart requires chronicle values such as distance or time, and a scatter chart can only take two variables.

 

As you can see, this data above is simply taking X and Y locations, which we can plot onto a graph. Each row represents the location of the data.


Green represents the start location and the orange end location. We can plot these data using a scatter plot but cannot connect them in a line chart.

Solution


A workaround is to append x1, x2, y1, and y2 and assign a unique ID column with value “S,E” (start, end point). In the Power Query editor, we can duplicate the data table twice, and then remove 2 columns from each copy(x1,y1 on one ; x2,y2 on the other). Make sure to rename the columns to be x and y and then append them together. Otherwise, the data won’t join together and need to reverse the step. Now, we can plot the new X and Y in a line chart and stack them on the scatter plot.

This technique is pretty good as we don’t need to use python,D3 or any programming languages to visualise. On the other hand, Power BI plotly custom visual follows a similar pattern by “stacking” on top of multiple charts to create new visualisations. However, I prefer to stick with Power BI standard visualisation as it's much easier to do.

Here is the final outcome of the visualisation showing the shot direction.

 



Advanced metrics involving time sequences, convex hull data

Convex hull can be easily created through a SQL script on the server side; all we need to do is join the table onto our database. The benefit of doing this is to ensure performance is always maintainable and at its best. We don't need to write any Dax calculation for these visualisations, however for dynamic cross-filtering and ranking would definitely require Dax.

Animation

 

For animation, I prefer to use a custom visual play axis as it's free and easier to use. For any graph visual we can simply drag timestamp onto the column but it would not be effective as we want to play all graphs simultaneously.

Aesthetic

Scatter Plot customising colour/size/type

Line chart customising line colour/line type

Make sure to fade the line to grey/fade to give a better overall UX and change all scatter plots to a certain colour (faded purple/blue, personal preferences). 


Additional tips

 

  • For large data sources, I highly recommend filtering all these data to a usable level as there will be potential performance issues such as delay. Make sure to do this through the server side layer and not within dax calculation.
  • Always use the performance analyser in Power BI to make sure the visualisation is smooth. As more features are added on top of the visualisations, likely to have slower performance. Ideally, we want to make sure it's less than 2 seconds for the best user experience.

Other data viz galleries that I've created

Outcome analysis.

https://community.powerbi.com/t5/Data-Stories-Gallery/Football-outcome-analysis/td-p/2657537

Football heatmap of player movement.
https://community.powerbi.com/t5/Data-Stories-Gallery/heat-map-of-players-movement-in-the-field/td-p/2657391

iPad Football dashboard.
https://community.powerbi.com/t5/Data-Stories-Gallery/Football-iPad-Dashboard/td-p/2657492

There will be a lot of interesting things we can do within BI sports visualisations, which I will be covering in later blogs.

Updated 4 years ago
Version 19.0

6 Comments

  • dpombal's avatar
    dpombal
    Icon for Post Partisan rankPost Partisan

    Hi RayWu,


    I have the same question , like ingdanielrayez

    - Regarding how to get one color for Succes Pass and another for Unsuccesfull Pass?

    Configuring line chart

    • x on Xaxis
    • y on Yaxis
    • Legend (Id unique field)

    There is no option to use outcome field (0,1) on legend ( if you use this field there is no option to plot all passes) as it is required to use the ID for plotting all lines.


    Regards

  • Hi RayWu, 

     

    Last few days I decided to move my football analyzes from python to Power Bi. Your advice on drawing pass maps was quite helpful, but I have a few questions;

     

    - How did you get one color for Succes Pass and another for Unsuccesfull Pass?

    I graph each passing line using the line graph: Table.X on the X axis and Table.SumY on Y. The only way to graph each vector was by using Id in the Category field. This way prodece multiple legend-color for each Id. How I could fix this?

     

     

     

     

     

     

     

     

     

     

     

     

    Thanks in advance

     

  • Hello RayWu,

     

    Impressive work.

    I am on ingdanielrayez step, I can do as a line chart, but I cannot differentiate it by outcome.

    Is it possible to give more details about your process or share your data model in order to check how it's done?

     

    Thanks!

  • radumpandea's avatar
    radumpandea
    Regular Visitor

    Hello RayWu .

     

    Fantastic work and thank you very much for sharing.

     

    Can you please share the way you made things work in the line graph? The Legend usage with ID of each Pass turns this into a rainbow and you can't visualize that properly.

     

    Many thanks in advance.

  • RayWu's avatar
    RayWu
    Icon for Memorable Member rankMemorable Member

    Hello everyone, many of these methods may be outdated, so I can't guarantee their effectiveness on newer versions. I've used different workarounds to make them compatible with Power BI versions from 2011 to 2022.

    Regarding the chart colors, I utilized the outcome values (0 or 1) to visualise the red and green i.e failure/success.  These values should be in the data fields and are linked to the combined X and Y axes. Data modeling transformation is necessary, especially since open source data like Opta, StatsBomb, etc., doesn't come with this information by default which you will have to link together to generate a new column to visualise.

    Considering the recent updates, Python might be a more suitable alternative. You should be able to visualize the graph using Matplotlib in Power BI and other py libraries . But for perforance wise default charts is always the best in power bi.