Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
9 years ago
Solved

Please explain cumulative sum work principle

So, I have the followint formula, that calculates cumulative sum for a measure CumulativeAmount = CALCULATE ( SUM ( sheet1[amount] ), FILTER ( ALL ( calendar[Date] ), calendar[Date] <= MAX (...
  • v-ljerr-msft's avatar
    9 years ago

    Hi Anonymous,

     

    There are two important points about this expression:

     

    The use of ALL(Date) in order to ignore the current context. In fact, FILTER iterates over the entire table, analyzing dates that are outside of the current filter context. In this way, it will return date that are lower than or equal to the current filter.

     

    The comparisons of Date[DateKey] against MAX(Date[Datekey]). When you are not familiar with DAX, these expressions look strange. However, if you recall the exact meaning of MAX , you see that it means "the maximum value of DateKey in the current context." Because the expression is part of CALCULATE filters, it still works in the original filter context. On the other hand, the expression Date[DateKey] is a column name, meaning "The value of DateKey in the current row context which is created by the FILTER during its iteration."

     

    Hope it could help you better understand how it works. :smileyhappy:

     

    Regards