Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello,
I am creating a measure (expression at the very bottom of the post) to tell me the percentage of items that completed on time. To that end, I have a calculated column that is basically [# yes] / ([# yes] + [# no]. However when I put this intro a matrix visual to validate the answer, this is what I ended up with:
This confuses me because I thought that the measure would be calculated independently for each row, so I would end up with 100% on the 'Yes' row, and 0% on the 'No' and 'N/A' rows.
I am a relative newbie to Power BI and DAX, so I assume I'm just missing something here. Why does this not behave the way I think it should? What changes would need to be made to make it work that way?
Thanks for your help!
% Programs Completed On Time =
CALCULATE(
DISTINCTCOUNT('Table - PROGRAMS'[ID]),
&& 'Table - PROGRAMS'[PROGRAM_STATUS] = "Completed"
&& 'Table - PROGRAMS'[PROGRAM_COMPLETED_ON_TIME] = "Yes"
)
/
CALCULATE(
DISTINCTCOUNT('Table - PROGRAMS'[ID]),
&& 'Table - PROGRAMS'[PROGRAM_STATUS] = "Completed"
&& 'Table - PROGRAMS'[PROGRAM_COMPLETED_ON_TIME] IN {"Yes", "No"}
)
Solved! Go to Solution.
@pbiuser12345 It's because you are trying to use CALCULATE with a single table. That tends not to work. Ditch CALCULATE can go with COUNTROWS( DISTINCT( SELECTCOLUMNS( FILTER(...), ... ) ) )
@pbiuser12345 It's because you are trying to use CALCULATE with a single table. That tends not to work. Ditch CALCULATE can go with COUNTROWS( DISTINCT( SELECTCOLUMNS( FILTER(...), ... ) ) )
Thanks Greg, that put me on the right track. The below expression is working the way I would have expected.
I'm not sure I understand the 'why' of this though. Are you able to elaborate or point me to something that explains why CALCULATE is bad on a single table? Should I consider it best practice to reserve CALCULATE for measures that span multiple tables, and stick to more basic/fundamental functions for single table applications?
% Programs Completed On Time =
COUNTROWS(
FILTER(
'Table - PROGRAMS',
&& 'Table - PROGRAMS'[PROGRAM_STATUS] = "Completed"
&& 'Table - PROGRAMS'[PROGRAM_COMPLETED_ON_TIME] = "Yes"
)
)
/
COUNTROWS(
FILTER(
'Table - PROGRAMS',
&& 'Table - PROGRAMS'[PROGRAM_STATUS] = "Completed"
&& 'Table - PROGRAMS'[PROGRAM_COMPLETED_ON_TIME] IN {"Yes", "No"}
)
)
Have a read of this, which I think answers the "why". https://www.sqlbi.com/articles/the-importance-of-star-schemas-in-power-bi/
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
110 | |
91 | |
84 | |
66 |