Forum Discussion
Dynamic date slicer with default starting point and ongoing ending point (yesterdays date)
- 2 years ago
You can achieve this dynamic date slicer behavior using DAX expressions in Power BI without needing to resort to M code. Here's how you can create a dynamic date slicer:
1. **Create Measures for Start and End Dates**:
First, create measures to calculate the start and end dates based on your requirements.```DAX
StartDate = DATE(YEAR(TODAY()), 1, 1)
``````DAX
EndDate = TODAY() - 1
```The `StartDate` measure returns the first day of the current year, and the `EndDate` measure returns yesterday's date.
2. **Create a Slicer**:
Add a slicer visual to your report and use the date column from your date table as the field for the slicer.3. **Set Default Slicer Values**:
Set the default values for the slicer to be the values of the `StartDate` and `EndDate` measures. You can do this by selecting the slicer, going to the Format pane, and configuring the Start and End dates under the "Default settings" section.4. **Testing and Adjustments**:
Test the slicer to ensure that it defaults to the start of the reporting year and yesterday's date. Also, verify that it updates dynamically when you navigate to different years.By following these steps, you can create a dynamic date slicer in Power BI that always defaults to the start of the reporting year and yesterday's date, ensuring that your data is filtered appropriately based on your requirements.
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! - Anonymous2 years ago
Hi RaMiRo87 ,
Thanks johnbasha33 for the quick reply.
One thing I need to clarify is that you can't find the start date and end date settings in the formatting pane.
You can create a slicer table.Slicer table = CALENDAR(DATE(YEAR(TODAY()), 1, 1), TODAY() - 1)Then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You can achieve this dynamic date slicer behavior using DAX expressions in Power BI without needing to resort to M code. Here's how you can create a dynamic date slicer:
1. **Create Measures for Start and End Dates**:
First, create measures to calculate the start and end dates based on your requirements.
```DAX
StartDate = DATE(YEAR(TODAY()), 1, 1)
```
```DAX
EndDate = TODAY() - 1
```
The `StartDate` measure returns the first day of the current year, and the `EndDate` measure returns yesterday's date.
2. **Create a Slicer**:
Add a slicer visual to your report and use the date column from your date table as the field for the slicer.
3. **Set Default Slicer Values**:
Set the default values for the slicer to be the values of the `StartDate` and `EndDate` measures. You can do this by selecting the slicer, going to the Format pane, and configuring the Start and End dates under the "Default settings" section.
4. **Testing and Adjustments**:
Test the slicer to ensure that it defaults to the start of the reporting year and yesterday's date. Also, verify that it updates dynamically when you navigate to different years.
By following these steps, you can create a dynamic date slicer in Power BI that always defaults to the start of the reporting year and yesterday's date, ensuring that your data is filtered appropriately based on your requirements.
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!
Hello johnbasha33
There is no such Default Value setting under format option of a slicer in power BI to set Start Date and End Date value as mentioned in #3 in your post.
3. **Set Default Slicer Values**:
Set the default values for the slicer to be the values of the `StartDate` and `EndDate` measures. You can do this by selecting the slicer, going to the Format pane, and configuring the Start and End dates under the "Default settings" section.
Could you plz explain where is this setting, did you use any custom visual import like Date Picker?