Forum Discussion

MacedoLuis's avatar
MacedoLuis
New Member
3 years ago

MAT Based Previous Quarters

vl_salesyearquarterCategoty
113mi20211Kit Kat
114mi20212Nescau
100mi20213Chocolate
87mi20214Nescau
88mi20221Beve
115mi20222Iorgurt
77mi20223Nesquit
100mi20224Nescau
90mi20231Cookies


dim_calendar

yearquarterquarter_list
20211202101
20212202102
20213202103
20214202104
20221202201
20222202202
20223202203
20224202204
20231202301
20232202302
20233202303
20234202304


How can I calculate Moving Annual Sales for previous 4quarters, in way that 2023 Q1 = sum of values of the lasts 4 quarters, 
and 2022 Q4 = sum of values of the lasts 4 quarters, and so on? Any Help?

2 Replies

  • MacedoLuis , Create a new Rank column in dim calendar (calling it date in my formula)

     

    Qtr Rank = RANKX(all('Date'),'Date'[quarter_list],,ASC,Dense)

     

     

    Then you can have measure like
    This Qtr = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])))
    Last Qtr = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Qtr Rank]=max('Date'[Qtr Rank])-1))

     

     


    Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510
    Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
    Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

     

     

    Power BI Custom Period Till Date (PTD)- https://youtu.be/rQ3Z_LtxwQM

    • LuisMacedo's avatar
      LuisMacedo
      Regular Visitor

      amitchandak  I tried it, and got blanks. And also tried like this, but i got blanks. Would you have another to calculate it?

      fx_MovingAnnualTotal =
      VAR fx_calendartable =
          SUMMARIZE(DimCalendario,
              DimCalendario[Data],
              DimCalendario[Quarter],
              DimCalendario[Trim_Ano],
              "@Qtr Rank",
              RANKX(ALL(DimCalendario), DimCalendario[Trim_Ano],,ASC,Dense)
          )
      VAR fx_LastQtr =
          CALCULATE([Faturamento na Venda], FILTER(fx_calendartable, [@Qtr Rank] = MAXX(fx_calendartable, [@Qtr Rank])-1))
      RETURN
      fx_LastQtr