Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Discrete Count Buckets Based on Averages

I am trying to categorize students based on score averages in Power BI but have run into lots of issues. I would like be able to categorize the averages into buckets depending on what filters are applied to the date through slicers. For example, if I filter on two months I would like the results to be bucketed based on the average of the two months.

Here is a sample of the data I will be using:

Date    Score   Student Category
Jan-20  0.8     Jim     Above 80
Feb-20  0.75    Jim     Below 80
Mar-20  0.7     Jim     Below 80
Jan-21 0.85 Jim Above 80 Feb-21 0.60 Jim Below 80 Mar-21 0.79 Jim Below 80 Jan-20 0.9 Andrea Above 80 Feb-20 0.95 Andrea Above 80 Mar-20 0.92 Andrea Above 80 Jan-20 0.6 Max Below 80 Feb-20 0.65 Max Below 80 Mar-20 0.7 Max Below 80

I would like to be able to show how many students fall into the above 80 and below 80 scorecards depending on what filter i choose. For example, if i filtered on jan and feb 2020, it would show 2 students below 80 and 1 student above 80. If I only filtered on Jan 2020, it would show 2 students above 80 and 1 below 80.

I was able to create a solution that only works for one year using SUMMARIZECOLUMNS and then doing a filtered count of these columns, however this breaks down once I have more than one year. 

 

Scores Above 80 =
COUNTROWS(
FILTER(
SUMMARIZECOLUMNS(
'Table'[Student],
'Table'[Date of call].[Year],
"Avg Score", AVERAGE('Table'[Score])
),[Avg Score]>0.80
))
 
If I remove the time column, it doesn't interact with the slicers properly and keeps breaking

 

Scores Above 80 =
COUNTROWS(
FILTER(
SUMMARIZECOLUMNS(
'Table'[Student],
"Average",AVERAGE('Table'[Score])
),[Average] > 0.80
))
 
Perhaps there is a much easier way of approaching this, but I'm stuck with my answer. Any help would be greatly appreciated
  • Anonymous solution attached, there are few other tables in the model, just ignore those. Look at the score and date table. 

     

    Also in sample data, I used the year 2021 instead of 2020 but the logic is the same.

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    ⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡

8 Replies

  • Anonymous solution attached, there are few other tables in the model, just ignore those. Look at the score and date table. 

     

    Also in sample data, I used the year 2021 instead of 2020 but the logic is the same.

     

    Check my latest blog post Year-2020, Pandemic, Power BI and Beyond to get a summary of my favourite Power BI feature releases in 2020

    I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

    ⚡Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.⚡

  • Anonymous Yes remove time will break the segmentation but let me first understand your data.  the score is a column or a measure? 

    • Anonymous's avatar
      Anonymous
      Not applicable

      hI parry2k sorry for not being clearer. I'm trying to create a measure that calculates the distinct counts that belongs to the scoring cut-offs. I have the column in my current table that has a score for each test (which can happen at various time-intervals), and I want the measure to dynamically interact with the time intervals selected by the user.

  • m3tr01d's avatar
    m3tr01d
    Icon for Continued Contributor rankContinued Contributor

    Anonymous 
    You can try this measure instead 

    Scores Above 80 = 
    COUNTROWS(
        FILTER(
            VALUES( 'Data'[Student] ),
            CALCULATE( AVERAGE( Data[Score] ) ) > 0.8
        )
    )
    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks m3tr01d I think the challenge is that I need some kind of distinct count. I originally had something similar to your suggestion but it tends to over-count students. Appreciate the suggestion

  • Anonymous's avatar
    Anonymous
    Not applicable

    Thank you parry2k ! The use of a variable for comparison worked great!

     

    Posting the Dax for anyone curious:

     

    Scores Above 80 =
    VAR _above = 0.8
    RETURN
    SUMX(
    SUMMARIZE(
    VALUES('Table'[Student]),
    'Table'[Student],
    "__avg", AVERAGE( 'Table'[Score])
    ),
    IF ( [__avg] > _above, 1)
    )
  • Anonymous Yes, I like to use variables where possible, especially static values, it is easy to change in case you want to replace it instead of making the changes in the DAX. If you want to take it to next level, you can easily use the what-if parameter and change the value of this variable with the what-if value and everything should work.

     

    I always look for scalable, easy to manage code.