Forum Discussion

Whitney's avatar
Whitney
Icon for Helper II rankHelper II
5 years ago
Solved

Retrospective rolling 6 month average based on given criteria

Hello!   I'm hoping you could help me, please.   I've been tasked to forecast the percentage of WIP that we consume each month. Our workload fluctuates so a hard-coded percentage figure isn't sui...
  • v-kkf-msft's avatar
    v-kkf-msft
    5 years ago

    Hi Whitney ,

     

    Try the following formula to create measures:

     

    CurrentMonth = MAX('Slicer Table'[Current Month])
    relative = 
    VAR MaxDate = [CurrentMonth]
    VAR MinDate = EOMONTH(MaxDate,-6) + 1
    VAR IsWip = 
        IF(
            MAX('Calendar'[Date]) >= MAX('Table'[Stage 1 start])
            && MAX('Calendar'[Date]) <= EOMONTH(MAX('Table'[Stage 2 start]) ,-1),
            "WIP"
        )
    return 
        IF(
            MAX('Calendar'[Date]) <= MaxDate && MAX('Calendar'[Date]) >= MinDate,
            IsWip
        )
    Measure = 
    var sum_1 = 
      CALCULATE(
        SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]),
        FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-5),"yyyy mmmm"))
      )
    var sum_2 = 
      CALCULATE(
        SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]),
        FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-4),"yyyy mmmm"))
      )
    var sum_3 = 
      CALCULATE(
        SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]),
        FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-3),"yyyy mmmm"))
      )
    var sum_4 = 
      CALCULATE(
        SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]),
        FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-2),"yyyy mmmm"))
      )
    var sum_5 = 
      CALCULATE(
        SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]),
        FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],-1),"yyyy mmmm"))
      )
    var sum_6 = 
      CALCULATE(
        SUMX(FILTER('Table',[relative]="WIP"),'Table'[Stage 2 hours]),
        FILTER('Calendar','Calendar'[Year_Month] = FORMAT(EDATE([CurrentMonth],0),"yyyy mmmm"))
      )
    var NotNullTotal = IF(sum_1<>BLANK(),1) + IF(sum_2<>BLANK(),1) + IF(sum_3<>BLANK(),1) + IF(sum_4<>BLANK(),1) + IF(sum_5<>BLANK(),1) + IF(sum_6<>BLANK(),1)
    return DIVIDE( sum_1 + sum_2 + sum_3 + sum_4 + sum_5 + sum_6, NotNullTotal )

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.

    Best Regards,
    Winniz

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.