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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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)))

 

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)))

 

Anonymous
Not applicable

Case 1 & Case 3 are working with above logic. 

Can you please look into case 2?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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