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 September 15. Request your voucher.

Reply
graceweii
Frequent Visitor

Average not calculating correctly in matrix (DAX)

Hi everyone, 

 

This may be a little complicated to explain, but I will try my best to explain it clearly. 

 

I need to calculate the average Cost per KG (C/KG) for the year 2021. C/KG is calculated by (Value Received USD / Received KGs ). 

 

As you can see in the picture below, the average is not calculating correctly. (12+22+22)/3 = 18.67, should not be 14.86, which is what Power BI currently shows. 

 

These are the two items that I created to calculate the C/KG X: 

 

C/KG = DIVIDE(MPLINE[Value Received USD],MPLINE[Received KGs],BLANK())
C/KG X = AVERAGEX(VALUES(MPLINE[ItemNrDel]),CALCULATE(AVERAGE(MPLINE[C/KG])))

 

 

 

image.png

 

Please let me know how I can fix this issue!

 

Best, 

Grace

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

Does this measure work?

C/KG new = If(hasonevalue(MPLINE[ItemNrDel]),[C/KG],AVERAGEX(VALUES(MPLINE[ItemNrDel]),[C/KG]))

Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish, thank you for your help! Unfortunately this is still givnig the same result. 

 

graceweii_0-1659454425658.png

I'm really lost... Please let me know if I should provide more information

Hi,

Share the download link of the PBI file.  Also, show the expected result very clearly.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
lbendlin
Super User
Super User

Assuming that you want this to be measures you need to use aggregation functions like SUM()  in your code. Otherwise this will be computed on row level.

 

Please provide sanitized sample data that fully covers your issue. I cannot help you without usable sample data.
Please paste the data into a table in your post or use one of the file services like OneDrive or Google Drive. I cannot use screenshots of your source data.
Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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