Forum Discussion

Pharms's avatar
Pharms
Frequent Visitor
2 years ago
Solved

Ranking averages into quartiles

Hello

Can't find quite what I am after in other posts. The scenario is I have about 50 people each with a result in a variety of subjects, at different points in time. I would like to rank the people into quartiles based on their average over the subjects. The data looks something like this

Currently in excel where the owner averages and then ranks, then manually assigns quartiles. This data will soon be in a SQL server and I have been asked to automate this process. It will be a card filtered by the individual so I can assign a Term filter to the visual, but struggling with the quartiling by average of results.

 

Hope I am being clear enough and many thanks for any advice in advance. 

  • Pharms 

    Please find attached the file with the expected outcome:

    Quartile = 
    
    VAR __Avg = [Student Average]
    VAR __Q1  =  PERCENTILEX.EXC( ALLSELECTED( 'Table'[Pupil]) , [Student Average] , 0.25  )
    VAR __Q2  =  PERCENTILEX.EXC( ALLSELECTED( 'Table'[Pupil]) , [Student Average] , 0.50  )
    VAR __Q3  =  PERCENTILEX.EXC( ALLSELECTED( 'Table'[Pupil]) , [Student Average] , 0.75  )
    RETURN
        SWITCH(
            TRUE(),
            __Avg > 0 && __Avg <= __Q1 , "Q1",
            __Avg > 0 && __Avg <= __Q2, "Q2",
            __Avg > 0 && __Avg <= __Q3 , "Q3",
             "Q4"
        )
    

     



3 Replies

  • Pharms 

    Could you share the expected result in Excel as you have share the source data?

  • Pharms's avatar
    Pharms
    Frequent Visitor
    PupilSubjectTermResult  PupilAverageQuartile   
    AMT22English80  A76.3Q4 Q142.3
    BMT22English85  B72.0Q3 Q260.75
    CMT22English71  C76.0Q4 Q374
    DMT22English33  D43.0Q2   
    EMT22English35  E57.9Q2   
    FMT22English67  F63.6Q3   
    GMT22English50  G41.6Q1   
    HMT22English84  H64.4Q3   
    AMT22Maths66.23        
    BMT22Maths59.07        
    CMT22Maths78.76        
    DMT22Maths63        
    EMT22Maths57        
    FMT22Maths57        
    GMT22Maths41        
    HMT22Maths61        
    AMT22French72        
    BMT22French76        
    CMT22French66        
    DMT22French62        
    EMT22French48        
    FMT22French76        
    GMT22French60        
    HMT22French54        
    AMT22Chemistry62        
    BMT22Chemistry69        
    CMT22Chemistry74        
    DMT22Chemistry26        
    EMT22Chemistry38        
    FMT22Chemistry59        
    GMT22Chemistry33        
    HMT22Chemistry64        
    AMT22Geography85        
    BMT22Geography75        
    CMT22Geography90        
    DMT22Geography48        
    EMT22Geography61        
    FMT22Geography68        
    GMT22Geography40        
    HMT22Geography83        
    AMT22History79        
    BMT22History68        
    CMT22History82        
    DMT22History32        
    EMT22History79        
    FMT22History66        
    GMT22History21        
    HMT22History63        
    AMT22Physics71        
    BMT22Physics71        
    CMT22Physics86        
    DMT22Physics31        
    EMT22Physics62        
    FMT22Physics50        
    GMT22Physics41        
    HMT22Physics60        
    AMT22Religious Studies86        
    BMT22Religious Studies77        
    CMT22Religious Studies80        
    DMT22Religious Studies28        
    EMT22Religious Studies55        
    FMT22Religious Studies53        
    GMT22Religious Studies32        
    HMT22Religious Studies73        
    AMT22Spanish86        
    BMT22Spanish68        
    CMT22Spanish56        
    DMT22Spanish64        
    EMT22Spanish86        
    FMT22Spanish76        
    GMT22Spanish56        
    HMT22Spanish38        

     

    Hi Fowmy Is this what you mean? I have trimmed it down.

     

    I have created a card easily enough to simply display one pupil's results average using slicers and filters.

     

    I would like BI to tell me what quartile that average sits in based on the all the individual averages in the group. The table on the left is the raw data, the two smaller tables I calculated.

    • Fowmy's avatar
      Fowmy
      Super User

      Pharms 

      Please find attached the file with the expected outcome:

      Quartile = 
      
      VAR __Avg = [Student Average]
      VAR __Q1  =  PERCENTILEX.EXC( ALLSELECTED( 'Table'[Pupil]) , [Student Average] , 0.25  )
      VAR __Q2  =  PERCENTILEX.EXC( ALLSELECTED( 'Table'[Pupil]) , [Student Average] , 0.50  )
      VAR __Q3  =  PERCENTILEX.EXC( ALLSELECTED( 'Table'[Pupil]) , [Student Average] , 0.75  )
      RETURN
          SWITCH(
              TRUE(),
              __Avg > 0 && __Avg <= __Q1 , "Q1",
              __Avg > 0 && __Avg <= __Q2, "Q2",
              __Avg > 0 && __Avg <= __Q3 , "Q3",
               "Q4"
          )