Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!View all the Fabric Data Days sessions on demand. View schedule
I have a 7 day moving average measure that works fine except for one thing, it stops as of the current date. Here's my measure:
Addition $: 7d MA =
VAR __LAST_DATE =
LASTDATE ( 'Calendar'[Date] )
RETURN
IF (
__LAST_DATE <= [Last Refresh Time:],
AVERAGEX (
DATESBETWEEN (
'Calendar'[Date],
DATEADD ( __LAST_DATE, -7, DAY ),
__LAST_DATE
),
CALCULATE ( [Addition $] )
),
BLANK ()
)
Blank overall amount
Everything in the future, including the 'total' is blank. Now, I know that this is what I told it to do in the false part of the IF, but I cannot figure out how to make that same AVERAGEX calculation work for future dates. I tried putting in another variable and using it in the DATESBETWEEN but it gives garbage results.
To see what is happening I used a COUNTX instead. Here's revised DAX and results:
With COUNTX
There are not 952 in DATEDBETWEEN 7 days ago and today! I would expect to see 7 there
Solved! Go to Solution.
Much appreciated, darlove. While that didn't fix my issue, you exposed something to me that allowed me to fix it myself.
When I used your __NOW variable, the DATEADD function in the IF(false) statemet barked at me. That's because a CALCULATE doesn't yield a table and DATEADD wants a table.
But, by playing around a bit I learned a couple of things. First, my [LocalTime] column is a datetime. Evidently DATEADD didn't like having a datetime field passed to it for some reason. Anyway, I opted to add a [Date] field to 'Last Refresh Time' table through the back end. I then played around a bit to finally come up with this working variable:
DATEADD is a time-intel function and works correctly on a column of dates in a proper calendar table. You can't have DATEADD ( __NOW, -7, DAY ), because __NOW belongs to a different table, not to Calendar.
You can check it: DATEADD ( __NOW, -7, DAY ) = BLANK().
Best
D
That makes sense now.
Do you have any suggestions how I can create a __NOW variable that will get LASTDATE('Calendar'[Date]) properly filtered to stop at TODAY()?
var __now =
CALCULATE(
VALUES( 'Calendar'[Date] ),
TREATAS(
LASTDATE('Last Refresh Time'[LocalTime]),
'Calendar'[Date]
)
)
Best
D
Much appreciated, darlove. While that didn't fix my issue, you exposed something to me that allowed me to fix it myself.
When I used your __NOW variable, the DATEADD function in the IF(false) statemet barked at me. That's because a CALCULATE doesn't yield a table and DATEADD wants a table.
But, by playing around a bit I learned a couple of things. First, my [LocalTime] column is a datetime. Evidently DATEADD didn't like having a datetime field passed to it for some reason. Anyway, I opted to add a [Date] field to 'Last Refresh Time' table through the back end. I then played around a bit to finally come up with this working variable:
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 13 | |
| 9 | |
| 9 | |
| 5 | |
| 4 |
| User | Count |
|---|---|
| 28 | |
| 20 | |
| 20 | |
| 19 | |
| 12 |