Forum Discussion

fionabee's avatar
fionabee
Icon for Helper I rankHelper I
1 year ago
Solved

Calculating a percentage within a distinct count

I'm currently using the following measure in a visual: CALCULATE(COUNT(Table1[Status]),Table1[Status]="Accepted")/[Number]   In this measure "Number" was originally a count of all case number...
  • DataNinja777's avatar
    1 year ago

    Hi fionabee ,

     

    To calculate the percentage of distinct cases that have at least one "Accepted" status, you need to shift from counting rows to identifying unique case IDs that meet your condition. Using a filtered table with CALCULATETABLE allows you to isolate the distinct case values where at least one row has a status of "Accepted." Then you divide that count by the total number of distinct cases to get the correct percentage.

    Accepted Case % =
    VAR AcceptedCases =
        CALCULATETABLE(
            VALUES(Table1[Case]),
            Table1[Status] = "Accepted"
        )
    RETURN
    DIVIDE(
        COUNTROWS(AcceptedCases),
        CALCULATE(DISTINCTCOUNT(Table1[Case]))
    )
    

    In this approach, AcceptedCases creates a virtual table of unique Case values where the status is "Accepted". COUNTROWS(AcceptedCases) gives the number of such cases, and the denominator uses CALCULATE(DISTINCTCOUNT(...)) to get the total number of distinct cases. This ensures that each case is only counted once, and only if it includes an accepted status. For your example, it returns 1 accepted case out of 3, or 33%.

     

    Best regards,