Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
SDPowerBI123
Regular Visitor

Moving Average column

hello all i am trying to do a moving average column but having no success.

 

SDPowerBI123_0-1724917439569.png

i am just trying for a moving average of 2 days, but the column seem to only show current day. i also shown my dax there for the calculated column in case you need to see. i can type it below for you.

 

Moving Average X Days Prior =
CALCULATE(
    AVERAGEX('SPY 1 Years Daily', 'SPY 1 Years Daily'[Close]),
    DATESINPERIOD('SPY 1 Years Daily'[Date], LASTDATE('SPY 1 Years Daily'[Date]), -2, DAY
    )
)
1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @SDPowerBI123 - The issue with your DAX formula for the moving average is that it calculates the average over only the current day

can you check the below modified one to get the current and previous days

 

Moving Average 2 Days =
CALCULATE(
AVERAGEX(
DATESINPERIOD(
'SPY 1 Years Daily'[Date],
LASTDATE('SPY 1 Years Daily'[Date]),
-2,
DAY
),
'SPY 1 Years Daily'[Close]
)
)

 

Hope this helps





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
sjoerdvn
Super User
Super User

Try this:

Moving Average 2 Days = VAR ld = LASTDATE('SPY 1 Years Daily'[Date])
VAR fd =DATESINPERIOD('SPY 1 Years Daily'[Date], ld,-2, DAY)
RETURN CALCULATE(AVERAGE('SPY 1 Years Daily'[Close]),ALL('SPY 1 Years Daily'),fd)
rajendraongole1
Super User
Super User

Hi @SDPowerBI123 - The issue with your DAX formula for the moving average is that it calculates the average over only the current day

can you check the below modified one to get the current and previous days

 

Moving Average 2 Days =
CALCULATE(
AVERAGEX(
DATESINPERIOD(
'SPY 1 Years Daily'[Date],
LASTDATE('SPY 1 Years Daily'[Date]),
-2,
DAY
),
'SPY 1 Years Daily'[Close]
)
)

 

Hope this helps





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.