Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello, I am trying to create a metric that based on the selected `player_id` it returns the moving average for the last x dates available.
Solved! Go to Solution.
Hi @veranceftw ,
I created a sample pbix file(see attachment), please check whether that is what you want.
1. Create a measure as below to get the count of dates per player
CountofDates =
CALCULATE (
DISTINCTCOUNT ( 'player_stats_matchday'[Date] ),
FILTER (
ALLSELECTED ( 'player_stats_matchday' ),
'player_stats_matchday'[player_id] = SELECTEDVALUE ( 'Players'[player_id] )
&& 'player_stats_matchday'[Date] <= SELECTEDVALUE ( 'player_stats_matchday'[Date] )
)
)
2. Create a measure as below to get the rolling_tst
rolling_tst =
VAR _count =
CALCULATE (
DISTINCTCOUNT ( 'player_stats_matchday'[Date] ),
FILTER (
ALLSELECTED ( 'player_stats_matchday' ),
'player_stats_matchday'[player_id] = SELECTEDVALUE ( 'Players'[player_id] )
&& 'player_stats_matchday'[Date] <= SELECTEDVALUE ( 'player_stats_matchday'[Date] )
)
)
RETURN
AVERAGEX (
FILTER (
ALLSELECTED ( 'player_stats_matchday' ),
[CountofDates] >= _count - 4
&& 'player_stats_matchday'[CountofDates] <= _count
),
'player_stats_matchday'[xG Net]
)
If the above one is not what you want, please provide some sample data with Text format(exclude sensitive data) and your expected result with more details(backend logic, special examples with screenshot etc.). Thank you.
Best Regards
Hi @veranceftw ,
I created a sample pbix file(see attachment), please check whether that is what you want.
1. Create a measure as below to get the count of dates per player
CountofDates =
CALCULATE (
DISTINCTCOUNT ( 'player_stats_matchday'[Date] ),
FILTER (
ALLSELECTED ( 'player_stats_matchday' ),
'player_stats_matchday'[player_id] = SELECTEDVALUE ( 'Players'[player_id] )
&& 'player_stats_matchday'[Date] <= SELECTEDVALUE ( 'player_stats_matchday'[Date] )
)
)
2. Create a measure as below to get the rolling_tst
rolling_tst =
VAR _count =
CALCULATE (
DISTINCTCOUNT ( 'player_stats_matchday'[Date] ),
FILTER (
ALLSELECTED ( 'player_stats_matchday' ),
'player_stats_matchday'[player_id] = SELECTEDVALUE ( 'Players'[player_id] )
&& 'player_stats_matchday'[Date] <= SELECTEDVALUE ( 'player_stats_matchday'[Date] )
)
)
RETURN
AVERAGEX (
FILTER (
ALLSELECTED ( 'player_stats_matchday' ),
[CountofDates] >= _count - 4
&& 'player_stats_matchday'[CountofDates] <= _count
),
'player_stats_matchday'[xG Net]
)
If the above one is not what you want, please provide some sample data with Text format(exclude sensitive data) and your expected result with more details(backend logic, special examples with screenshot etc.). Thank you.
Best Regards
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 41 | |
| 38 | |
| 36 | |
| 30 | |
| 28 |
| User | Count |
|---|---|
| 128 | |
| 88 | |
| 79 | |
| 67 | |
| 62 |