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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Anonymous
Not applicable

How to get previous dates based on slicer start date and end selection

Hi all,

Thank you in advance. I am trying to achevie below functonality.

I have a slicer like below 

Ravi_BI_0-1659039207137.png

Based on start date and enddate, days difference it needs to return previous start date and end date.

 Slicer Selected date  O/p required Format
      mm/dd/yyyy
 Start DateEnd DatedifferenceStart DateEnd Date 
Case 11/1/20221/1/20220 days12/31/202112/31/2021 
Case 22/1/20222/28/202228 Days1/3/20221/31/2022 
Case 31/1/20221/15/202215 days1/16/20211/31/2021 

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , The second set of dates is what you need

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) //add +1 if needed
var _maxX = _max-datediff1
var _minX = _min -datediff1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , The second set of dates is what you need

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) //add +1 if needed
var _maxX = _max-datediff1
var _minX = _min -datediff1
return
CALCULATE(SUM(Sales[Sales Amount]),filter(all(date,date[date]<=_maxX &&date[date]>=_minX)))

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Case 1 & Case 3 are working with above logic. 

Can you please look into case 2?

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors