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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Mr_Glister
Advocate II
Advocate II

Calculate difference between moving average value of two different dates

Hi, 

I have daily observations with a bit of variability in their measurements, so I'm calculating a 30 day moving average. 

I do so with the following DAX and it works fine:

 

My daily weight moving average = 

 

 

Smartavgmoving =
VAR _Maxdate = MAX( 'Date table'[Date])
RETURN  CALCULATE( AVERAGE( Table[My daily weight]), DATESBETWEEN( 'Date table'[Date], _Maxdate - 15, _Maxdate +15))

 

 

As expected the output looks like this:

Mr_Glister_0-1699460028249.png

 

I want to calculate the rate of change between certain periods (for example, between every first and last of a month) but no matter how I try to pass a date filter to my moving average calculation, the outcome is always the table above. 

For example, the measure below results in the same table as posted above. 

 

=CALCULATE( Smartavgmoving, Table[DATE] = dt"2023-01-17"))

 

 

Can somebody point me in the right direction?

2 REPLIES 2
amitchandak
Super User
Super User

@Mr_Glister , Based on what I got, Try measures like

 

First of month =
VAR _Maxdate = Eomonth(MAX( 'Date table'[Date]), -1) +1
RETURN CALCULATE( AVERAGE( Table[My daily weight]), DATESBETWEEN( 'Date table'[Date], _Maxdate - 15, _Maxdate +15))


Last of Month=
VAR _Maxdate = Eomonth(MAX( 'Date table'[Date]), 0)
RETURN CALCULATE( AVERAGE( Table[My daily weight]), DATESBETWEEN( 'Date table'[Date], _Maxdate - 15, _Maxdate +15))

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak,

(Nice to get help from one of the forum heroes!)

I will try your suggestion and I'm sure it will work for this narrow case. But the real reason I posted this to the forum is the following question:

 

Since my original measure correctly calculates a value for each date, shouldn't I be able to directly access the values of each date? For example, if - for some reason - I wanted to calculate the difference of exactly the two dates I highlighted. Or put differently, why does the DAX below not work and how would I have to do it correctly?

=CALCULATE( Smartavgmoving, Table[DATE] = dt"2023-01-17"))

 

Mr_Glister_0-1699514026467.png

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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