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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
Anonymous
Not applicable

To create a Date Slicer

I wanted to create  a date slicer of Today, last 2 days ,this week and this month
can anybody pls explain

And the slicer order should be in
  Today
  Last 2 days
  this week and
 this month

 

@PowerBI @powerbi3 @BI @Powerbidesign @Anonymous 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @Anonymous ,

1. first use enter data to create a new table like:

vcgaomsft_0-1667891008346.png

2. then please new a measure like:

 

Measure = 
VAR _SLICER = MAX('Table'[Slicer])
VAR _TODAY = TODAY()
VAR _DATE = MAX('Calendar'[Date])
VAR _LAST_2_DAYS = TODAY() - 2
VAR _FIRSTDATEOFWEEK = TODAY() - WEEKDAY(TODAY(),2)
VAR _MONTH = MONTH(_TODAY)
VAR _YEAR = YEAR(_TODAY)
VAR _FILTER = 
SWITCH(
    TRUE(),
    _SLICER = "Today"&&_DATE=_TODAY,1,
    _SLICER = "Last 2 days"&&_DATE>=_LAST_2_DAYS&&_DATE<_TODAY,1,
    _SLICER = "This week"&&_DATE>=_FIRSTDATEOFWEEK&&_DATE<_FIRSTDATEOFWEEK+7,1,
    _SLICER = "This month"&&_YEAR=YEAR(_DATE)&&_MONTH=MONTH(_DATE),1
)   
RETURN
_FILTER

 

3. apply it to the filter:

vcgaomsft_1-1667891091096.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

View solution in original post

Anonymous
Not applicable

Hi @Anonymous ,

vcgaomsft_0-1667897695940.png

 

Best Regards,
Gao

Community Support Team

View solution in original post

8 REPLIES 8
amitchandak
Super User
Super User

@Anonymous , You need a date table and one table with all these values

 

measure

 

Switch Period =
var _max = if(isfiltered('Date'),MAX( 'Date'[Date]) , today()),
var _min =
SWITCH(SELECTEDVALUE(Period[PeriodType])
"today",today()
"Last 2 days",eomonth(_max,-1* if( mod(Month(_max),3) =0,3,Month(_max)))+1,
"this week",_max -1*weekday(_max,-1)+1 ,
"this month",eomonth(_max,-1)+1 ,
BLANK())
return
CALCULATE(Sum(Sales[Sales[Amount]),DATESBETWEEN('Date'[Date],_min,_max))

 

 

refer for the period type

https://medium.com/chandakamit/power-bi-when-i-felt-lazy-and-i-needed-too-many-measures-ed8de20d9f79

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
Anonymous
Not applicable

@amitchandak  can you pls explain
and i even want to add custom date picker also
like and it should be in this order:
  Today
  Last 2 days
  this week 
  this month and 
custom(date picker)


when i clicked custom (date picker) it should display date picker 
any idea?
and  i even created a date picker but when i click year it doesn't show all the years

@WarrenBelz  @iAm_ManCat @Anonymous @BI @andres777 

 

Anonymous
Not applicable

Hi @Anonymous ,

1. first use enter data to create a new table like:

vcgaomsft_0-1667891008346.png

2. then please new a measure like:

 

Measure = 
VAR _SLICER = MAX('Table'[Slicer])
VAR _TODAY = TODAY()
VAR _DATE = MAX('Calendar'[Date])
VAR _LAST_2_DAYS = TODAY() - 2
VAR _FIRSTDATEOFWEEK = TODAY() - WEEKDAY(TODAY(),2)
VAR _MONTH = MONTH(_TODAY)
VAR _YEAR = YEAR(_TODAY)
VAR _FILTER = 
SWITCH(
    TRUE(),
    _SLICER = "Today"&&_DATE=_TODAY,1,
    _SLICER = "Last 2 days"&&_DATE>=_LAST_2_DAYS&&_DATE<_TODAY,1,
    _SLICER = "This week"&&_DATE>=_FIRSTDATEOFWEEK&&_DATE<_FIRSTDATEOFWEEK+7,1,
    _SLICER = "This month"&&_YEAR=YEAR(_DATE)&&_MONTH=MONTH(_DATE),1
)   
RETURN
_FILTER

 

3. apply it to the filter:

vcgaomsft_1-1667891091096.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly -- How to provide sample data

Anonymous
Not applicable

Hi @Anonymous  I did the exact same thing but it didnt show in order

can you pls tell me where did i miss

Anonymous
Not applicable

Hi @Anonymous ,

vcgaomsft_0-1667897695940.png

 

Best Regards,
Gao

Community Support Team

Anonymous
Not applicable

Thank you so much @Anonymous 
and i would like include  date picker also such as:

  Today
  Last 2 days
  this week 
  this month 

is working perfectly fine ...

 

is there anyway that we could include Custom(Date picker) in the same slicer ?

 

Thanks in Advance !!!

 @Anonymous @Eyelyn9 @BI @andres777 

Anonymous
Not applicable

Hii @Anonymous
  

Is it possible to include custom(date picker) in the same slicer


 @amitchandak @Greg_Deckler @Shaurya @BI 

Anonymous
Not applicable

Hi @Anonymous ,

Do you mean adding another such slicer to the inside? Unfortunately, this is not possible at the moment.😥

vcgaomsft_0-1667972893484.png

 

Best Regards,
Gao

Community Support Team

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.