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

Dynamic Date Range Filter to show most recent completed week but also allow user to control dates

Hello,

I'm attempting to create a dynamic date range filter in a report, but I'm having difficulties with setting the filter up properly. I would like the report to show the last complete week (Monday through Sunday), but I would like it to automatically update to reflect whatever the last complete week was without the user having to update the filter.

 

I know there is the Relative date filter type, however, I would rather not use this because the user needs the ability to extend the start and/or end dates if need be.

 

For example: If the user opened the report today (April 07, 2023), the report would show the date range filter of (03/27/23 through 04/02/23) since that was the most recent completed week Monday-Sunday. However, the user could then extend the start date and/or end date to arbitrary dates if need be (say 02/28/23 through 04/06/23).

 

DateRangeFilter.png

 

Any help would be greatly appreciated.

 

Thank you,

Paul

 

Sample data:

ValueDate
1.1760911/5/2023
1.204121/6/2023
1.2304491/7/2023
1.1760911/8/2023
1.204121/9/2023
1.2304491/10/2023
1.1760911/11/2023
1.204121/12/2023
1.2304491/13/2023
1.1760911/14/2023
1.204121/15/2023
1.2304491/16/2023
1.1760911/17/2023
1.204121/18/2023
1.2304491/19/2023
1.1760911/20/2023
1.204121/21/2023
1.2304491/22/2023
1.1760911/23/2023
1.204121/24/2023
11/25/2023
21/26/2023
31/27/2023
41/28/2023
51/29/2023
61/30/2023
71/31/2023
82/1/2023
92/2/2023
102/3/2023
112/4/2023
122/5/2023
132/6/2023
142/7/2023
152/8/2023
162/9/2023
172/10/2023
182/11/2023
192/12/2023
202/13/2023
212/14/2023
222/15/2023
232/16/2023
242/17/2023
252/18/2023
262/19/2023
272/20/2023
282/21/2023
292/22/2023
302/23/2023
312/24/2023
322/25/2023
332/26/2023
342/27/2023
352/28/2023
363/1/2023
373/2/2023
383/3/2023
393/4/2023
403/5/2023
413/6/2023
423/7/2023
433/8/2023
443/9/2023
453/10/2023
463/11/2023
473/12/2023
483/13/2023
493/14/2023
503/15/2023
513/16/2023
523/17/2023
533/18/2023
543/19/2023
553/20/2023
563/21/2023
573/22/2023
583/23/2023
593/24/2023
603/25/2023
613/26/2023
623/27/2023
633/28/2023
643/29/2023
653/30/2023
663/31/2023
674/1/2023
684/2/2023
694/3/2023
704/4/2023
714/5/2023
724/6/2023
734/7/2023
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , for that you can create independent date table and use that in slicer

 

example of last 14 day measures

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = _max -14
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

For the Latest value refer

 

Latest
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee884e

 

Add date range from above in the latest formula

 

example

 

Last Qty = Var _max = maxx(filter( ALLSELECTED(Data1), Data1[ID] = max(Data1[ID]) && 'Data1'[Date] >=_min && 'Data1'[Date] <=_max ),Data1[Date])
return
CALCULATE(sum(Data1[qty]), filter( (Data1), Data1[ID] = max(Data1[ID]) && Data1[Date] =_max && 'Data1'[Date] >=_min && 'Data1'[Date] <=_max ))
Sum Last Qty = sumx(VALUES(Data1[ID]) , [Last Qty])

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

1 REPLY 1
amitchandak
Super User
Super User

@Anonymous , for that you can create independent date table and use that in slicer

 

example of last 14 day measures

 

//Date1 is independent Date table, Date is joined with Table
new measure =
var _max = maxx(allselected(Date1),Date1[Date])
var _min = _max -14
return
calculate( sum(Table[Value]), filter('Date', 'Date'[Date] >=_min && 'Date'[Date] <=_max))

 

Need of an Independent Date Table:https://www.youtube.com/watch?v=44fGGmg9fHI

 

For the Latest value refer

 

Latest
https://amitchandak.medium.com/power-bi-get-the-last-latest-value-of-a-category-d0cf2fcf92d0

https://amitchandak.medium.com/power-bi-get-the-sum-of-the-last-latest-value-of-a-category-f1c839ee884e

 

Add date range from above in the latest formula

 

example

 

Last Qty = Var _max = maxx(filter( ALLSELECTED(Data1), Data1[ID] = max(Data1[ID]) && 'Data1'[Date] >=_min && 'Data1'[Date] <=_max ),Data1[Date])
return
CALCULATE(sum(Data1[qty]), filter( (Data1), Data1[ID] = max(Data1[ID]) && Data1[Date] =_max && 'Data1'[Date] >=_min && 'Data1'[Date] <=_max ))
Sum Last Qty = sumx(VALUES(Data1[ID]) , [Last Qty])

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

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.