Reply
SDPowerBI123
Regular Visitor
Partially syndicated - Outbound

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

Syndicated - Outbound

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

Syndicated - Outbound

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

Syndicated - Outbound

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!





avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

Check out the March 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)