Forum Discussion

lollo's avatar
lollo
Frequent Visitor
8 years ago
Solved

Cumulative Sum

Hello,

 

I have one table with [Date], [Capacity Need], [Production Order]

related with the [Date Dimension Table]  with the field [Date], [Year], [WeekOfYear], [LastDateOfPreviousWeek] ...,

i need a Measure for the Expired Prdoduction Order doing the sum of [Capacity Need] between the MIN date in [Date Dimension] and the [LastDayOfPreviousWeek], i have some problem with the FILTER in the CALCULATE formula.

 

Any suggestions? Thanks!

  • Solved,

    I added two columns in DateDimension, one with the first day of the week,
    and one that concatenates the year of the first day of the week with the number of the week "ISO", this because it can happen that in some years there are two weeks Nr. 52, as in the case where the last week of the year is between two years;

    finally I added this measure:

     

    ManAllocHoursRunningSum = 
    CALCULATE(
                          SUM(
                                     'Capacity Need'[Man Allocated Hours]);
                                     FILTER(
                                                  ALL(DateDimension[Date]);
                                                  DateDimension[Date]<=MIN(DateDimension[LastDayOfPreviousWeek]
                                                 )
                                   )
                        )

     

    now it works well

     

4 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Seems like it would be something like:

     

    Measure = CALCULATE(SUM(Table[Capacity Need]),FILTER(Table[Date] >= MIN('Date Dimension Table'[Date]) && Table[Date] <= MAX('Date Dimension Table'[LastDayOfPreviousWeek])))

    Assuming lastdayofpreviousweek is a date.

    • lollo's avatar
      lollo
      Frequent Visitor

      Maybe I did not say it clear enough

      this is an exmple of data:

       

      Capacity Need (Table)
      DepartmentDate Capacity Need Prod. Order
      DEPT115/01/2018                      10,00P1
      DEPT116/01/2018                      10,00P2
      DEPT117/01/2018                      10,00P3
      DEPT118/01/2018                      10,00P4
      DEPT119/01/2018                      10,00P5
      DEPT120/01/2018                      10,00P6
      DEPT121/01/2018                      10,00P7
      DEPT122/01/2018                      10,00P8
      DEPT123/01/2018                      10,00P9
      DEPT124/01/2018                      10,00P10
      DEPT125/01/2018                      10,00P11
      DEPT126/01/2018                      10,00P12
      DEPT127/01/2018                      10,00P13
      DEPT128/01/2018                      10,00P14
      DEPT215/01/2018                      10,00P15
      DEPT216/01/2018                      10,00P16
      DEPT217/01/2018                      10,00P17
      DEPT218/01/2018                      10,00P18
      DEPT219/01/2018                      10,00P19
      DEPT220/01/2018                      10,00P20
      DEPT221/01/2018                      10,00P21
      DEPT222/01/2018                      10,00P22
      DEPT223/01/2018                      10,00P23
      DEPT224/01/2018                      10,00P24
      DEPT225/01/2018                      10,00P25
      DEPT226/01/2018                      10,00P26
      DEPT227/01/2018                      10,00P27
      DEPT228/01/2018                      10,00P28

       

      Date Dimension (Table)
      DateWeekNumberLastDayOfPreviousWeek
      15/01/2018314/01/2018
      16/01/2018314/01/2018
      17/01/2018314/01/2018
      18/01/2018314/01/2018
      19/01/2018314/01/2018
      20/01/2018314/01/2018
      21/01/2018314/01/2018
      22/01/2018321/01/2018
      23/01/2018321/01/2018
      24/01/2018321/01/2018
      25/01/2018321/01/2018
      26/01/2018321/01/2018
      27/01/2018321/01/2018
      28/01/2018321/01/2018
      15/01/2018414/01/2018
      16/01/2018414/01/2018
      17/01/2018414/01/2018
      18/01/2018414/01/2018
      19/01/2018414/01/2018
      20/01/2018414/01/2018
      21/01/2018414/01/2018
      22/01/2018421/01/2018
      23/01/2018421/01/2018
      24/01/2018421/01/2018
      25/01/2018421/01/2018
      26/01/2018421/01/2018
      27/01/2018421/01/2018
      28/01/2018421/01/2018

       

      this is the pivot I would like to get

       

      WeekNumber3344
       ExpiredWeek HoursExpiredWeek Hours
      DEPT10707070
      DEPT20707070

       

      Many Thanks in advance

      Lorenzo

       

      • lollo's avatar
        lollo
        Frequent Visitor

        Solved,

        I added two columns in DateDimension, one with the first day of the week,
        and one that concatenates the year of the first day of the week with the number of the week "ISO", this because it can happen that in some years there are two weeks Nr. 52, as in the case where the last week of the year is between two years;

        finally I added this measure:

         

        ManAllocHoursRunningSum = 
        CALCULATE(
                              SUM(
                                         'Capacity Need'[Man Allocated Hours]);
                                         FILTER(
                                                      ALL(DateDimension[Date]);
                                                      DateDimension[Date]<=MIN(DateDimension[LastDayOfPreviousWeek]
                                                     )
                                       )
                            )

         

        now it works well