March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
I have a measure which works however is not very precise. The idea is to calculate a 3 month rolling average starting from PREVIOUS month, so if we are in February the average will be based on January, December and November.
The part today() - MONTH(today()) is supposed to do just that, however it seems to still include current month.
Also, I'm currently using days as method of couting 3 months back, which is not best option as each month has slightly different numbers of days (28, 30 or 31), so when simply using 90 its always a little off.
The part ( previousWeekDate - 90 ) looks 90 days back, however I would like to be more like previousmonth-3 or something to make sure its looking at the whole month. Any suggestions please ? 🙂
!!INC RAG =
VAR previousWeekDate =
today() - MONTH(today())
RETURN
CALCULATE(
DISTINCTCOUNT( '1'[No.] ),
FILTER (
all('Shared Dates'),
'Shared Dates'[Date] <= previousWeekDate
&& 'Shared Dates'[Date] >= ( previousWeekDate - 90 )
)
) /3
Solved! Go to Solution.
We can calculate the dates in the range then use that as a filter like this:
!!INC RAG =
VAR _Months = 3
VAR _Start = EOMONTH ( TODAY (), - ( _Months + 1 ) ) + 1
VAR _End = EOMONTH ( _Start, _Months )
VAR _Dates =
CALCULATETABLE (
VALUES ( 'Shared Dates'[Date] ),
'Shared Dates'[Date] >= _Start &&
'Shared Dates'[Date] <= _End
)
RETURN
CALCULATE ( DISTINCTCOUNT ( '1'[No.] ), _Dates )
We can simplify it further using DATESINPERIOD like this.
!!INC RAG =
VAR _Months = 3
VAR _Start = EOMONTH ( TODAY (), - (_Months + 1) ) + 1
RETURN
CALCULATE ( DISTINCTCOUNT ( '1'[No.] ), DATESINPERIOD ( 'Shared Dates'[Date], _Start, 3, MONTH ) )
We can calculate the dates in the range then use that as a filter like this:
!!INC RAG =
VAR _Months = 3
VAR _Start = EOMONTH ( TODAY (), - ( _Months + 1 ) ) + 1
VAR _End = EOMONTH ( _Start, _Months )
VAR _Dates =
CALCULATETABLE (
VALUES ( 'Shared Dates'[Date] ),
'Shared Dates'[Date] >= _Start &&
'Shared Dates'[Date] <= _End
)
RETURN
CALCULATE ( DISTINCTCOUNT ( '1'[No.] ), _Dates )
We can simplify it further using DATESINPERIOD like this.
!!INC RAG =
VAR _Months = 3
VAR _Start = EOMONTH ( TODAY (), - (_Months + 1) ) + 1
RETURN
CALCULATE ( DISTINCTCOUNT ( '1'[No.] ), DATESINPERIOD ( 'Shared Dates'[Date], _Start, 3, MONTH ) )
Wow, thank you! The first solution actually does the same as my solution: it still takes the current month into accunt, however the second one worked like a dream 🙂
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
124 | |
89 | |
84 | |
70 | |
51 |
User | Count |
---|---|
206 | |
143 | |
97 | |
79 | |
68 |