Restricting the date in date slider

Hi there,

I have a date slider that shows to and from date fields. From date field shows date starting in 1996 and to shows the date value of 2026. Is there any way I could restrict the from and to date to current year? For example from starts from 1-Jan-2020 and To should the year to date().

Without seeing your data model, it’s hard to know exactly what will solve this issue.

The cause is your date table, apparently it is including dates from 1996 to 2026 - which seems like a lot of time. So my first question is, do you have data that requires all those years?

If the answer is no, I would definitely recommend trimming down the calendar to only the needed dates - that large a table is going to slow your model.

Once that is done, you need to have a column on your date table to recognize the period you want (like current year, or year offset, or something similar). This column can be used to filter your date table in the slicer.

image

@leo_89,

Very much along the lines of @Heather’s response, I have some DAX code that I regularly reuse for this purpose. Just create a calculated column on your Dates table (you could also do this as a measure, but occasionally I like to slice on this field, so I do it as a calculated column) using this code, then set the filter pane on the slicer visual as below:

Active Dates = 

VAR MinDate = DATE( 2020, 1, 1)
VAR MaxDate = TODAY()

VAR Result =
IF( 
    AND(
        Dates[Date] >= MinDate,
        Dates[Date] <= MaxDate
    ),
    1, 0
)

RETURN 
Result

image

To filter different dates, just change the values of the MinDate and MaxDate variables.

I’ve placed the code in the Analyst Hub community area to make it easy for folks to grab:

I hope this is helpful.

  • Brian
2 Likes

Hi @leo_89, we aim to consistently improve the topics being posted on the forum to help you in getting a strong solution faster. While waiting for a response, here are some tips so you can get the most out of the forum and other Enterprise DNA resources.

  • Use the forum search to discover if your query has been asked before by another member.
  • When posting a topic with formula make sure that it is correctly formatted to preformatted text </>.image
  • Use the proper category that best describes your topic
  • Provide as much context to a question as possible.
  • Include the masked demo pbix file, images of the entire scenario you are dealing with, screenshot of the data model, details of how you want to visualize a result, and any other supporting links and details.

I also suggest that you check the forum guideline How To Use The Enterprise DNA Support Forum. Not adhering to it may sometimes cause delay in getting an answer.

Please also check the How To Mask Sensitive Data thread for some tips on how to mask your pbix file.

Hi @Leo_89, we’ve noticed that no response has been received from you since the 16th of December. We just want to check if you still need further help with this post? In case there won’t be any activity on it in the next few days, we’ll be tagging this post as Solved. If you have a follow question or concern related to this topic, please remove the Solution tag first by clicking the three dots beside Reply and then untick the checkbox. Thanks!

Hi @Leo_89, a response on this post has been tagged as “Solution”. If you have a follow question or concern related to this topic, please remove the Solution tag first by clicking the three dots beside Reply and then untick the check box. Also, we’ve recently launched the Enterprise DNA Forum User Experience Survey, please feel free to answer it and give your insights on how we can further improve the Support forum. Thanks!