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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply
harshadrokade
Post Partisan
Post Partisan

Average calculation

I Have below data.

I want to generate a column that will give me difference between below values for each Class-

  1. Average score of specific Class ( Like for CLass 1, average of Student A,B,C)
  2. Average score of all the Class (Average score of all the Class will be calculated based on the Average score generated for each Class & not base on avarage of all the students) (i.e. average of all class average generated as per above 1st item)

Student data table-

ClassStudentScore
1A2
1B3
1C4
2D1
2E2
3F5
3G3
3H5
3I2
4J3
4K1
4L3

 

2 ACCEPTED SOLUTIONS

That's really odd. 

can you create a new test measure same as above but without the difference.

 

Test Measure

VAR AverageAllClasses = 
	CALCULATE (
		[Average by Class],
		REMOVEFILTERS()
	)
		
RETURN AverageAllClasses

  Drop that into matrix as well and send results. 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

I've updated my demo file with the code I sent and it's working.

 

Do you want to have a look and see if you can spot what the difference is?

 

bcdobbs_0-1641836512509.png

Same link for demo 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

11 REPLIES 11
bcdobbs
Community Champion
Community Champion

I think you just need a measure like this:

Average by Class = 
    AVERAGEX (
        VALUES ( Result[Class] ),
        CALCULATE ( AVERAGE ( Result[Score] ) )
    )


VALUES ( Result[Class] ) creates a list of classes.
AVERAGEX then iterates over this list and calculates an AVERAGE for each.
The CALCULATE is needed as it forces a context transition so you only get an average for the current class.

 

You can then use the measure in a matrix visual which you can see in this demo.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

@bcdobbs Thanks sir. The card is showing 

 

Actually I am trying to add a column which will provide me the difference between average score by class & average of that class. I need a measure for the same.

 

Can you pls help me with the same which will provide me difference bewteen Average score of specific Class  & verage score by Class

Avg Difference = 

VAR AverageAllClasses = 
	CALCULATE (
		[Average by Class],
		REMOVEFILTERS()
	)
		
RETURN [Average by Class] - AverageAllClasses


Try this.

Add a matrix visual with classes on the rows and drop this into the values.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

THanks @bcdobbs Sir.

 

I tried this but it is giving me wrong values as below-

 

harshadrokade_0-1641831199198.png

 

The correct difference values after I manually deduct the average of class from average by class is as below.

 

harshadrokade_1-1641831358001.png

 

 

Can you drop average by class into the visual and also into a card and send screen shot?

 

(Or better send your pbix file)



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

HI @bcdobbs 

 

This is how it looks in table visual & also in card visual. I can't send pbix file as the organisation doesn;t allow uploads.. Thanks in advance.

 

harshadrokade_1-1641833913935.png

 

harshadrokade_2-1641833938741.png

 

 

 

That's really odd. 

can you create a new test measure same as above but without the difference.

 

Test Measure

VAR AverageAllClasses = 
	CALCULATE (
		[Average by Class],
		REMOVEFILTERS()
	)
		
RETURN AverageAllClasses

  Drop that into matrix as well and send results. 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

@bcdobbs 

 

I wrongly marked this as resolved but its not.

 

Now I see below results

harshadrokade_0-1641834930580.png

 

I'm out at the moment but will fire up the demo file when I get back. Something is very odd in terms of what is being displayed. Will be a few hours.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

@bcdobbs Thanks a lot sir for rea time help. No hurry. Reply when you have a moment. Thanks again

I've updated my demo file with the code I sent and it's working.

 

Do you want to have a look and see if you can spot what the difference is?

 

bcdobbs_0-1641836512509.png

Same link for demo 



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.