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!The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!
Hello community.
I have created a formula that should return the measure based on previous date. The formula is as follows.
VAR PeriodEnd = FIRSTDATE(Dates[Date])-1
VAR PeriodStart =
PeriodEnd -
DATEDIFF (
FIRSTDATE(Dates[Date]),
LASTDATE(Dates[Date]),
DAY
)
VAR Result =
CALCULATE(
[Dækningsgrad nuværende],
DATESBETWEEN(
Dates[Date],
PeriodStart,PeriodEnd
)
)
RETURN
ResultIn my mind that should return my measure [Dækningsgrad nuværende] based on my Dates table. -1 period. And if i change (-1) with (-2) that should return my measure minus two periods. However it is not working.
If i set my dates as the following. Last period show 99,02%, but if i change to last period which in this instance would be 01-01-2020 - 31-12-2020
In the above example my measure "Dækningsgrad lastperiod" in 2020 should have returned as "Dækningsgrad 2nd last period" in 2021. Whereas second last period should be 2019.
Dækningsgrad 2nd last period =
VAR PeriodEnd = FIRSTDATE(Dates[Date])-2
VAR PeriodStart =
PeriodEnd -
DATEDIFF (
FIRSTDATE(Dates[Date]),
LASTDATE(Dates[Date]),
DAY
)
VAR Result =
CALCULATE(
[Dækningsgrad nuværende],
DATESBETWEEN(
Dates[Date],
PeriodStart,PeriodEnd
)
)
RETURN
ResultCan you see what could be wrong?
Thanks in advance.
Solved! Go to Solution.
@Anonymous , refer if these can help
same period based on date range
Last Period =
var _max =maxx(allseleceted(date),date[date])
var _min =maxx(allseleceted(date),date[date])
var datediff1 = datediff(_min,_max,day)
var _maxX = _max-datediff1
var _minX = _min -datediff1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))
same period based on date range year behind
Last Period =
var _max =maxx(allseleceted(date),date[date])
var _min =maxx(allseleceted(date),date[date])
var datediff1 = datediff(_min,_max,day)
var _maxX = eomonth(_max,-12)+1
var _minX = eomonth(_min,-12)+1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))
Hi @Anonymous,
Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or accept the helpful suggestions to help others who faced similar requirements.
If these also don't help, please share more detailed information to help us clarify your scenario to test.
How to Get Your Question Answered Quickly
Regards,
Xiaoxin Sheng
@Anonymous , refer if these can help
same period based on date range
Last Period =
var _max =maxx(allseleceted(date),date[date])
var _min =maxx(allseleceted(date),date[date])
var datediff1 = datediff(_min,_max,day)
var _maxX = _max-datediff1
var _minX = _min -datediff1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))
same period based on date range year behind
Last Period =
var _max =maxx(allseleceted(date),date[date])
var _min =maxx(allseleceted(date),date[date])
var datediff1 = datediff(_min,_max,day)
var _maxX = eomonth(_max,-12)+1
var _minX = eomonth(_min,-12)+1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))
The Power BI Data Visualization World Championships is back! It's time to submit your entry.
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 60 | |
| 49 | |
| 30 | |
| 25 | |
| 23 |
| User | Count |
|---|---|
| 128 | |
| 102 | |
| 57 | |
| 39 | |
| 31 |