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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.

Top Solution Authors