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.
Hi all,
I need help to write a DAX measure that will respond to cross-filtering. I'm developing a report for a hospital on their homeless patient population, and I'm trying to show the percent of appointments that were completed, canceled, and no-showed based on an [Appt Status] column. I have three different sets of measures, one for each possible status. Everything works fine until that column is cross-filtered. The measures for "Canceled" status are below:
Selected Appointments = COUNTROWS( 'Appointments' )
Canceled Appointments = CALCULATE( [Selected Appointments], Appointments[Appt Status] = "Canceled [3]" )
% Canceled = IF( [Selected Appointments] = 0, --If there are no appts in the denominator, BLANK(), --then display blank. DIVIDE( [Canceled Appointments], [Selected Appointments] ) + 0 --If there were some appts, but none were canceled, show 0.0%. )
The underlying data looks something like this:
In the table below, I summarize the % of appointments completed and canceled by department category. The bar chart shows the total number of appointments by status. When I click on the bar chart and cross-filter by "Canceled" status, the "Appts" column in the table is filtered, but "Completed Appts" and "Canceled Appts" (which come from my DAX measures) do not change. As a result, "% Completed" has a non-sensical result. How do I rewrite my measures so that they will respect the cross-filtering and evaluate to zero if a particular appointment status is not in the cross-filtered filter context?
Thanks in advance for your help!
Solved! Go to Solution.
Try adding a KEEPFILTERS to the CALCULATE:
Canceled Appointments = CALCULATE( [Selected Appointments], KEEPFILTERS(Appointments[Appt Status] = "Canceled [3]") )
This will respect other filters that are also flowing into the measure.
Hi @SQLguy
I recommend wrapping the Filter argument of CALCULATE in KEEPFILTERS.
Normally, the Filter arguments of CALCULATE overwrite existing filters, but using KEEPFILTERS modifies this behaviour so that they are intersected with existing filters.
For example, your Canceled Appointments measure would be:
Canceled Appointments = CALCULATE( [Selected Appointments], KEEPFILTERS ( Appointments[Appt Status] = "Canceled [3]" ) )
Regards,
Owen
Thank you very much, @OwenAuger and @jdbuchanan71! KEEPFILTERS solved the problem!
Try adding a KEEPFILTERS to the CALCULATE:
Canceled Appointments = CALCULATE( [Selected Appointments], KEEPFILTERS(Appointments[Appt Status] = "Canceled [3]") )
This will respect other filters that are also flowing into the measure.
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 |
---|---|
110 | |
95 | |
76 | |
65 | |
51 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |