Forum Discussion
Distinct count for every customer row
- 5 years ago
Hi Anonymous
I've created the measure but please remember next time not to change the names of the fields in the visual as this makes it really much harder to work with the model for a person that has not worked with the model. Nobody wants to spend time on deciphering step by step, painstakingly, which field belongs to which table.
Here's the measure but I can't guarantee it'll be fast:
The Count = var vCurrentSubjectID = DISTINCT( 'D - Subject'[Subject ID] ) var vResult = if( NOT ISEMPTY( 'F - Sales packing slip' ), CALCULATE( DISTINCTCOUNT( 'F - Sales packing slip'[Packing slip ID] ), 'D - Subject'[Subject ID] in vCurrentSubjectID, ALLSELECTED( 'F - Sales packing slip' ) ) ) return vResult
Here's your measure:
CALCULATE(
COUNTROWS( FactSales ),
REMOVEFILTERS( FactSales[Documentdo di transporto] )
)
Hi Anonymous , thanks for your reply.
Unfortunately your measure causes this to happen (the result rows are multiplied endlessly and the count is not correct, it should be 6):
In the SalesTable there are multiple lines for each Documento di trasporto. For example this Documento di trasporto has two lines:
so that's why for that Customer we have a count of 9 in total (it counts some documento di trasporto 2 times because they have two lines):