Forum Discussion

Raphaël's avatar
Raphaël
Regular Visitor
9 years ago
Solved

Cumulative sum by dates by persons

Dear all,  I am trying to build a cumulative sum by date and by person but can't figure out how to do that. The only thing I suceed to do is a simple cumulative sum by date.   Let me explain with ...
  • Datatouille's avatar
    9 years ago

    Hi Raphaël

     

    I think you are right to ask not only the answer but also the logic running behind DAX !

     

    I guess 'Persons' column also comes from your 'Query' Table, right ? In that case, try:

    Cumul = 
    CALCULATE (
        SUM ('Query'[Indicator]),
        FILTER (ALL ('Query'[Date] ),'Query'[Date] <= MAX ( 'Query'[Date]))
    )

     

    Filter (Table, filter...) is an iterator function. It iterates over each row of the Table (1st argument) in the current filter context and evaluates the filter condition.

    And here is the explanation in your case:

     

    The ALL function basically ignores the current filter context.

    All(Table) ignores any filters which would come from this 'Table'. This is why your formula isn't computing what you want here.

     

    By writing All(Query), you are ignoring the filter coming from date (which is right here because you want to do a running total) but also the filter coming from 'Persons' (which is NOT what you want here) or any other columns from 'Query' Table that you would potentially bring in your pivot table/slicers, etc.

     

    All accepts a Table or a column as an argument.

    My suggestion is based on All(Query[Date]) which allows you to ignore the filter context only coming from [Date] column of Query Table.