Forum Discussion

koenmilt's avatar
koenmilt
Frequent Visitor
8 years ago
Solved

Cumulative total ignoring certain table columns

I have the following situation:

 

I have a report in which i show the following:

Employee

Cost_center

Function

Year_Week

Hours Spend

Cumulative Hours spend

 

The cumulative Hours spend looks like the following:

Cumulative Hours spend =
CALCULATE (
sum('OVERUREN_WEEK'[Hours Spend]);
FILTER (
ALL ('OVERUREN_WEEK'[Year_Week]);
'OVERUREN_WEEK'[Year_Week] <= MAX ( 'OVERUREN_WEEK'[Year_Week )
)
)

 

The problem i'm having is that the cumulative measure resets when an Employee transfers to a different function or cost center.

So for example:

 

Employee  - cost center - function - year_week - hours spend - cumulative

Henk   -  2500                - Developer - 201701   - 3                   - 3

Henk   -  2500                - Developer - 201702   - 1                   - 4

Henk   -  4000                - Developer - 201703   - 2                   - 2

 

The cumulative restarts when the employee switches to a different Cost_center in week 201703.

The only way I was able to resolve was by removing Cost_Center and Funciton from the grid, But I dont want to do that.

 

Any help would be greatly appreciated!

  • Hi koenmilt,

     

    You could try  this:

    Cumulative Hours spend =
    CALCULATE (
        SUM ( 'OVERUREN_WEEK'[Hours Spend] ),
        FILTER (
            ALLEXCEPT ( 'OVERUREN_WEEK', OVERUREN_WEEK[Employee] ),
            OVERUREN_WEEK[Year_Week] <= MAX ( OVERUREN_WEEK[Year_Week] )
        )
    )

     

    Best regards,

    Yuliana Gu

8 Replies

  • v-yulgu-msft's avatar
    v-yulgu-msft
    Microsoft Employee

    Hi koenmilt,

     

    Please create several calculated column in source table using below formulas:

    Previous Const_center =
    LOOKUPVALUE (
        OVERUREN_WEEK[Cost_center],
        OVERUREN_WEEK[Employee], OVERUREN_WEEK[Employee],
        OVERUREN_WEEK[Year_Week], OVERUREN_WEEK[Year_Week] - 1
    )
    
    Previous Function =
    LOOKUPVALUE (
        OVERUREN_WEEK[Function],
        OVERUREN_WEEK[Employee], OVERUREN_WEEK[Employee],
        OVERUREN_WEEK[Year_Week], OVERUREN_WEEK[Year_Week] - 1
    )
    
    Is Change =
    IF (
        OVERUREN_WEEK[Cost_center] = OVERUREN_WEEK[Previous Const_center]
            && OVERUREN_WEEK[Function] = OVERUREN_WEEK[Previous Function],
        0,
        1
    )
    
    Change times =
    CALCULATE (
        SUM ( OVERUREN_WEEK[Is Change] ),
        FILTER (
            ALLEXCEPT ( OVERUREN_WEEK, OVERUREN_WEEK[Employee] ),
            OVERUREN_WEEK[Year_Week] <= EARLIER ( OVERUREN_WEEK[Year_Week] )
        )
    )

     

    Then, create a measure to return Cumulative total.

    Cumulative Hours spend =
    CALCULATE (
        SUM ( OVERUREN_WEEK[Hours Spend] ),
        FILTER (
            ALLEXCEPT ( OVERUREN_WEEK, OVERUREN_WEEK[Employee] ),
            OVERUREN_WEEK[Change times] = MAX ( OVERUREN_WEEK[Change times] )
                && OVERUREN_WEEK[Year_Week] <= MAX ( OVERUREN_WEEK[Year_Week] )
        )
    )

     

    Best regards,
    Yuliana Gu

    • koenmilt's avatar
      koenmilt
      Frequent Visitor

      Hi Yuliana,

       

      First of all, thanks for the reply!

       

      I have tried creating the measures you suggested. But i'm having trouble creating the first one.

       

      It says "a single value for column "EMPLOYEE" in table "OVERUREN_WEEK" cannot be determined.  This can happen when a measure formula refers to a column that contains many values without specifying aggregation such as min, sum..."

       

       

      Also, in your final example (the picture) it does not seem to work, The cumulative total for Henk in Year_week 201704 is reset because he switched cost_center there.

      • v-yulgu-msft's avatar
        v-yulgu-msft
        Microsoft Employee

        Hi koenmilt,

         

        From the highlighted rows, we can see that the cumulative total for Henk in Year_week 201704 is reset, comparing with Year_week 201703.

         

        For the error message, do you have multiple records for one employee under the same week?

         

        Regards,
        Yuliana Gu