Forum Discussion
Distinct Count but exclude if total is 0?
Hi,
I'm looking to get the distinct count of customers by month from my dataset but want to not count it if the sum of the totals for a customer is zero. Sample data below. Customer A has 50 and -50 both in Month 1 for a net total of 0. If I drop the data into a matrix table, the total distinct count will be 4 since customer A shows up. Is there a way to get around it so that distinct count will just be 3?
| Customer | Month | Amount |
| A | 1 | 50 |
| A | 1 | -50 |
| A | 3 | 100 |
| B | 1 | 68 |
| C | 1 | 61 |
| D | 1 | 12 |
| A | 4 | 13 |
| B | 5 | 16 |
| C | 3 | 73 |
| D | 4 | 22 |
| D | 4 | 62 |
| C | 5 | 21 |
| B | 2 | 30 |
Thanks
Hi,
These measures work
Total = SUM(Data[Amount])Measure = countrows(FILTER(VALUES(Data[Customer]),[Total]>0))Hope this helps.
3 Replies
- VahidDM
Super User
Hi loafers
Try this measure:
Measure = VAR _Count = COUNTA ( 'Table'[Customer] ) VAR _Zero_Month_Count = COUNTROWS ( FILTER ( SUMMARIZE ( 'Table', 'Table'[Customer], 'Table'[Month], "Sum Month", SUM ( 'Table'[Amount] ) ), [Sum Month] = 0 ) ) RETURN _Count - _Zero_Month_CountOutput:
If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn | Twitter | Blog | YouTube
FIFA World Cup - Medal Records - Ashish_Mathur
Super User
Hi,
These measures work
Total = SUM(Data[Amount])Measure = countrows(FILTER(VALUES(Data[Customer]),[Total]>0))Hope this helps.
- v-yalanwu-msft
Community Support
Hi, loafers ;
You could create measures as follow:
sum = CALCULATE( SUM('Table'[Amount]),FILTER(ALLSELECTED('Table'),[Customer]=MAX('Table'[Customer])))count = CALCULATE(DISTINCTCOUNT('Table'[Customer]),FILTER('Table',[sum]<>0))The final output is shown below:
Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.