Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Distinct count for every customer row

Hi, I have two tables: DimSubjects (dimension) where I have all the customer and a FactSales (fact table) where I have sales transaction. They are related by a subject key (one to many) and I display...
  • daxer-almighty's avatar
    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