cancel
Showing results for
Did you mean: New Member

## Average of the lowest 40

I have been tryng to create a measure that calculates the average of the 'best' 40 results from site A by period. Lower scores are better and zero represents no score and needs to be ignored. Sample data below. There are hundreds of scores per period at site A. Can anyone help? Please 🙂

 Site Period Score A 100 1.7 A 100 1.65 A 100 1.55 A 100 1.6 B 100 0 A 100 1.59 A 101 1.45 A 101 1.55 A 101 1.75 A 101 1.55 A 101 1.9 B 101 0 B 101 1.75

1 ACCEPTED SOLUTION Frequent Visitor

Hey Jimmy17.
You could first create a calculated column which counts the values which are lower than the value in the current row.
Something like this should work:

Rank =
VAR ScoreCurrentRow = Score[Score]
VAR SiteCurrentRow = Score[Site]
VAR PeriodCurrentRow = Score[Period]
return COUNTROWS(FILTER(Score, Score[Score] < ScoreCurrentRow && SiteCurrentRow = Score[Site] && PeriodCurrentRow = Score[Period] &&  Score[Score] <> 0 )) + 1 After this you could create a measure which calculates the average over the site and the period, but only over the top 40 (In my example it was 2):
AVG = CALCULATE(AVERAGE(Score[Score]), Score[Score] <> 0, Score[Rank] <= 2)  Frequent Visitor

Hey Jimmy17.
You could first create a calculated column which counts the values which are lower than the value in the current row.
Something like this should work:

Rank =
VAR ScoreCurrentRow = Score[Score]
VAR SiteCurrentRow = Score[Site]
VAR PeriodCurrentRow = Score[Period]
return COUNTROWS(FILTER(Score, Score[Score] < ScoreCurrentRow && SiteCurrentRow = Score[Site] && PeriodCurrentRow = Score[Period] &&  Score[Score] <> 0 )) + 1 After this you could create a measure which calculates the average over the site and the period, but only over the top 40 (In my example it was 2):
AVG = CALCULATE(AVERAGE(Score[Score]), Score[Score] <> 0, Score[Rank] <= 2)   