Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon'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.
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:
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?
@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))
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"))
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
131 | |
80 | |
53 | |
38 | |
35 |
User | Count |
---|---|
207 | |
82 | |
75 | |
55 | |
50 |