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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
manoj_0911
Post Patron
Post Patron

How to Implement PRESET DATE Filters and Dynamic Date Axis in an single Power BI Report?

How to Implement PRESET DATE Filters and Dynamic Date Axis in an single Power BI Report?

 

Question:

 

Hello everyone,

 

I'm working on a Power BI report and need help implementing the following functionalities:

 

1. Preset Date Filters: I want to create a set of predefined date filters (like "Today", "Yesterday", "This Week","Last Week", "This Month", "Last Month", "This Quarter", "Last Quarter" "This Year", "Last Year", "Custom Range") that users can easily select without having to manually adjust the date slicer.

 

2. Dynamic Date Axis:

I need a date axis in my visuals that dynamically adjusts based on the selected date range, with specific behavior as follows:

  • If "Today" or "Yesterday" is selected, the axis should display Hour.
  • If "This Week" or "Last Week" is selected, the axis should display Date.
  • If "This Month" or "Last Month" is selected, the axis should display Week.
  • If "This Quarter" or "Last Quarter" is selected, the axis should display Month.
  • If "This Year" or "Last Year" is selected, the axis should display Month.
  • If a "Custom Range" is selected, the axis should:
    • Display Month if the selection is greater than 12 months.
    • Display Date if the selection is less than 12 months.

These are useful, but i want them both combined and working "

https://www.youtube.com/watch?v=fKygF7VEJnQ

https://www.youtube.com/watch?v=hilfglpKNRQ

"

Could someone guide me on the best way to implement these functionalities? Any step-by-step approach, DAX expressions, or examples would be greatly appreciated.

 

Thanks in advance for your help!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @manoj_0911 ,

I created some data:

vyangliumsft_0-1726126181294.png

Here are the steps you can follow:

1. Modeling – New parameter -- Fields.

vyangliumsft_3-1726126198590.png

vyangliumsft_4-1726126198591.png

2. Create measure.

 

Flag =
var _selectgroup=SELECTEDVALUE('Group_Table'[Group])
var _selectparameter=SELECTEDVALUE('Parameter'[Parameter])
var _parameterfield=SELECTEDVALUE('Parameter'[Parameter Fields])
var _today=TODAY()
return
SWITCH(
    TRUE(),
_selectgroup="This Year"&&CONTAINSSTRING(_parameterfield,"Year")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today),1,
_selectgroup="Last Year"&&CONTAINSSTRING(_parameterfield,"Year")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)-1,1,
_selectgroup="This Week"&&CONTAINSSTRING(_parameterfield,"Date")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)&&WEEKNUM(MAX('Table'[Date]),2)=WEEKNUM(_today,2),1,
_selectgroup="Last Week"&&CONTAINSSTRING(_parameterfield,"Date")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)&&WEEKNUM(MAX('Table'[Date]),2)=WEEKNUM(_today,2)-1,1,
_selectgroup="This Month"&&CONTAINSSTRING(_parameterfield,"Week")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)&&MONTH(MAX('Table'[Date]))=MONTH(_today),1,
_selectgroup="Last Month"&&CONTAINSSTRING(_parameterfield,"Week")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)&&MONTH(MAX('Table'[Date]))=MONTH(_today)-1,1,0)

 

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_5-1726126218129.png

4. Result:

 

vyangliumsft_6-1726126218135.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi  @manoj_0911 ,

I created some data:

vyangliumsft_0-1726126181294.png

Here are the steps you can follow:

1. Modeling – New parameter -- Fields.

vyangliumsft_3-1726126198590.png

vyangliumsft_4-1726126198591.png

2. Create measure.

 

Flag =
var _selectgroup=SELECTEDVALUE('Group_Table'[Group])
var _selectparameter=SELECTEDVALUE('Parameter'[Parameter])
var _parameterfield=SELECTEDVALUE('Parameter'[Parameter Fields])
var _today=TODAY()
return
SWITCH(
    TRUE(),
_selectgroup="This Year"&&CONTAINSSTRING(_parameterfield,"Year")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today),1,
_selectgroup="Last Year"&&CONTAINSSTRING(_parameterfield,"Year")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)-1,1,
_selectgroup="This Week"&&CONTAINSSTRING(_parameterfield,"Date")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)&&WEEKNUM(MAX('Table'[Date]),2)=WEEKNUM(_today,2),1,
_selectgroup="Last Week"&&CONTAINSSTRING(_parameterfield,"Date")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)&&WEEKNUM(MAX('Table'[Date]),2)=WEEKNUM(_today,2)-1,1,
_selectgroup="This Month"&&CONTAINSSTRING(_parameterfield,"Week")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)&&MONTH(MAX('Table'[Date]))=MONTH(_today),1,
_selectgroup="Last Month"&&CONTAINSSTRING(_parameterfield,"Week")=TRUE()&&YEAR(MAX('Table'[Date]))=YEAR(_today)&&MONTH(MAX('Table'[Date]))=MONTH(_today)-1,1,0)

 

3. Place [Flag]in Filters, set is=1, apply filter.

vyangliumsft_5-1726126218129.png

4. Result:

 

vyangliumsft_6-1726126218135.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

Top Solution Authors
Top Kudoed Authors