Forum Discussion
ALLEXCEPT and ALL function does not work as I expected in DAX
It seems like you're dealing with a complex scenario in Power BI where you want to control which measures are affected by user selections. The ALLEXCEPT and ALL functions in DAX are powerful tools, but it might require some adjustments in your DAX formulas to achieve the desired behavior.
Without having access to the PBIX file and the specific data model, it can be challenging to provide an exact solution. However, I can offer some general guidance and suggestions based on the information you've provided:
Use of ALLEXCEPT: In your first measure, you are using ALLEXCEPT to remove filters on specific columns. Make sure that the dimensions you want to exclude are correctly specified. It's essential to understand the relationships between tables and dimensions in your model.
DAX MEASURE:
Test Appointment Qty =
CALCULATE(
SUM(Appointment[m_appointment_qty]),
ALLEXCEPT(
Appointment,
Appointment[dim_country_id],
Appointment[dim_country],
Appointment[dim_master_date],
Appointment[dim_service_category],
Appointment[dim_promise_met]
),
Appointment[table_type] = "Appointment",
Appointment[dim_calculation_type] = "Original"
)
Use of ALL: In your second measure, you are using ALL to remove filters on specific columns. Ensure that the columns you are excluding have the desired effect. Also, it's important to understand the context transition that happens in DAX calculations.
DAX MEASURE:
Test2 Appointment Qty =
CALCULATE(
SUM(Appointment[m_appointment_qty]),
ALL(
Appointment[data_flag],
Appointment[Availability],
Appointment[dim_day_diff],
Appointment[cleaner_id]
),
Appointment[table_type] = "Appointment",
Appointment[dim_calculation_type] = "Original"
)
Context Transition: Be aware of how context transition works in DAX. When you place a field in a table or visual, it can affect the context in which measures are evaluated. Ensure that the dimensions you are using in ALLEXCEPT and ALL are providing the correct context for your calculations.
Debugging: Use the DAX Studio or the Power BI Performance Analyzer to debug your DAX formulas. These tools can help you understand the impact of each filter on your measures.
If the issue persists, it might be helpful to see the actual data model and sample data to provide more specific assistance. You can try simplifying your DAX expressions and gradually adding complexity to identify where the issue arises. Additionally, consider using DAX variables to break down complex calculations into smaller, more manageable parts.