Forum Discussion
Count Distinct where sum is
I am trying to get a distinct count of values where the sum of values is not zero
Below I have a basic distinct count:
| Segment | Amount | var1 | var2 |
| A | 10 | example | random1 |
A | 1 | example 2 | random 2 |
| B | 0 | example 3 | random 3 |
| C | 1 | example 4 | random 4 |
| D | 2 | example 5 | random 5 |
| D | 2 | example 6 | random 6 |
Thanks for your suggestions all but strangely none worked with my dataset. I'm not sure if it's the size of the dataset or the fact that it is running through a direct query causing the issue.
To get around it I created an additional table from the main query using a combination of the CALCULATETABLE, SUMMARIZE and FILTER functions and put a count card visual pulling data from new table.
13 Replies
- AnonymousNot applicable
share some sample data and expected output.
- vanessafvgCommunity Champion
do you want a distinct count or row count? distinct count on segment will just count the segment?
- BI-BolaFrequent Visitor
Anonymous
Original post updated
I am after a distinct count of the segment column values where the sum of "Amount" is not equal to zero
- AnonymousNot applicable
Create measure
measure= Sumx(summerize(table,table[sagement],"Total",sum(table[Amount]),If(Total>0,1,0))
Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar
If I resolve your problem Mark it as a solution and give kudos.- BI-BolaFrequent Visitor
Doesn't seem to work, spelling of functions were corrected
MEASURE = SUMX(SUMMARIZE(AccountTransactions,AccountTransactions[Segment],"Total", SUM(AccountTransactions[Amount]),If(Total>0),1,0))error "The syntax for ')' is incorrect."- AnonymousNot applicable
it's my bad.
I forgot to close bracket.
measure= Sumx(summerize(table,table[sagement],"Total",sum(table[Amount])),If(Total>0,1,0))
Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar
If I resolve your problem Mark it as a solution and give kudos.
- V-lianl-msftCommunity Support
Hi BI-Bola ,
You can try the DAX below:
Measure = CALCULATE(COUNTROWS(DISTINCT('sample'[Segment])),FILTER('sample','sample'[Amount]<>0))Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. - BI-BolaFrequent Visitor
I have expanded the example table so that it is more in line with my dataset, apologies if it was unclear.
Thanks for the response but your formula does't seem to work for the updated table
- V-lianl-msftCommunity Support
Hi BI-Bola ,
After my test, I can get the expected results.
If my understanding is wrong, please share the result you expect.
Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.- AnonymousNot applicable
Hi BI-Bola
Heve you tried the solution which i suggested.
measure= Sumx(summerize(table,table[sagement],"Total",sum(table[Amount])),If(Total>0,1,0))
Thanks & regards,
Pravin Wattamwar
www.linkedin.com/in/pravin-p-wattamwar
If I resolve your problem Mark it as a solution and give kudos.
- BI-BolaFrequent Visitor
Thanks for your suggestions all but strangely none worked with my dataset. I'm not sure if it's the size of the dataset or the fact that it is running through a direct query causing the issue.
To get around it I created an additional table from the main query using a combination of the CALCULATETABLE, SUMMARIZE and FILTER functions and put a count card visual pulling data from new table.