Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
LupinAinsworth
Frequent Visitor

Unexpected DAX filtering behavior

Hi all, 

I wrote the following DAX to accomodate a client request: 

 

var Selection = ROUNDDOWN(SELECTEDVALUE('Forecast'[Period]), -2)
return
IF(MINX('Forecast', MIN('Forecast'[Period]))>=MIN('Date'[Fiscal YRMO]), CALCULATE(
[Actual]
, ALL('Scenario'[Scenario Description])
,FILTER( ALL('Forecast'[Period]), 'Forecast'[Period]=Selection)))

 

It works as expected for the request, however I am finding that when I bring in fields from other dimension tables only some of rows show up. I have no idea why because the way I read the dax, this shouldn't be happening (these are dimensions not written in this dax, so for example, a department table). Does anyone have any idea what's happening? What am I missing? I am so stumped. Thank you! 

 

 

 

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @LupinAinsworth 

 

Your issue with unexpected DAX filtering behavior, where only some rows from other dimension tables show up, might be related to the interaction between the measure and the context in which it is being used. Let's break down your DAX formula and see what could be causing the issue:

  1. Selection Variable:

    • ROUNDDOWN(SELECTEDVALUE('Forecast'[Period]), -2): This part is rounding down the selected forecast period to the nearest hundred. The -2 parameter in ROUNDDOWN seems unusual unless there's a specific reason for this based on your data.
  2. Condition and Calculation:

    • IF(MINX('Forecast', MIN('Forecast'[Period])) >= MIN('Date'[Fiscal YRMO]), ...): This checks if the minimum period in the 'Forecast' table is greater than or equal to the minimum fiscal year/month in the 'Date' table. If true, it calculates the measure [Actual].
  3. CALCULATE Function:

    • [Actual]: The actual measure being calculated.
    • ALL('Scenario'[Scenario Description]): Removes any filters on the 'Scenario Description' column.
    • FILTER(ALL('Forecast'[Period]), 'Forecast'[Period] = Selection): Applies a filter to include only the periods matching the 'Selection'.

Potential Issues and Considerations:

  1. Context Transition: When you bring in fields from other dimension tables (like 'Department'), the context changes. The measure is recalculated for each row of your visual, considering the filter context introduced by these new dimensions. If the relationship between these tables and your 'Forecast' or 'Date' tables isn't straightforward, it might lead to unexpected results.

  2. ALL Function: The use of ALL('Scenario'[Scenario Description]) and ALL('Forecast'[Period]) in your CALCULATE function clears filters on these fields. This might affect how the measure interacts with other dimensions if there are relationships or dependencies you haven't accounted for.

  3. Filter Context: The FILTER(ALL('Forecast'[Period]), 'Forecast'[Period] = Selection) may not be working as expected if 'Selection' does not match the granularity of the other dimensions you are bringing into your visual.

Suggestions for Troubleshooting:

  1. Examine Relationships: Check the relationships between your 'Forecast' table and other dimension tables. Ensure they are set up correctly.

  2. Test in Different Contexts: Test your measure by placing it in different visuals with various dimension combinations. This will help you understand how it behaves with different filter contexts.

  3. Debugging Step-by-Step: Break down your measure and test each part separately. For instance, first check what the 'Selection' variable returns, then test the IF condition, and so on.

  4. Review Data Model: Ensure that your data model is set up correctly, with appropriate relationships and granularity that matches the expectations of your measures.

If after these checks the issue still persists, you might need to provide more context or specific examples of where it fails to retrieve the expected results. This could be related to the specific data model, relationships between tables, or the granularity of the data.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

LinkedIn | Twitter | Blog | YouTube 

View solution in original post

1 REPLY 1
VahidDM
Super User
Super User

Hi @LupinAinsworth 

 

Your issue with unexpected DAX filtering behavior, where only some rows from other dimension tables show up, might be related to the interaction between the measure and the context in which it is being used. Let's break down your DAX formula and see what could be causing the issue:

  1. Selection Variable:

    • ROUNDDOWN(SELECTEDVALUE('Forecast'[Period]), -2): This part is rounding down the selected forecast period to the nearest hundred. The -2 parameter in ROUNDDOWN seems unusual unless there's a specific reason for this based on your data.
  2. Condition and Calculation:

    • IF(MINX('Forecast', MIN('Forecast'[Period])) >= MIN('Date'[Fiscal YRMO]), ...): This checks if the minimum period in the 'Forecast' table is greater than or equal to the minimum fiscal year/month in the 'Date' table. If true, it calculates the measure [Actual].
  3. CALCULATE Function:

    • [Actual]: The actual measure being calculated.
    • ALL('Scenario'[Scenario Description]): Removes any filters on the 'Scenario Description' column.
    • FILTER(ALL('Forecast'[Period]), 'Forecast'[Period] = Selection): Applies a filter to include only the periods matching the 'Selection'.

Potential Issues and Considerations:

  1. Context Transition: When you bring in fields from other dimension tables (like 'Department'), the context changes. The measure is recalculated for each row of your visual, considering the filter context introduced by these new dimensions. If the relationship between these tables and your 'Forecast' or 'Date' tables isn't straightforward, it might lead to unexpected results.

  2. ALL Function: The use of ALL('Scenario'[Scenario Description]) and ALL('Forecast'[Period]) in your CALCULATE function clears filters on these fields. This might affect how the measure interacts with other dimensions if there are relationships or dependencies you haven't accounted for.

  3. Filter Context: The FILTER(ALL('Forecast'[Period]), 'Forecast'[Period] = Selection) may not be working as expected if 'Selection' does not match the granularity of the other dimensions you are bringing into your visual.

Suggestions for Troubleshooting:

  1. Examine Relationships: Check the relationships between your 'Forecast' table and other dimension tables. Ensure they are set up correctly.

  2. Test in Different Contexts: Test your measure by placing it in different visuals with various dimension combinations. This will help you understand how it behaves with different filter contexts.

  3. Debugging Step-by-Step: Break down your measure and test each part separately. For instance, first check what the 'Selection' variable returns, then test the IF condition, and so on.

  4. Review Data Model: Ensure that your data model is set up correctly, with appropriate relationships and granularity that matches the expectations of your measures.

If after these checks the issue still persists, you might need to provide more context or specific examples of where it fails to retrieve the expected results. This could be related to the specific data model, relationships between tables, or the granularity of the data.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!! 

LinkedIn | Twitter | Blog | YouTube 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.