Forum Discussion

Applicable88's avatar
Applicable88
Impactful Individual
4 years ago

Filtercontext in running total explained

Hello, 

I know its a common formula how to compute the running total. I just don't understand why it works and always took it for granted. For example we have this very standard measure, which is computing the running total of the year and also to a specific point in time :

RunningTotal= 

Calculate (

      Sales[Value]), 

     Filter ( 'Calendar'),

    'Calendar' [Year]= MAX( 'Calendar' [YEAR]) &&

    'Calendar' [Date]<=Max ('Calendar' [Date] )

    )

)

 
What I don't understand is, why MAX( 'Calendar' [YEAR]) and Max ('Calendar' [Date] ) are actually working automatically in a filter context to the date column. Shouldn't they be evaluated as the Maximum Year and Maximum Date of the whole available dataset at any date row, which is being computed at that moment? To illustrate what I mean, I put an example of MAX('Calendar'[Year]  in a fourth row, which is here 2023 because my Mastercalendar only has rows until 2023:
Date SalesRunningTotalMAX('Calendar'[Year]
2017-01-01          1001002023
2017-01-025006002023
2017-01-03200026002023
2017-01-04300056002023
2017-01-0510057002023
2017-01-0640061002023
2017-01-0730064002023
2017-01-0815065502023
2017-01-099066402023
2017-01-1010067402023
Total67406740 
Any explanation is highly appreciated.
Thank you very much in advance.
Best. 

4 Replies

  • Applicable88 Filter is an iterator.

     

    Follow us on LinkedIn

     

    Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

    • Applicable88's avatar
      Applicable88
      Impactful Individual

      parry2k , I know Filter goes row by row. But the iterator function is not explaining the fact, that it's not using the MAX Year of that dataset, but the MAX Year in that filter context of the computed row. 

      So I'm pretty sure its not the filter()- function which makes it happen here. 

  • Applicable88 you answered your own question, think, if it goes row by row then on each row it returns the max value of that row, if you are using MAX ( Year ), it is against full table.

     

    Follow us on LinkedIn

     

    Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

     

    Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

  • v-chenwuz-msft's avatar
    v-chenwuz-msft
    Community Support

    Hi Applicable88 

     

    The measure you provide have the DAX max(), when it calculates in a table visual, is the same as selectvalue().I'll provide some data that you can see more visually.

    I create a measure : M_max= MAX('Table'[value])

    For the first line, the max() calculate the column form a table (Table of the process, as the following show ) where index_1 = 1.

    Only two rows and the maximum value is 2,so the result is 2.

     

    For the second line, the process table is like this

    . So the maximum value is 3. And so on.

    The filter context is the index_1 to filter the table which will be input into the measure to calculate.

    In your caes, MAX('Calendar'[Year]) , if it is a measure in table visual, the result should be 2017. If you want to get 2023,maybe try the next measure, this will calculate maximum year of all the column:

    Measure = MAXX(ALL(‘Calendar’),[Year])

     

    If I misunderstood you , please let me know.

    Best Regards

    Community Support Team _ chenwu zhu

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.