Forum Discussion

trdoan's avatar
trdoan
Helper III
7 years ago
Solved

Count Distinct from different tables + Find matching values

Hi everyone,   Here is my sample data.   The 3 sheets are my 3 tables where the "General Info" table has all Store Names and the other 2 tables have several Store Names which have 1-to-many relat...
  • MFelix's avatar
    7 years ago

    Hi trdoan,

     

    Create the following measures:

     

    Distintc Count Laboratory =
    IF (
        DISTINCTCOUNT ( NDT[Store] ) = BLANK ();
        0;
        DISTINCTCOUNT ( Laboratory[Store] )
    ) + 0
    
    
    
    Distintc Count NDT =
    IF (
        DISTINCTCOUNT ( Laboratory[Store] ) = BLANK ();
        0;
        DISTINCTCOUNT ( NDT[Store] )
    ) + 0
    
    
    
    NDT Alternatives Count =
    IF (
        CALCULATE ( COUNT ( NDT[NDT] ); ALLSELECTED ( NDT[NDT] ) ) <> 1;
        DISTINCTCOUNT ( NDT[Store] )
    )
    
    
    
    NDT No alternatives =
    IF (
        CALCULATE ( COUNT ( NDT[NDT] ); ALLSELECTED ( NDT[NDT] ) ) = 1;
        "No alternate Store can do : "
            & CONCATENATEX ( NDT; SELECTEDVALUE ( NDT[NDT] ); "," );
        "Alternative Stores: " & CONCATENATEX ( NDT; NDT[Store]; "," )
    )

     

    Check PBIX file attach.

     

    Regards,

    MFelix