Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

7 Day moving Average

Hello, I am new to power bi but I am having hard time finding the 7 moving  avg of a measurement(Avg Tv Sold):

So far the dax formula i've been using which is not working correctly is: 

Avg Last7days = 

CALCULATE(

 AVERAGEX(VALUES(TVDATA[Avg Tv Sold]),
 DATESINPERIOD(Date[Sold_Date], LASTDATE(Date[Sold_Date]), -7, DAY)   

)
  • Hi, Anonymous ;

    You could modify the measure as follows:

    AVG = CALCULATE(AVERAGEX('Table',[AVG Tv Sold2]),DATESINPERIOD('Table'[Date],MAX('Table'[Date]),7,DAY))

    The final output is shown below:

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Anonymous , Assume you have measure TV Sold

     


    Avg Last7days =

    CALCULATE(

    AVERAGEX(VALUES(Date[Sold_Date]),[Tv Sold]),
    DATESINPERIOD(Date[Sold_Date], LASTDATE(Date[Sold_Date]), -7, DAY)

    )

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for the reply, when I campare it to the actual moving avg, it seem to be somewhat off by a small amount like .36 or .65. Do you know what is causing this?

      • Anonymous's avatar
        Anonymous
        Not applicable

        I think I figured out that AverageX is not including zeros values. For example on 

        DateAVG Tv Sold
        1/2/202020
        1/3/202030
        1/4/20200
        1/5/20200
        1/6/202070
        1/7/202022
        1/8/202050
        1/9/202010
        1/10/202020

         

        for actual moving AVG should of been:

        27.42857
        26
        24.57143
        28.66667
        34.4
        25.5
        26.66667
        15
        20

         

        But with AVERAGEX would only do those days with sales above zeros. how do i include the zeros into the calculation?

         

        Thank You!

  • v-yalanwu-msft's avatar
    v-yalanwu-msft
    Icon for Community Support rankCommunity Support

    Hi, Anonymous ;

    You could modify the measure as follows:

    AVG = CALCULATE(AVERAGEX('Table',[AVG Tv Sold2]),DATESINPERIOD('Table'[Date],MAX('Table'[Date]),7,DAY))

    The final output is shown below:

    Best Regards,
    Community Support Team_ Yalan Wu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.