Close Menu
AIToday7

    Subscribe to Updates

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

    What's Hot

    Zillow Launches Claude Connector for Listings, Tours, and Financing

    October 19, 2026

    Dream Labs Raises $90M Seed to Bring Robot AI Across Different Machines

    October 19, 2026

    Fal Debuts FLUX 3 Max Video Model Post-Trained With Black Forest Labs

    October 19, 2026
    Facebook X (Twitter) Instagram
    Trending
    • Zillow Launches Claude Connector for Listings, Tours, and Financing
    • Dream Labs Raises $90M Seed to Bring Robot AI Across Different Machines
    • Fal Debuts FLUX 3 Max Video Model Post-Trained With Black Forest Labs
    • Even Realities G2 review: Smart glasses, stupid controls
    • Nathan Fielder’s Surprise Call From Elizabeth Holmes: ‘I Trust You’
    • REG – Technology Minerals – Result of General Meeting
    • What’s the point of the 2.5G Ethernet port on your router?
    • Democrats think cracking down on AI could give them an edge
    Facebook X (Twitter) Instagram Pinterest Vimeo
    AIToday7
    • Home
    • AI News
    • Tech News
    • AI Guides
    • Chatbots
    • Cybersecurity
    • Gadgets
    • More
      • Generative AI
      • Startups
    AIToday7
    Home»AI Guides»How to Solve Issues When You Nest Measures While Overwriting the Same Filter
    AI Guides

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

    aitoday7By aitoday7September 30, 2026No Comments8 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.

    Base Query

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

    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)
    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
    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]                        )
    Figure 3 - The results of the measure after adding KEEPFILTERS() to get the distinct values instead of the sum of both colour
    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”.

    Figure 4 - Results for the new [SalesBlackWhiteGreen] measure. As you can see, the new measure returns the same result. (Figu
    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].

    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:

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

    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)
    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 Autho
    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:

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

    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 read

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

    How 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 read

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

    How 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.

    Post Views: 12

    Data Analysis Data Engineering Dax Power BI Power Bi Tutorials
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleHow Many Stories Can Your Data Tell?
    Next Article “We’re not going to shoot ourselves in the foot” over hack fallout, says OpenAI’s chief research officer
    aitoday7
    • Website

    Related Posts

    AI Guides

    Zillow Launches Claude Connector for Listings, Tours, and Financing

    October 19, 2026
    AI Guides

    Dream Labs Raises $90M Seed to Bring Robot AI Across Different Machines

    October 19, 2026
    AI Guides

    My Father’s Final Weeks Revealed Why Canadian Healthcare Needs AI

    October 18, 2026
    Add A Comment
    Leave A Reply Cancel Reply

    Top Posts

    Zillow Launches Claude Connector for Listings, Tours, and Financing

    October 19, 20260 Views

    Dream Labs Raises $90M Seed to Bring Robot AI Across Different Machines

    October 19, 20260 Views

    Fal Debuts FLUX 3 Max Video Model Post-Trained With Black Forest Labs

    October 19, 20260 Views
    Stay In Touch
    • Facebook
    • YouTube
    • TikTok
    • WhatsApp
    • Twitter
    • Instagram
    Latest Reviews
    Uncategorized

    Architecting memory and storage in the AI era

    aitoday7September 4, 2026
    Uncategorized

    Roland Releases Melody Flip, an AI Melody-Generation Plug-In for DAWs

    aitoday7September 4, 2026
    Uncategorized

    Home Depot Labor Day Sale (2026): BOGO on Best Grills and Tools

    aitoday7September 4, 2026

    Subscribe to Updates

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

    Most Popular

    Zillow Launches Claude Connector for Listings, Tours, and Financing

    October 19, 20260 Views

    Dream Labs Raises $90M Seed to Bring Robot AI Across Different Machines

    October 19, 20260 Views

    Fal Debuts FLUX 3 Max Video Model Post-Trained With Black Forest Labs

    October 19, 20260 Views
    Our Picks

    Architecting memory and storage in the AI era

    September 4, 2026

    Roland Releases Melody Flip, an AI Melody-Generation Plug-In for DAWs

    September 4, 2026

    Home Depot Labor Day Sale (2026): BOGO on Best Grills and Tools

    September 4, 2026

    Subscribe to Updates

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

    Facebook X (Twitter) Instagram Pinterest
    • About Us
    • Get In Touch
    • Disclaimer
    • Privacy Policy
    • Terms and Conditions
    © 2026 AIToday7. All Rights Reserved.

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