Forum Discussion
Problem with count and distinctcount measure
Hi
I need a measure/calculated column that counts Red as distinctcount from the X column and the Blue as count from the Y column.
This is my data:
Color X Y
Red 1 200
Blue 1 200
Red 1 200
Blue 1 200
Red 1 200
I made a measure which gives me the right total number but not the right division of Red and Blue. So my matrix looks like this:
Number of Transactions
Red 6
Blue 6
Total 6
I want the matrix to look like this:
Number of Transactions
Red 1
Blue 5
Total 6
Thanks,
Robert
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a measure as below.
Re = SUMX( SUMMARIZE( 'Table', 'Table'[Color], "Result", IF( [Color]="Red", CALCULATE( DISTINCTCOUNT('Table'[X]), FILTER( ALL('Table'), 'Table'[Color]=EARLIER('Table'[Color]) ) ), COUNTROWS( ALL('Table') ) ) ), [Result] )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
4 Replies
- amitchandak
Super User
Anonymous , count(Table[y]) should give that. Looking at this data can not make much sense
- nvprasad
Solution Sage
Hi,
I hope you are taking colors from different tables and transactions from a different table. Please check whether these two tables having relationships or not.
Ideally, if it has relationships it should display expected results. Incase if you are having a chain of relationships then please make sure relationships are both directional.
Appreciate a Kudos! 🙂
If this helps and resolves the issue, please mark it as a Solution! 🙂Regards,
N V Durga Prasad - themistoklis
Community Champion
Anonymous
You can try the following measure:
Measure = SUMX ( Table_1, -- Table Name IF ( Table_1[Color] = "Red", CALCULATE(DISTINCTCOUNT ( Table_1[X] )), CALCULATE(COUNT ( Table_1[Y] )) ) ) - v-alq-msft
Community Support
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
You may create a measure as below.
Re = SUMX( SUMMARIZE( 'Table', 'Table'[Color], "Result", IF( [Color]="Red", CALCULATE( DISTINCTCOUNT('Table'[X]), FILTER( ALL('Table'), 'Table'[Color]=EARLIER('Table'[Color]) ) ), COUNTROWS( ALL('Table') ) ) ), [Result] )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.