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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. 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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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