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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Vickar
Advocate II
Advocate II

Measure to Get Relative Dates for calculating Previous Adjacent Period based on Relative Date Slicer

I have a Relative Date Slicer, the requirement is to create a measure that calculates a sum based on the previous adjacent period(not same period last  year) related to the relative date slicer.

 

1. for e.g. if today is 06Oct2022, if user selects "Last 4 days", then the date range would be 02Oct2022 to 05Oct2022. the measure should return prev. period date range as 28Sep2022 to 01Oct2022.
2. similary, if user selects "Last 1 weeks(calendar)" in relative date slicer, considering current week is 43, the date range selected would be week 42, measure should return prev. period as week 41.

3. similary, if the user selects "Last 1 month(calendar)" in relative date slicer, considering current month is Oct2022, the date range selected would be Sep2022, measure should return Aug2022.


I authored the below measure that correctly returns the previous adjacent date range based on the date range in the current filter context. But this doesn't compares the current full month with the previous full month. i.e. if user selects "last 1 month(calendar)", which lets suppose is 01Sep2022 to 30Sep2022, the below measure will calculate previous date range as 02Aug2022 to 31Aug2022 (1Aug2022) will be excluded. whereas I want the prev date range to include 1Aug2022

 

 

Activated Previous Period = 
//if current date range selected is 02Oct2022 to 05Oct2022, the prev date range should be 28Sep20 to 01Oct2022
var _MinDate = MIN('Contracts'[ActivationDate]) //e.g. 02Oct2022
var _MaxDate = MAX('Contracts'[ActivationDate]) //e.g. 05Oct2022
var _DateBeforeMin = _MinDate - 1 // e.g. 01Oct2022
var _DaysBtwnMinMax = COUNTROWS(DATESBETWEEN('Contracts'[ActivationDate],_MinDate,_MaxDate)) + 1  //e.g. 4
var _MinDateAfterDateShift  = _DateBeforeMin  - (_DaysBtwnMinMax-1)// e.g. 28Sep2022   //-1 to make lower limit of date range inclusive 
var _ShiftedDateRange = DATESBETWEEN('Contracts'[ActivationDate],_MinDateAfterDateShift,_DateBeforeMin)

var _ActivatedDuringShiftedPeriod = 
CALCULATE([Activated This Period],
        _ShiftedDateRange
)
return
_ActivatedDuringShiftedPeriod

 

 

 

any help would be highly appreciated 

@amitchandak @Greg_Deckler @Shaurya 

3 REPLIES 3
lbendlin
Super User
Super User

use EDATE(-12)  to shift your selected min/max dates back a year, or apply SAMEPERIODLASTYEAR to your date filter context.

Thanks for your response. But as I mentioned in the question, the requirement is not to compare it with SPLY. Rather the adjacent previous period. I've also given example for it.


Hi Vickar, did you find a solution for this?

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors