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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Kelvin_Aurelio
New Member

Calculating correct Average

Hello everyone,

I have a table containing project ratings (scores) for each row.
Each project was rated multiple times, and the rows are not ordered by project.

It's similar to this:

 

ID RatingID ProjectScoreAverage expectedAverage calculated so far
132740,5847,61
2271.553,0847,61
3229.7553,0847,61
4129.2529,547,61
5350.540,5847,61

6

344.2540,5847,61
725853,0847,61
8126.7529,547,61

 

I'm struggling to calculate the score average for each project. I've already tried:

 

 

 

 

 

AVERAGE_Pj =
VAR Project = DISTINCT('Avaliações'[ID Project])
    RETURN
    AVERAGEX (
        Project,
        CALCULATE (
            AVERAGE ( 'Ratings'[final_score]),
            FILTER (
                'Ratings',
                'Ratings'[ID Project] = EARLIER ( 'Avaliações'[ID Project] )
        )
    )
)

 

 

 

But it seems it's calculating the average for the entire column.

 

What am I missing?

 

Thanks in advance.

2 ACCEPTED SOLUTIONS
mark_endicott
Super User
Super User

@Kelvin_Aurelio - As long as I understand what you're trying to do correctly, use this (just refit to your table name):

 

 

AVERAGEX( VALUES( 'Table'[ID Project] ), CALCULATE(AVERAGE( 'Table'[Score] ), REMOVEFILTERS( 'Table'[ID Rating]) ))

 

 

PBIX attached to show you my results are correct - your expected 29.5 for Project 1 is incorrect.

 

If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

View solution in original post

quantumudit
Super User
Super User

Hello @Kelvin_Aurelio 

You can use the following DAX to create a calculated column that will give you the correct average.

Average Actual =
AVERAGEX (
    FILTER ( 'Table', 'Table'[ID Project] = EARLIER ( 'Table'[ID Project] ) ),
    'Table'[Score]
)
Please note that based on your dataset, the project-1 average is 28

Here is the screenshot of the calculated column along with the DAX:

quantumudit_0-1740673578194.png

 

I am also attaching the Power BI file for your reference.

 

Best Regards,
Udit

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
Visit My Linktree: LinkTree

Proud to be a Super User

 

 

View solution in original post

6 REPLIES 6
quantumudit
Super User
Super User

Hello @Kelvin_Aurelio 

You can use the following DAX to create a calculated column that will give you the correct average.

Average Actual =
AVERAGEX (
    FILTER ( 'Table', 'Table'[ID Project] = EARLIER ( 'Table'[ID Project] ) ),
    'Table'[Score]
)
Please note that based on your dataset, the project-1 average is 28

Here is the screenshot of the calculated column along with the DAX:

quantumudit_0-1740673578194.png

 

I am also attaching the Power BI file for your reference.

 

Best Regards,
Udit

If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

🚀 Let's Connect: LinkedIn || YouTube || Medium || GitHub
Visit My Linktree: LinkTree

Proud to be a Super User

 

 

It worked here, thanks!

weiqb
Frequent Visitor

I think what you want is average.

you can add a new calculated column.

avg =
VAR _current = 'score'[ID Project]
VAR _avg =
    ROUND (
        AVERAGEX (
            FILTER (
                'score',
                'score'[ID Project] = _current
            ),
            'score'[Score]
        ),
        2
    )
RETURN
    _avg

mark_endicott
Super User
Super User

@Kelvin_Aurelio - As long as I understand what you're trying to do correctly, use this (just refit to your table name):

 

 

AVERAGEX( VALUES( 'Table'[ID Project] ), CALCULATE(AVERAGE( 'Table'[Score] ), REMOVEFILTERS( 'Table'[ID Rating]) ))

 

 

PBIX attached to show you my results are correct - your expected 29.5 for Project 1 is incorrect.

 

If I answered your question please mark my post as the solution, it helps others with the same challenge find the answer!

For some reason I got the same results as mine in the example.

But thanks for trying 🙂

@Kelvin_Aurelio - You need to use my solution in a measure not a calulated column. 

 

Measures are Dynamic (and therefore can be affected by filtering) and are more optimal than calculated columns because they do not create additional data in your model and they do not need to be recalculated at the point of a refresh. 

 

In the file I attached, you will have seen I used a measure. This is considered best practice, so you should think about using these more as you learn Power BI. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 NL Carousel

Fabric Community Update - February 2025

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