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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Michael1
Advocate II
Advocate II

Calculating a Weighted Performance using DAX

Hello Power BI Community,

 

I am trying to calculate a weighted measure where the result is a single value.

 

This is student assessment data where there are four possible levels that a student might have achieved (beginning, devloping, proficient or distinguished) where each of these levels needs to be weighted (beginning=0, developing=0.5, proficient=1.0, distinguished=1.5).

 

To accomplish this (without DAX), I simply determine the number of students at each level and then multiply them by the value (above) and lastly divide by the number of students assessed.

 

To complicate this formula--I have duplicate records, so I need to filter by performance level and by a distinct Student ID.

 

If you are willing, please take a look at the code below and offer suggestions.

 

Bmk 2 Retest 4 5 ES Weighted Performance =
VAR Beginning =
    CALCULATE (
        COUNTROWS ( 'Bmk 2 Retest 4 5 ES' ),
        FILTER ( 'Bmk 2 Retest 4 5 ES', DISTINCT ( 'Bmk 2 Retest 4 5 ES'[StudentID] ) ),
        FILTER (
            'Bmk 2 Retest 4 5 ES',
            'Bmk 2 Retest 4 5 ES'[performance_level] = "Beginning"
        )
    )
VAR Developing =
    CALCULATE (
        COUNTROWS ( 'Bmk 2 Retest 4 5 ES' ),
        FILTER ( 'Bmk 2 Retest 4 5 ES', DISTINCT ( 'Bmk 2 Retest 4 5 ES'[StudentID] ) ),
        FILTER (
            'Bmk 2 Retest 4 5 ES',
            'Bmk 2 Retest 4 5 ES'[performance_level] = "Developing"
        )
    )
VAR Proficient =
    CALCULATE (
        COUNTROWS ( 'Bmk 2 Retest 4 5 ES' ),
        FILTER ( 'Bmk 2 Retest 4 5 ES', DISTINCT ( 'Bmk 2 Retest 4 5 ES'[StudentID] ) ),
        FILTER (
            'Bmk 2 Retest 4 5 ES',
            'Bmk 2 Retest 4 5 ES'[performance_level] = "Proficient"
        )
    )
VAR Distinguished =
    CALCULATE (
        COUNTROWS ( 'Bmk 2 Retest 4 5 ES' ),
        FILTER ( 'Bmk 2 Retest 4 5 ES', DISTINCT ( 'Bmk 2 Retest 4 5 ES'[StudentID] ) ),
        FILTER (
            'Bmk 2 Retest 4 5 ES',
            'Bmk 2 Retest 4 5 ES'[performance_level] = "Distinguished"
        )
    )
VAR NumberAssessed =
    CALCULATE (
        COUNTROWS ( 'Bmk 2 Retest 4 5 ES' ),
        FILTER ( 'Bmk 2 Retest 4 5 ES', DISTINCT ( 'Bmk 2 Retest 4 5 ES'[StudentID] ) )
    )
RETURN
    CALCULATE (
        ( ( beginning * 0 )
            + ( developing * 0.5 )
            + ( proficient * 1.0 )
            + ( distinguished * 1.5 ) )
            / NumberAssessed
    )

 

When I try to display the measure in a Card I receive this error:

couldn't load data.png

 

Your help is greatly appreciated,

 

Michael

1 ACCEPTED SOLUTION
Mi2n
Microsoft Employee
Microsoft Employee

Instead of trying to use Distinct() within in the Filter() function, can you try to use it directly inside the Countrows() function like,

 

COUNTROWS ( DISTINCT ( 'Bmk 2 Retest 4 5 ES'[StudentID] ))

 

Let me know if this helps.

 

Oh, and why do you even calculate the value for Beginning if it is gonna be multiplied with zero ? Smiley Wink 

View solution in original post

5 REPLIES 5
Mi2n
Microsoft Employee
Microsoft Employee

Instead of trying to use Distinct() within in the Filter() function, can you try to use it directly inside the Countrows() function like,

 

COUNTROWS ( DISTINCT ( 'Bmk 2 Retest 4 5 ES'[StudentID] ))

 

Let me know if this helps.

 

Oh, and why do you even calculate the value for Beginning if it is gonna be multiplied with zero ? Smiley Wink 

This works great!  Thank you.

Mi2n
Microsoft Employee
Microsoft Employee

Just a small update. Instead of both the CountRows() and Distinct() function, the single Countdistinct() function will also work. 

DISTINCTCOUNT works great!  Thanks -- I guess I just needed to switch the way I was trying to think about this.

 

Thank you again :)!

Mi2n
Microsoft Employee
Microsoft Employee

Oops! forgot the function name. Smiley Embarassed

 

Good that you got it anyway.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.