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

Dynamic Date Range

I have a custom date range. what I want is If someone select last 30 days, Last Month, This month so i have calculated the start date and enddate Accordingly based on users selection that will be applied to entire page and the custom date slicer as well

Msurya99_0-1735050039587.png

 

1 REPLY 1
rohit1991
Super User
Super User

Could you please try below Steps: 
1. Create Helper table (for the slicer):

DateRange = DATATABLE("Option", STRING,
  {{"Last 30 Days"},{"Last Month"},{"This Month"}})

 

2. Two measures:

StartDate =
SWITCH( SELECTEDVALUE(DateRange[Option]),
  "Last 30 Days", TODAY() - 30,
  "Last Month",  EOMONTH(TODAY(),-2) + 1,
  "This Month",  EOMONTH(TODAY(),-1) + 1)
EndDate =
SWITCH( SELECTEDVALUE(DateRange[Option]),
  "Last 30 Days", TODAY(),
  "Last Month",  EOMONTH(TODAY(),-1),
  "This Month",  TODAY())

 

3. One filter measure:

InRange =
VAR s = [StartDate]
VAR e = [EndDate]
RETURN IF( MAX('Date'[Date]) >= s && MAX('Date'[Date]) <= e, 1, 0 )

 

4. Put DateRange[Option] as a slicer >> add InRange = 1 in the page/visual filter pane.
Now picking an option updates the entire page (and any custom date slicer that’s bound to your Date table).


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.