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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Filtering Aggregrate for Distinct Count

Hi All,

For a single month, I can calculate the distinct count of customers with positive volume with the following measure:

Dist Mth =
CALCULATE (
DISTINCTCOUNT ( Facts[Customer CompKey] ),
Facts[Quantity (L)] > 0
)

For the equivalent quarter calculation I have hit a snag...

Dist Qtr =
CALCULATE (
DISTINCTCOUNT ( Facts[Customer CompKey] ),
Facts[Quantity (L)] > 0    //This needs done at the aggregate level i.e. SUM(Facts[Quantity (L)]) > 0
ALL(Period),
DATESINPERIOD ( Period[Calendar Date].[Date], LASTDATE ( Period[Calendar Date] ), -3, MONTH )
)
 
The calculation returns the correct result 99% of the time.
The issue occurs when there is positve volume in a month but the quarter is <= 0.
i.e.
Month 1    100   This row is counted
Month 2   -100   This row is excluded
Month 3        0   This row is excluded
Quarter         0   The aggregate is incorrectly reporting 1 from Month 1 instead of the correct value of 0

Any suggestions on how to filter based on an aggregate most welcome!
 
Cheers, Steve
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Try like

Dist Qtr =
CALCULATE (
countx(filter(values ( Facts[Customer CompKey] ),calculate(sum(Facts[Quantity (L)])) > 0),[Customer CompKey]),
//This needs done at the aggregate level i.e. SUM(Facts[Quantity (L)]) > 0
ALL(Period),
DATESINPERIOD ( Period[Calendar Date].[Date], LASTDATE ( Period[Calendar Date] ), -3, MONTH )
)

 

 

View solution in original post

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

Could you show me your data model? Please share a sample with me by your Onedrive for Business. And you can show me the result want. This will make it easier for me to understand your requirement.

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

amitchandak
Super User
Super User

@Anonymous , Try like

Dist Qtr =
CALCULATE (
countx(filter(values ( Facts[Customer CompKey] ),calculate(sum(Facts[Quantity (L)])) > 0),[Customer CompKey]),
//This needs done at the aggregate level i.e. SUM(Facts[Quantity (L)]) > 0
ALL(Period),
DATESINPERIOD ( Period[Calendar Date].[Date], LASTDATE ( Period[Calendar Date] ), -3, MONTH )
)

 

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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