Nested measures both modifying filter context

scottsen

Well-known Member
Joined
Mar 16, 2014
Messages
1,263
Hi Folks! My turn for a question :)

I would like to know if there is a consistent/knowable criteria for evaluating the order which filters get applied.

Example...

We have some base measure for "opportunity revenue" that calculates the revenue for all customers... That meet some criteria which is "date-sensitive". It is grabbing the last date in the filter context and using it to do a lookup in a profitability table to grab a [ProfitBucket] value... if that is "0" they are an "opportunity".

Code:
Opportunity_Revenue :=
CALCULATE (
    [Revenue],
    FILTER (
        Customers,
        CALCULATE (
            VALUES ( Profitability[ProfitBucket] ),
[COLOR="#FF0000"]            LASTDATE ( Calendar[Date] )[/COLOR]
        )  = 0
    )
)

However, if I now (naively?) write a measure that uses that base measure:
Code:
Opportunity_Revenue_YTD :=
CALCULATE (
    [[B]Opportunity_Revenue[/B]],
    VALUES ( Calendar[Year] ),
    FILTER (
        ALL ( Calendar ),
        Calendar[KW ID] <= [COLOR="#FF0000"]MAX ( Calendar[KW ID] )[/COLOR]
            && Calendar[KW ID] >= [First Week Id]
    )
)

It becomes... confusing.

Is the Calendar[Date] referred to in the base measure, the original filter context, or the one modified by the FILTER() in my 2nd measure?
or...
Is the Calendar[KW ID] referred to in the 2nd measure, or original filter context, or the one modified by the LASTDATE() in the 1st measure?

[Note: This was probably a dumb example cuz it might accidentally work... I should have used a PriorYear related measure, but I'm too lazy to fix it now, and the question is still valid'ish :)]
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
The Opportunity_Revenue_YTD measure sets a filter context to a set of dates between [First Week Id] and [KW ID], within the currently selected years.
Then it executes the Opportunity_Revenue measure within such a filter context, so for each customer the Profitability[ProfitBucket] is evaluated within the last day available in the set of dates defined in the previous filter context.
Does it make sense to you, now?
 
Upvote 0
Thanks, Marco.

Ya... what is weird is what you are telling me is that it expects "just like you would expect". Which is not what I expected ;)
 
Upvote 0
I was just making a joke... that I was trying to make it more complicated than it really was :)
 
Upvote 0

Forum statistics

Threads
1,224,115
Messages
6,176,466
Members
452,728
Latest member
mihael546

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top