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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.