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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
mansiluthra12
Helper I
Helper I

Get selected value from relative date slicer.

I have Relative date slicer and I want to pick what is selected in drop down.

Is it possible?
Example – Suppose slicer have following value following value – I want to pick weeks.

mansiluthra12_0-1637750564844.png

 

5 REPLIES 5
madman
New Member

Dynamic title =
var _max = maxx(allselected(dim_calendar),dim_calendar[Date]) + 1
var _min = minx(allselected(dim_calendar),dim_calendar[Date])
var prefix = IF(_max -1 > TODAY() && _min < TODAY() || _max -1 == _min, "this", IF(_max -1> TODAY(), "next", "last"))
var days_diff = DATEDIFF(_min, _max, DAY)
var suffix = IF(MOD(YEARFRAC(_min, _max),1) == 0, "year", IF(days_diff >= 7 && MOD(days_diff, 7) == 0, "week", IF(MOD(YEARFRAC(_min, _max)*12,1) == 0, "month", "day")))
var date_diff = IF(suffix == "year", DATEDIFF(_min, _max, YEAR), IF(suffix == "month", DATEDIFF(_min, _max, MONTH), IF(suffix == "week", DATEDIFF(_min, _max, WEEK), DATEDIFF(_min, _max, DAY))))
var final_text = IF(prefix == "this", prefix & " " & suffix, prefix & " " & ABS(date_diff) & " " & suffix & "s")
return "Text " & final_text

@madman Thank you so much for the code; it helps to catch the text on the relative date slicer, brilliant!

amitchandak
Super User
Super User

@mansiluthra12 m You can get the range in var

 

measure =
var _max = maxx(allselected('Date'),'Date'[Date])
var _min = minx(allselected('Date'),'Date'[Date])

return

<code>

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

Actually , I dont need the range between the dates , I need to have text what is selected in filter(like days, weeks,years),as based on selection I will be using it in other measure 

mansiluthra12_0-1637752755647.png

 

Hi @mansiluthra12 did you find the solution for this.

Please share me the solution if you find any. Looking for your reply.

 

Thanks in advance

Sanjeev 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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