Forum Discussion
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:
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
- danextianSuper 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:
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/445133