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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
shikharshah
Regular Visitor

Help understanding averagex with distinct count

I want to calculate the average items  per bill in a given dataset

From what I understand this formula:

 

Average lines per bill number = AVERAGEX(VALUES('20 Aug'[Bill No]),CALCULATE(DISTINCTCOUNT('20 Aug'[Item Name])))
 
It will create a table with the distinct bill no. then find the distinct item names per bill number and then it should find the average items per bill no.
 
This is not happening. It is returning total distinct items across the data set

From my research, I need to add a CALCULATE before the DISTINCTCOUNT formula. It is then correctly calculating average items per bill

Ask: Can someone help me understand WHY I need to put the CALCUALTE? From the documentation and tutorials I have seen, it should have calcualted the average items per bill without the calculate. Been trying to understand this for the past couple of hours. An explanation here will be really helpful!!
1 REPLY 1
danextian
Super User
Super User

hI @shikharshah ,

The measure could have been simplified as without using CALCULATE but it wouldn't work as expected. Using an external measure within  a DAX expression  automatically wraps that measure within CALCULATE  so

DistCount = DISTINCTCOUNT('table'[column]) is equivalent to CALCULATE([DistCount]). Not usingCALCULATE means the row context of VALUES('20 Aug'[Bill No]) is never converted to filter context so the same distinct count  is evaluvated for each unique item in Bill No.  Please see table below:

danextian_0-1693142141198.png

There is a more detailed explanation in a similar post - https://community.fabric.microsoft.com/t5/Desktop/Using-measure-or-Aggregation-in-AVERAGEX/m-p/44513... 

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.