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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Pan_Forex
Helper III
Helper III

Average for last 30 results, 2 conditions

Hey guys, I would like to count the average score for each player separately for each race he played. I would like to take into account the last 30 games in which he played a particular race. How do I rewrite the following functions to make this possible? The current version counts well the average of each player's last 30 games. 

 

1. I created an index column: index= rankx(filter(Table, [Player] = earlier([Player]) ), [game_id],,asc,desc)

2. I created new table: series = generateseries(Min(Table[index]), Max(Table[index]) ,1)

3. I connected the two tables with a relation

4. i created a meassure: calculate(average(Table[score]), filter(all(series) , series[Value] >= max(series[Value]) -30 && series[Value] <= max(series[Value]) ))

 

Table looks like that:

Pan_Forex_0-1672763047224.png

I filtered out a single player to show what result I want to achieve:

Pan_Forex_1-1672763664582.png

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @Pan_Forex 

I don't see why do you need to create the index column and the series table. Please try

AverageMeasure =
AVERAGEX (
TOPN (
30,
CALCULATETABLE (
'Table',
ALLEXCEPT ( 'Table', 'Table'[player], 'Table'[race] )
),
'Table'[game_id]
),
'Table'[score]
)

View solution in original post

8 REPLIES 8
Pan_Forex
Helper III
Helper III

If you want I can provide data and results of several players to make it easier for you to understand my logic

 

@Pan_Forex 

Please try returning the top 1 instead of thhe top 30. See if you get the last result. Also in this filter context there is no need for the CALCULATETABLE - ALLEXCEPT

AverageMeasure =
AVERAGEX (
TOPN (
1,
'Table',
'Table'[game_id]
),
'Table'[score]
)

In this form it only takes one result into account 😞 Maybe let's approach it differently. How do you count the average for each player and last 30 games played only as Romans?

@Pan_Forex 

If it works with top1 then it should work with top30. Please double check your results. 

tamerj1
Super User
Super User

Hi @Pan_Forex 

I don't see why do you need to create the index column and the series table. Please try

AverageMeasure =
AVERAGEX (
TOPN (
30,
CALCULATETABLE (
'Table',
ALLEXCEPT ( 'Table', 'Table'[player], 'Table'[race] )
),
'Table'[game_id]
),
'Table'[score]
)

Thank you so much for your reply. You are right, your solution is much simpler. Unfortunately, the average is still counted only from the last 30 games regardless of race. I would like the average to be counted from the last 30 games of Romans, last 30 games of Asians etc. It seems to me that I need 4 separate measures?

@Pan_Forex 

Would you please share a screenshot of your visual?

It seems to me that currently the problem occurs when someone has played more than 30 games with a particular race. Then the result is wrong.

Pan_Forex_0-1672766663952.png

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.