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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Previous date range based on slicer

Hi All, 

 

I have a set of data with corresponding dates, and a slicer to filter the data based on the selected date range.

 

I am trying to create a second table that looks at the input of the slicer, but presents the data in the previous equivalent period.

 

For example, the slicer would present the data range 01/07/2019 - 31/12/2019 (6 month period). I want one table to present the data from this range and another table that would look at the range 01/01/2019 - 01/07/2019. (i.e. previous 6 month period.)

 

How can I do this? I have looked at time intelligence functions but can only set intervals of fixed periods (months, days, years etc..)

 

Thank you

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

HI @Anonymous,

I'd like to  suggest you take a look at below blog to know how to use DATE function to manually define filter range and do rolling calculations:

Time Intelligence "The Hard Way" (TITHW)  

Regards,

Xiaoxin Sheng

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

HI @Anonymous,

I'd like to  suggest you take a look at below blog to know how to use DATE function to manually define filter range and do rolling calculations:

Time Intelligence "The Hard Way" (TITHW)  

Regards,

Xiaoxin Sheng

amitchandak
Super User
Super User

Please find the logic. Added logic to adjust the end of the month. if needed you can remove that. 30Th Jun will give 30jan or 30th march not 31st so done the coding for that.

 

Same Month range last period = 
var _diff = datediff(MIN('Date'[date]),max('Date'[date]),MONTH)
var _p_st_date = MINX('Date',DATEADD('Date'[date],-1*_diff,MONTH))
var _maxDt =maxx('Date','Date'[date])
var _maxEndDt =maxx('Date',ENDOFMONTH('Date'[date]))


var _p_end_date = if(_maxDt<>_maxEndDt, MAXX('Date',DATEADD('Date'[date],-1*_diff,MONTH)),MAXX('Date',ENDOFMONTH(DATEADD('Date'[date],-1*_diff,MONTH))))
Return
//_p_st_date & " " & _p_end_date & " " &_maxDt &" " &_maxEndDt
CALCULATE(sum(Sales[Sales Amount]),all('Date'[date]),'Date'[date]>=_p_st_date && 'Date'[date]<= _p_end_date)

 

If you need only days

Same Date range last period = 
var _diff = datediff(MIN('Date'[date]),max('Date'[date]),DAY)
var _p_st_date = MINX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
var _p_end_date = MAXX('Date',DATEADD('Date'[date],-1*_diff,Day))-1
Return
CALCULATE(sum(Sales[Sales Amount]),all('Date'[date]),'Date'[date]>=_p_st_date && 'Date'[date]<= _p_end_date
)

 

The assumption is that you have a date range slicer (or month) and you are using date table.

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

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
sartys
Frequent Visitor

PARELLELPERIOD function allows you to define "custom" time interval, -6 months in this case. https://docs.microsoft.com/pl-pl/dax/parallelperiod-function-dax

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.