Forum Discussion

Casperserven1's avatar
3 years ago
Solved

Accumulating using previous

I am trying to do tthe following and struggling - I am sure this is easy but just can't see it.
New HiresRetireesTotal Workforce
3520
6323
8130
9831
4629
3131
2132
7831

So in excel my first row = 22 +New Hires - Retirees

My second row = 20 (the result from the previous row) +NewHires - Retirees
My third row    = 23  (the result from the previous row) +NewHires - Retirees
etc.. 
Tried various things including EARLIER, using indexing, 

  • tamerj1's avatar
    tamerj1
    3 years ago

    Casperserven1

    Now I got it. Please try

    Total Workforce =
    VAR StartingWF = 22
    VAR TableBefore =
    FILTER ( 'Table', 'Table'[Date] < EARLIER ( 'Table'[Date] ) )
    VAR Change =
    SUMX ( TableBefore, 'Table'[New Hires] - 'Table'[Retirees] )
    RETURN
    StartingWF + Change

10 Replies

      • tamerj1's avatar
        tamerj1
        Community Champion

        Casperserven1 
        Please refer to attached sample file with the proposed solution

        Total Workforce = 
        VAR StartingWF = 22
        VAR TableOnAndBefore = 
            FILTER ( 'Table', 'Table'[Date] <= EARLIER ( 'Table'[Date] ) )
        VAR Change = 
            SUMX ( TableOnAndBefore, 'Table'[New Hires] - 'Table'[Retirees] )
        RETURN
            StartingWF + Change