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

Add filter "buttons" on visuals

Hi,

I have a line chart showing everyday sales. I have filtered it to show last 14 days using the filter pane.

EashwarBalaji_0-1699439536661.png

Is there a way to add dynamic filter on the visual for the user to choose the number of days, they want to see the sales for.
For example, on google, you could see this on a line graph where you could filter the data for 1D/5D/1M/1Y and so on by the click of a button

EashwarBalaji_1-1699439676264.png

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1699595654940.png

(2) We can create a table.

Slicer = DATATABLE ( 
    "Slicer", STRING, 
    {
        { "1D" },
        { "5D" },
        { "1M" },
        { "1Y" },
        { "5Y" }
    }
)

(3)We can create a measure.

Flag = 
var _today=TODAY()
var _flag=SWITCH(TRUE(),
SELECTEDVALUE('Slicer'[Slicer])="1D" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= TODAY()-1,1,
SELECTEDVALUE('Slicer'[Slicer])="5D" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= TODAY()-5,1,
SELECTEDVALUE('Slicer'[Slicer])="1M" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= EDATE(TODAY(),-1),1,
SELECTEDVALUE('Slicer'[Slicer])="1Y" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY())),1,
SELECTEDVALUE('Slicer'[Slicer])="5Y" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= DATE(YEAR(TODAY())-5,MONTH(TODAY()),DAY(TODAY())),1,
ISFILTERED(Slicer[Slicer])=FALSE(),1,0)
return _flag

(4) Then the result is as follows.

vtangjiemsft_1-1699595926427.png

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. 

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1699595654940.png

(2) We can create a table.

Slicer = DATATABLE ( 
    "Slicer", STRING, 
    {
        { "1D" },
        { "5D" },
        { "1M" },
        { "1Y" },
        { "5Y" }
    }
)

(3)We can create a measure.

Flag = 
var _today=TODAY()
var _flag=SWITCH(TRUE(),
SELECTEDVALUE('Slicer'[Slicer])="1D" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= TODAY()-1,1,
SELECTEDVALUE('Slicer'[Slicer])="5D" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= TODAY()-5,1,
SELECTEDVALUE('Slicer'[Slicer])="1M" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= EDATE(TODAY(),-1),1,
SELECTEDVALUE('Slicer'[Slicer])="1Y" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY())),1,
SELECTEDVALUE('Slicer'[Slicer])="5Y" && MAX('Table'[Date])<=TODAY() && MAX('Table'[Date]) >= DATE(YEAR(TODAY())-5,MONTH(TODAY()),DAY(TODAY())),1,
ISFILTERED(Slicer[Slicer])=FALSE(),1,0)
return _flag

(4) Then the result is as follows.

vtangjiemsft_1-1699595926427.png

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. 

Anonymous
Not applicable

Ohh nevermind,

1) I just added an integer column, "Number" in the table creation query

EashwarBalaji_0-1699628049602.png

2) In Column tools pane of "Slicer", changed the Sort by column to "Number" 

EashwarBalaji_1-1699628191026.png

 

Anonymous
Not applicable

This works perfectly, just one thing, how do I add an integer column to the slicer table, I want to sort it using that column.

JohnnySaade
Helper I
Helper I

You can simply create identical charts and filter each of them on a specific period. Create a bookmark that will show and hide the charts and link each bookmark to a button that you will llay on top of the charts. P.S. have the charts overlaying each other 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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