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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Filter Date with Buttons

Hi, 

 

I really need help to create exactly the same thinng on this screenshot.  The requirement is the user when click on the button report should dipslays selected time period.  Even if I need to use DAX, please tell me step by step how I can do it. Here is screenshot and my data. 

 

Thank you,

 

timebuttons.PNG

 

 

data.PNG

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Step1: Create a table like below and use it as slicer.

Capture.PNG

Step2: Create a measure as below and add it to visual filter.

Measure = 
var _time = SELECTEDVALUE('Table'[Time])
var _period = SELECTEDVALUE(Slicer[period])
return
SWITCH(_period,"month",IF(_time>=EDATE(TODAY(),-1)&&_time<=TODAY()+1,1,0),
        "week",IF(_time>=TODAY()-7&&_time<=TODAY()+1,1,0),
        "12H",IF(_time>=TODAY()-2/24&&_time<=TODAY()+1,1,0),
        "24H",IF(_time>=TODAY()-1/24&&_time<=TODAY()+1,1,0))

Step3: Set filter value = 1.

1.PNG2.PNG

 

Best Regards,

Jay

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

 

Step1: Create a table like below and use it as slicer.

Capture.PNG

Step2: Create a measure as below and add it to visual filter.

Measure = 
var _time = SELECTEDVALUE('Table'[Time])
var _period = SELECTEDVALUE(Slicer[period])
return
SWITCH(_period,"month",IF(_time>=EDATE(TODAY(),-1)&&_time<=TODAY()+1,1,0),
        "week",IF(_time>=TODAY()-7&&_time<=TODAY()+1,1,0),
        "12H",IF(_time>=TODAY()-2/24&&_time<=TODAY()+1,1,0),
        "24H",IF(_time>=TODAY()-1/24&&_time<=TODAY()+1,1,0))

Step3: Set filter value = 1.

1.PNG2.PNG

 

Best Regards,

Jay

amitchandak
Super User
Super User

@Anonymous , You have create an independent table with these values.

And then measure to filter based on the selected value

 

Switch ( selectedvalues(Slicer[Slicer]) ,

"2 Hour", calculate(Countrows(Table), Filter(Table, Table[Endtime] >= Now() -2 &&  Table[Endtime] <=now()),

"4 Hour", calculate(Countrows(Table), Filter(Table, Table[Endtime] >= Now() -4 &&  Table[Endtime] <=now()),

"month", calculate(Countrows(Table), Filter(Table,eomonth( Table[Endtime],-1) = eomonth(today(),0)),

//Add others 

)

 

what we do for measure slicer

measure slicer
https://www.youtube.com/watch?v=b9352Vxuj-M
https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/500115
https://radacad.com/change-the-column-or-measure-value-in-a-power-bi-visual-by-selection-of-the-slicer-parameter-table-pattern

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  Thank you so much for repying! Please, can you give me more details? I never done before and I do not know where to start for this task. I will be happy if you really give more details step by step. Thank you.

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.