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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
POSPOS
Post Patron
Post Patron

Incorrect average using DAX

Hi All,

I have a requirement to show the avergae of data for different protocols. Please find sample date below:

POSPOS_1-1700084304885.png

 

Issue: When one protocol is selected, then the values for same statuses should be aggregated, but they are getting showing as average as I have selected average for no. of days.

POSPOS_2-1700084370977.png


Expected output is 6+19=25 but it is showing as average 25/2=12.50.

POSPOS_3-1700084477840.png


The values should be aggregated for same protocols that has same statuses and values should show as average for different protocols.

Overall:

POSPOS_4-1700086091878.png

When all the protocols are selected, the result should be  (4+6+19+1)/3=10 but it shows as 7.50


Could someone please sugest on how to achieve this using DAX.
Attaching sample pbix file here.

Thank you,

Poojitha

2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@POSPOS Try this:

Measure = 
  VAR __Protocols = COUNTROWS(DISTINCT('Table'[Protocol]))
  VAR __Sum = SUM('Table'[No. of days])
  VAR __Result = DIVIDE(__Sum, __Protocols)
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Ashish_Mathur
Super User
Super User

Hi,

Write these measures

D = SUM('Table (2)'[No. of days])
Measure = AVERAGEX(VALUES('Table (2)'[Protocol]),[D])

Drag the second one to the visual.

Hope this helps.

Ashish_Mathur_0-1700107274499.png

 


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

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Write these measures

D = SUM('Table (2)'[No. of days])
Measure = AVERAGEX(VALUES('Table (2)'[Protocol]),[D])

Drag the second one to the visual.

Hope this helps.

Ashish_Mathur_0-1700107274499.png

 


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

@Ashish_Mathur  - thank you for the response. this solution worked.

Greg_Deckler
Super User
Super User

@POSPOS Try this:

Measure = 
  VAR __Protocols = COUNTROWS(DISTINCT('Table'[Protocol]))
  VAR __Sum = SUM('Table'[No. of days])
  VAR __Result = DIVIDE(__Sum, __Protocols)
RETURN
  __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors
Top Kudoed Authors