Forum Discussion

paulsmit's avatar
paulsmit
Frequent Visitor
4 years ago
Solved

Minimum and Maximum weekly average by location

Hi,

 

I'm looking to see if the gap between the highest weekly location average index and the lowest weekly location average index is growing.  

 

WeekLocationIndex
1Hartington100.00
1Borrowdale95.44
1Borrowdale83.76
1Hartington100.00
1Borrowdale96.33
1Borrowdale84.99
1Snowdon91.73
1Snowdon98.27
1Snowdon89.30
1Treyarnon97.37
1Treyarnon100.00
1Treyarnon99.16
2London100.00
2London95.44
2Cambridge83.76
2Cambridge100.00
2Scotland96.33
2Scotland84.99
2Scotland91.73
2Derby98.27
2Derby89.30
2Derby97.37
2Derby100.00
2Mansfield99.16

 

From the data above I would expect to get the following results

 

WeekMin IndexMax IndexDiff between Max and Min Index
190.13100.009.87
291.0299.168.14

 

Cheers

 

Paul

  • Ah, OK.

    Min Index = MINX(
    ADDCOLUMNS( SUMMARIZE( 'Table', 'Table'[Location] ), "@avg", CALCULATE( AVERAGE('Table'[Index]) ) ),
    [@avg]
    )

    I think that should do it.

5 Replies

  • Ah, OK.

    Min Index = MINX(
    ADDCOLUMNS( SUMMARIZE( 'Table', 'Table'[Location] ), "@avg", CALCULATE( AVERAGE('Table'[Index]) ) ),
    [@avg]
    )

    I think that should do it.

    • paulsmit's avatar
      paulsmit
      Frequent Visitor

      Thank you so much 🙂  

      If for some reason I needed to take this to the next level and I wanted to get the min and max based on the average of the top 3 and bottom 3 scoring locations (rather than just the top and bottom scoring locations) is that possible?

      • johnt75's avatar
        johnt75
        Super User

        TOPN is the function you'd need to look at. You can specify whether the value you are ranking on should be ascending or descending, so you can get either the top or bottom 3. The actual code for ranking would depend on whether you wanted to take absolute values or averages, but you would then be able to run AVERAGEX over the tables returned by TOPN

  • Create the below 3 measures

    Min Index = MIN( 'Table'[Index] )
    Max Index = MAX( 'Table'[Index] )
    Diff between Min and Max Index = [Max Index] - [Min Index]

    Then add all 3 measures to a table, or other visual, with the Week column from your table

    • paulsmit's avatar
      paulsmit
      Frequent Visitor

      Apologies, I probably didn't explain in my initial post that I need to average the index for each location before I find the min and max values