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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
dskrobowski
Helper I
Helper I

Sequence of Applied Filter Context in SUMMARIZECOLUMNS

Hello, I'm struggling to understand the order of operations for how filters are being applied by SUMMARIZECOLUMNS. From the content in the DGTD, we're given the idea that the behavior of SUMMARIZECOLUMNS in how it applies the FilterTable argument is somewhat similar to how CALCULATE works. However, I haven't seen any delineated sequence of behavior for how filters are applied, like what we have for CALCULATE.

 

An example based on Contoso is below and can be run in dax.do. Specifically, in "Sales with Calculate" below, it seems that, in the first row of the resulting table, CALCULATE's context transition is causing "Red" & "White" to overwrite "Red" in Product[Color]. This is a familiar concern especially when working with arbitrarily shaped sets. However, I'm struggling to understand how VALUES ( Product[Color] ) is able to see both colors in the context, given that the GroupBy_ColumnName only contains one color per row and also given the fact that the similar clause ( VALUES ( Product[Color] ) ) in "Sales Amount" apparently only retrieves one color per row.

 

What am I missing? Any tips are greatly appreciated!

 

Thanks. 🙂

 

// This is the query I'm struggling with.

EVALUATE
SUMMARIZECOLUMNS (
    'Product'[Color],
    TREATAS (
        { ( "CY 2008", "Red" ), ( "CY 2007", "White" ) },
        'Date'[Calendar Year],
        'Product'[Color]
    ),
    "Sales Amount",
        SUMX (
            VALUES ( Product[Color] ),
            SUMX ( 'Sales', Sales[Net Price] * Sales[Quantity] )
        ),
    "Sales With Calculate",
        SUMX (
            VALUES ( Product[Color] ),
            CALCULATE ( SUMX ( 'Sales', Sales[Net Price] * Sales[Quantity] ) )
        )
)
ORDER BY [Sales Amount] DESC


// This query for reference to see the values being combined

EVALUATE
SUMMARIZECOLUMNS (
    'Product'[Color],
    'Date'[Calendar Year],
    TREATAS ( { "CY 2008", "CY 2007" }, 'Date'[Calendar Year] ),
    TREATAS ( { "Red", "White" }, 'Product'[Color] ),
    "Sales Amount",
        SUMX (
            VALUES ( Product[Color] ),
            SUMX ( 'Sales', Sales[Net Price] * Sales[Quantity] )
        ),
    "Sales with Calculate",
        SUMX (
            VALUES ( Product[Color] ),
            CALCULATE ( SUMX ( 'Sales', Sales[Net Price] * Sales[Quantity] ) )
        )
)

 

1 ACCEPTED SOLUTION
dskrobowski
Helper I
Helper I

Per Alberto Ferrari, the behavior observed and described here is due to a bug in the optimizer. See the comments on the page here.

View solution in original post

7 REPLIES 7
dskrobowski
Helper I
Helper I

Per Alberto Ferrari, the behavior observed and described here is due to a bug in the optimizer. See the comments on the page here.

johnt75
Super User
Super User

SQLBI have a great video explaining this - https://www.youtube.com/watch?v=bGVLguWf4Ls . 

If you use KEEPFILTERS you get the correct result

EVALUATE
SUMMARIZECOLUMNS (
    'Product'[Color],
    TREATAS (
        { ( "CY 2008", "Red" ), ( "CY 2007", "White" ) },
        'Date'[Calendar Year],
        'Product'[Color]
    ),
    "Sales Amount",
        SUMX (
            VALUES ( Product[Color] ),
            SUMX ( 'Sales', Sales[Net Price] * Sales[Quantity] )
        ),
    "Sales With Calculate",
        SUMX (
            VALUES ( Product[Color] ),
            CALCULATE ( SUMX ( 'Sales', Sales[Net Price] * Sales[Quantity] ) )
        ),
    "Sales With Calculate KEEP",
        SUMX (
            KEEPFILTERS(VALUES ( Product[Color] ) ),
            CALCULATE ( SUMX ( 'Sales', Sales[Net Price] * Sales[Quantity] ) )
        )
)
ORDER BY [Sales Amount] DESC

@marcorusso, any insight you can provide? 🙂

Thanks John, yes, that's a great video. However, my question is about how SUMMARIZECOLUMNS is creating the values we see.

 

I can't explain how we can get "Sales with Calculate," and that's what I'm trying to understand.

 

Thanks.

I think its the same as in the video. When the White row is being evaluated the filter context contains 2007 and white. Somehow, and I can't quite put my finger on how, applying VALUES is overriding the white part of the filter context with both white and red, but it is leaving 2007 in the filter context, so the numbers shown are the values for white & red in 2007. Similarly, for red the values shown are for white and red in 2008.

I can't quite get how VALUES is getting the outer filter context, containing white & red, when white alone is in the filter context.

Yes, somehow, the presence of CALCULATE seems to be inflencing what VALUES can see in the context (I don't think that's what's happening, but that's just how it looks.). This is wha I can't wrap my head around.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.

Top Solution Authors