Close Menu
AI News TodayAI News Today

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Insight Is Still the Currency of Data Science

    Anthropic’s IPO pitch includes a warning about human extinction

    How to Solve Issues When You Nest Measures While Overwriting the Same Filter

    Facebook X (Twitter) Instagram
    • About Us
    • Contact Us
    Facebook X (Twitter) Instagram Pinterest Vimeo
    AI News TodayAI News Today
    • Home
    • AI News
    • AI Reviews
    • AI Tools
    • AI Tutorials
    • Chatbots
    • Free AI Tools
    • Artificial Intelligence
    AI News TodayAI News Today
    Home»AI Tools»How to Solve Issues When You Nest Measures While Overwriting the Same Filter
    AI Tools

    How to Solve Issues When You Nest Measures While Overwriting the Same Filter

    By No Comments7 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    How to Solve Issues When You Nest Measures While Overwriting the Same Filter
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Introduction

    We nest Measures all the time.

    Usually, I create a base measure with the aggregation and some base operation, like scaling.

    Afterwards, I create measures that apply filters or time intelligence operations based on that base measure.

    This is nothing new.

    But sometimes I have a measure that applies some filters, and I need another measure with a slightly different filter.

    In such cases, I prefer nesting the first measure and applying the additional filter.

    But what happens when I need to modify the same filter set in the nested measure?

    Let’s dig into it.

    Learn this step by step with the interactive Power BI roadmap.

    Base Query

    As usual, I’ll use DAX queries to show you the issue and a possible solution.

    So, here we are:

    DEFINE    VAR SelYear = TREATAS({ 2025 }, 'Date'[Year])        VAR SelCountry = TREATAS({ "Germany" }, Geography[RegionCountryName])        VAR SelColors = TREATAS({ "Black", "White", "Green" }, 'Product'[ColorName])EVALUATE    SUMMARIZECOLUMNS(Geography[CityName]                        ,'Date'[Year]                        ,'Product'[ColorName]                        ,SelYear                        ,SelCountry                        ,SelColors                        ,"Online Sales", [Sum Online Sales]                        )

    We will look at the Online Sales for Germany and for the colours “Black”, “White” and “Green”:

    Figure 1 – Result set from the base query (Figure by the Author)

    We will work with these numbers from now on.

    Next, I will create a measure to get the results for “Black” and “White” only:

    DEFINE    VAR SelYear = TREATAS({ 2025 }, 'Date'[Year])        VAR SelCountry = TREATAS({ "Germany" }, Geography[RegionCountryName])        VAR SelColors = TREATAS({ "Black", "White", "Green" }, 'Product'[ColorName])    MEASURE 'All Measures'[SalesBlackWhite] = CALCULATE([Sum Online Sales]                                        ,'Product'[ColorName] IN {"Black", "White"}                                        )                                        EVALUATE    SUMMARIZECOLUMNS(Geography[CityName]                        ,'Date'[Year]                        ,'Product'[ColorName]                        ,SelYear                        ,SelCountry                        ,SelColors                        ,"Online Sales", [Sum Online Sales]                        ,"Black and White Sales", [SalesBlackWhite]                        )

    The result of the measure [SalesBlackWhite] is the following:

    Figure 2 – These are the results of the measure [SalesBlackWhite]. As expected, the results are the same in every row, as the measure replaces the filter on each row. (Figure by the Author)

    Now it’s important to remember how DAX works when setting a filter on a column:

    It replaces any existing filter on the column.

    This means that the filter “forgets” that each row has a different colour and calculates the sum of both “Black” and “White”.

    One way of keeping the distinct values is to use KEEPFILTERS():

    DEFINE    VAR SelYear = TREATAS({ 2025 }, 'Date'[Year])        VAR SelCountry = TREATAS({ "Germany" }, Geography[RegionCountryName])        VAR SelColors = TREATAS({ "Black", "White", "Green" }, 'Product'[ColorName])    MEASURE 'All Measures'[SalesBlackWhite] = CALCULATE([Sum Online Sales]                                        ,KEEPFILTERS('Product'[ColorName] IN {"Black", "White"} )                                        )                                        EVALUATE    SUMMARIZECOLUMNS(Geography[CityName]                        ,'Date'[Year]                        ,'Product'[ColorName]                        ,SelYear                        ,SelCountry                        ,SelColors                        ,"Online Sales", [Sum Online Sales]                        ,"Black and White Sales", [SalesBlackWhite]                        )

    These are the results:

    Figure 3 – The results of the measure after adding KEEPFILTERS() to get the distinct values instead of the sum of both colours (Figure by the Author)

    The issue when nesting Measures

    Now, what happens when we create an additional measure, reuse the existing measure [SalesBlackWhite], and add another colour, “Green,” to the filter?

    DEFINE    VAR SelYear = TREATAS({ 2025 }, 'Date'[Year])        VAR SelCountry = TREATAS({ "Germany" }, Geography[RegionCountryName])        VAR SelColors = TREATAS({ "Black", "White", "Green" }, 'Product'[ColorName])    MEASURE 'All Measures'[SalesBlackWhite] = CALCULATE([Sum Online Sales]                                        ,'Product'[ColorName] IN {"Black", "White"}                                        )                                            MEASURE 'All Measures'[SalesBlackWhiteGreen] = CALCULATE([SalesBlackWhite]                                        ,'Product'[ColorName] IN {"Green"}                                        )                                        EVALUATE    SUMMARIZECOLUMNS(Geography[CityName]                        ,'Date'[Year]                        ,'Product'[ColorName]                        ,SelYear                        ,SelCountry                        ,SelColors                        ,"Online Sales", [Sum Online Sales]                        ,"Black and White Sales", [SalesBlackWhite]                        ,"Black, White and Green Sales", [SalesBlackWhiteGreen]                        )

    Now, I added a new measure [SalesBlackWhiteGreen].
    This measure reuses [SalesBlackWhite] but adds a filter for “Green”.

    This is the result:

    Figure 4 – Results for the new [SalesBlackWhiteGreen] measure. As you can see, the new measure returns the same result. (Figure by the Author)

    The new measure result is identical to the nested measure [SalesBlackWhite].

    Why?

    Based on the explanation above, the nested measure replaced the calling measure’s filter with Black and White.

    This approach didn’t work out as expected.

    Possible solutions

    What can we do to get the needed result:

    The Sales for “Black”, “White” and “Green” products?

    You can try using KEEPFILTERS() to retain an existing filter:

    DEFINE    VAR SelYear = TREATAS({ 2025 }, 'Date'[Year])        VAR SelCountry = TREATAS({ "Germany" }, Geography[RegionCountryName])        VAR SelColors = TREATAS({ "Black", "White", "Green" }, 'Product'[ColorName])    MEASURE 'All Measures'[SalesBlackWhite] = CALCULATE([Sum Online Sales]                                        ,KEEPFILTERS('Product'[ColorName] IN {"Black", "White"})                                        )                                            MEASURE 'All Measures'[SalesBlackWhiteGreen] = CALCULATE([SalesBlackWhite]                                        ,KEEPFILTERS('Product'[ColorName] IN {"Green"})                                        )                                        EVALUATE    SUMMARIZECOLUMNS(Geography[CityName]                        ,'Date'[Year]                        ,'Product'[ColorName]                        ,SelYear                        ,SelCountry                        ,SelColors                        ,"Online Sales", [Sum Online Sales]                        ,"Black and White Sales", [SalesBlackWhite]                        ,"Black, White and Green Sales", [SalesBlackWhiteGreen]                        )

    Again, the result is not as expected:

    Figure 5 – Results when using KEEPFILTER() in the Measures (Figure by the Author)

    This result is because of a filter conflict:

    • The outer measure filters the colour by “Green”

    • The nested measure keeps this filter and adds “Black” and “White”

    These colliding filters cause an empty result.

    Adding FILTER() instead of KEEPFILTERS() doesn’t change anything, as both produce the same result in this scenario.

    You can find related content to these two functions in the References section below.

    There are two ways of solving this issue.

    First, you write two measures that apply the filters independently, without nesting the other measure:

    DEFINE    VAR SelYear = TREATAS({ 2025 }, 'Date'[Year])        VAR SelCountry = TREATAS({ "Germany" }, Geography[RegionCountryName])        VAR SelColors = TREATAS({ "Black", "White", "Green" }, 'Product'[ColorName])    MEASURE 'All Measures'[SalesBlackWhite] = CALCULATE([Sum Online Sales]                                        ,'Product'[ColorName] IN {"Black", "White"}                                        )                                            MEASURE 'All Measures'[SalesBlackWhiteGreen] = CALCULATE([Sum Online Sales]                                        ,'Product'[ColorName] IN {"Black", "White", "Green"}                                        )                                        EVALUATE    SUMMARIZECOLUMNS(Geography[CityName]                        ,'Date'[Year]                        ,'Product'[ColorName]                        ,SelYear                        ,SelCountry                        ,SelColors                        ,"Online Sales", [Sum Online Sales]                        ,"Black and White Sales", [SalesBlackWhite]                        ,"Black, White and Green Sales", [SalesBlackWhiteGreen]                        )

    This time, the results are as expected:

    Figure 6 – Results with the two separate measures (Figure by the Author)

    The other way is to write a UDF to calculate the needed results.

    In the following case, I’ve added a parameter to switch between the two needed filters:

    fn_CalculateByColorFilter =        (FormulaExpr : EXPR         ,SwitchValue : NUMERIC VAL = 1)        =>        IF ( SwitchValue = 1                ,CALCULATE(FormulaExpr                            ,'Product'[ColorName] IN { "Black", "White" }                             )                ,CALCULATE(FormulaExpr                            ,'Product'[ColorName] IN { "Black", "White", "Green" }                            )                )

    Then, I can change the two measures to call the UDF:

    [SalesBlackWhite] = fn_CalculateByColorFilter([Sum Online Sales], 1)                                        [SalesBlackWhiteGreen] = fn_CalculateByColorFilter([Sum Online Sales], 2)

    The result is the same as before.

    But this function can be simplified:

    fn_CalculateByColorFilter =        (FormulaExpr : EXPR         ,SwitchValue : NUMERIC VAL = 1)        =>        CALCULATE(FormulaExpr                    ,IF ( SwitchValue = 1                            ,'Product'[ColorName] IN { "Black", "White" }                             ,'Product'[ColorName] IN { "Black", "White", "Green" }                        )                    )

    This doesn’t degrade performance, even though the IF() inside CALCULATE() doesn’t look optimal at first glance.

    When we look at the execution statistics, they don’t differ by much:

    Figure 7 – On the left, the first UDF and on the right, the simplified variant. The numbers don’t differ (Figure by the Author)

    As you can see, the numbers are almost identical.

    This is because both retrieve the same data from the data model and both use the same xSQL query.

    Here is what I extracted with DAX Studio:

    SET DC_KIND="AUTO";WITH    $Expr0 := (  ( PFCAST ( 'Online Sales'[UnitPrice] AS  INT )  PFCAST ( 'Online Sales'[SalesQuantity] AS  INT )  ) - PFCAST ( 'Online Sales'[DiscountAmount] AS  INT )  ) ,    $Expr1 := (  ( PFCAST ( 'Online Sales'[UnitPrice] AS  INT )  PFCAST ( 'Online Sales'[SalesQuantity] AS  INT )  ) - PFCAST ( 'Online Sales'[DiscountAmount] AS  INT )  ) ,    $Expr2 := (  ( PFCAST ( 'Online Sales'[UnitPrice] AS  INT ) * PFCAST ( 'Online Sales'[SalesQuantity] AS  INT )  ) - PFCAST ( 'Online Sales'[DiscountAmount] AS  INT )  ) SELECT    'Product'[ColorName],    'Geography'[CityName],    SUM ( @$Expr0 ),    SUM ( @$Expr1 ),    SUM ( @$Expr2 )FROM 'Online Sales'    LEFT OUTER JOIN 'Date'        ON 'Online Sales'[OrderDate]='Date'[DateKey]    LEFT OUTER JOIN 'Product'        ON 'Online Sales'[ProductKey]='Product'[ProductKey]    LEFT OUTER JOIN 'Store'        ON 'Online Sales'[StoreKey]='Store'[StoreKey]    LEFT OUTER JOIN 'Geography'        ON 'Store'[GeographyKey]='Geography'[GeographyKey]WHERE    'Date'[Year] = 2025 VAND    'Product'[ColorName] IN ( 'White', 'Black', 'Green' ) VAND    'Geography'[RegionCountryName] = 'Germany';

    As you can see, the engine retrieves a list for all three colours and compiles the result in the Formula engine.

    You can find more details on analysing DAX performance in the piece linked in the References section.

    Conclusion

    Understanding how filters are applied in DAX with the CALCULATE function is key to using nested measures.

    If you don’t get the expected result, remember how filters are applied; nested measures can overwrite the filter set by the calling measure.

    Try it with your data and different scenarios to see the effects.

    For example, it can be very confusing when your data model has a chain of tables with relationships between them.

    Then you must understand how filters move from one table to another to understand how the results are calculated.

    Now you can explain the results and change your code to get the expected results.

    References

    To learn more about KEEPFILTERS() and FILTER(), read these two pieces:

    Uncovering the secrets of KEEPFILTERS in DAXThe KEEPFILTERS() function in DAX is an underestimated function. Let’s go into the rabbit hole of this function and discover some secretsSalvatore Cagliari · 8 min readHow to use FILTER in DAX the correct wayThe FILTER() function in DAX can be challenging to tame. Here are some examples on how to use it and how not.Salvatore Cagliari · 11 min readHow to Get Performance Data from Power BI with DAX StudioSometimes we have a slow Report, and we need to figure out why. I will show you how to collect performance data and what these metrics mean.Salvatore Cagliari · 9 min read

    Like in my previous articles, I use the Contoso sample dataset. You can download the ContosoRetailDW Dataset for free from Microsoft here.

    The Contoso Data can be used freely under the MIT License, as described in this document.

    I updated the dataset to shift the data to contemporary dates and removed all tables not needed for this example.

    Filter issues Measures Nest Overwriting solve
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleAirbnb adds AI search, more social features
    Next Article Anthropic’s IPO pitch includes a warning about human extinction
    • Website

    Related Posts

    AI Tools

    Insight Is Still the Currency of Data Science

    AI Tools

    How to Clone a Voice With Coqui AI: A Hands-On Walkthrough for Real Projects

    AI Tools

    Towards Spec-Driven Test Automation: Part 2

    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Insight Is Still the Currency of Data Science

    0 Views

    Anthropic’s IPO pitch includes a warning about human extinction

    0 Views

    How to Solve Issues When You Nest Measures While Overwriting the Same Filter

    0 Views
    Stay In Touch
    • Facebook
    • YouTube
    • TikTok
    • WhatsApp
    • Twitter
    • Instagram
    Latest Reviews
    AI Tutorials

    Quantization from the ground up

    AI Tools

    David Sacks is done as AI czar — here’s what he’s doing instead

    AI Reviews

    Judge sides with Anthropic to temporarily block the Pentagon’s ban

    Subscribe to Updates

    Get the latest tech news from FooBar about tech, design and biz.

    Most Popular

    Insight Is Still the Currency of Data Science

    0 Views

    Anthropic’s IPO pitch includes a warning about human extinction

    0 Views

    How to Solve Issues When You Nest Measures While Overwriting the Same Filter

    0 Views
    Our Picks

    Quantization from the ground up

    David Sacks is done as AI czar — here’s what he’s doing instead

    Judge sides with Anthropic to temporarily block the Pentagon’s ban

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    Facebook X (Twitter) Instagram Pinterest
    • About Us
    • Contact Us
    • Terms & Conditions
    • Privacy Policy
    • Disclaimer

    © 2026 ainewstoday.co. All rights reserved. Designed by DD.

    Type above and press Enter to search. Press Esc to cancel.