Forum Discussion
Calculating a percentage within a distinct count
- 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,
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,
- fionabee1 year ago
Helper I
Hello, this seems to work perfectly! Final question, could you please show me how to write the same for when the status field is blank? So in my visual I can show a % of how many are outstanding?