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
Anonymous
Not applicable

Calculate ignores outer Filter context

Hi There,

 

After searching "running total" and "filter context" I couldn't find something that matches my question (in a reasonable time).

 

My base Idea was to compute a running total in DAX. I have a fact table 

SvenG_0-1624619437615.png

and a calendar table (marked as such)

SvenG_1-1624619464430.png

The "is_this_year" flag marks the current year (2021) with 1, otherwise 0. So the dates start in early 2019.

 

The setup is as follows: I have a page-level filter on "is_this_year":

SvenG_2-1624619571882.png

and I wrote the following Measure:

theMeasure = 
   VAR cur_max = MAX ( 'Calendar'[Date] )
   RETURN
      CALCULATE ( MIN ( 'Calendar'[Date] ), 'Calendar'[Date] <= cur_max )
Because of the Page-level filter I assument that I would get 1.1.2021 for every row but instead I get this:
SvenG_3-1624619742157.png

This lookes like the page-level filter is ignored.

 

My reasoning here is that in the DAX generated in Power BI I get a filter on Calendar[is_this_year] which is essentially a table

is_this_year
1
 
In the measure itself I modify the filter context and add a filter on the [Date] Column of the calendar table. My understanding of filter contexts was that, because those filters are applied on different columns they should exist side by side, meaning we have the following filters in the final filter context:
  • [is_this_year] = 1
  • [Date] <= 5.5.2021 (for example)

So I would expect to get a row like this:

DateThe measure
05.05.202101.01.2021

But I we can see in the picture above I get 03.01.2019 as a measure value.

 

Can someone help me understand this?

 

example file here:

https://1drv.ms/u/s!AtFejN9ixXnChShZpu7MiEgoXVw5?e=ZCdERm

 

Thank You!

 

3 REPLIES 3
Fowmy
Super User
Super User

@Anonymous 

I modified your measure, DAX works on the column-based engine (VertiPaq) , you have set a report level filter but  inside your measure, you modify the context with calculate, so you need to apply the external filters

theMeasure = 
VAR cur_max = MAX ( 'Calendar'[Date] )
RETURN
    CALCULATE ( MIN ( 'Calendar'[Date] ),  'Calendar'[Date] <= cur_max, VALUES('Calendar'[is_this_year]) )

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Anonymous
Not applicable

thanks for your answer. But I still do not grasp it completly. Shouldn't the report level filter be used to modify the context in DAX? In the end everything is put into a SUMMARIZECOLUMS and the report level filter is applied via a TREATAS.

 

So is my Measure / the CALCULATE not using that context?

 

Perhaps you could clarify that 🙂 

 

Thanks, Sven

amitchandak
Super User
Super User

@Anonymous , use filter. Because without filter in calculate, it as good as using .

 

theMeasure = VAR cur_max =
            MAXX (ALLSELECTED( 'Calendar'),[Date] )
        RETURN
            CALCULATE ( MIN ( 'Calendar'[Date] ), filter(ALLSELECTED('Calendar'), 'Calendar'[Date] <= cur_max ))

 

refer

http://dataap.org/blog/2019/04/22/difference-between-calculate-with-and-without-filter-expression/

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.