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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
mazeed92
Frequent Visitor

Filtering data for Monthly and yesterday on the visuals based on button selection

Hi,
I have developed the report like below. Now I want to keep two button on this page, 1. Month 2.Yesterday. Based on the selection on the button, data should be shown on the visuals on the entire page.

1. Month button - Month to Date

2. Yesterday button - To show the yesterday data (Availble previous date from the MaxDate)

 

mazeed92_1-1750155610000.png

 

Please help on this

 

Thanks

Abdul

2 ACCEPTED SOLUTIONS
pankajnamekar25
Super User
Super User

Hello @mazeed92 

Try this

 implement a toggle between "Month to Date" and "Yesterday" in Power BI using buttons, you can follow this method entirely within one page using DAX and a disconnected table.

First, create a disconnected table to act as your toggle selector. Go to the Modeling tab and create a new table with this DAX:

DateFilter =

DATATABLE(

    "Period", STRING,

    {

        {"Month"},

        {"Yesterday"}

    }

)

This table will not be related to any other table in your model. Add this DateFilter[Period] column to a slicer visual, format it horizontally, and style it like buttons.

Now, create a measure that adjusts based on the selected period. Here’s an example for sales or amount collected:

SelectedAmount =

VAR SelectedPeriod = SELECTEDVALUE(DateFilter[Period])

VAR MaxDate = MAX('Date'[Date])

RETURN

    SWITCH(

        SelectedPeriod,

        "Month", CALCULATE(SUM('Sales'[Amount]), DATESMTD('Date'[Date])),

        "Yesterday", CALCULATE(SUM('Sales'[Amount]), 'Date'[Date] = MaxDate - 1)

    )

You can replicate similar logic for other KPIs. For example, if you have a KPI for Total Customers:

SelectedTotalCustomers =

VAR SelectedPeriod = SELECTEDVALUE(DateFilter[Period])

VAR MaxDate = MAX('Date'[Date])

RETURN

    SWITCH(

        SelectedPeriod,

        "Month", CALCULATE(SUM('CustomerData'[TotalCustomers]), DATESMTD('Date'[Date])),

        "Yesterday", CALCULATE(SUM('CustomerData'[TotalCustomers]), 'Date'[Date] = MaxDate - 1)

    )

Make sure your 'Date' table is marked as a date table and is properly related to your fact tables like 'Sales' or 'CustomerData'.

Once these measures are created, replace your existing measures in the visuals with these dynamic ones. Now, when the user selects either "Month" or "Yesterday" from the slicer, the entire page will update accordingly, showing the correct data context.

 

 

Thanks 

Pankaj Namekar | LinkedIn

If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

View solution in original post

Hi @mazeed92,

Thanks for reaching out to the Microsoft fabric community forum.

 

Yes, this method works with DirectQuery as well. Since the toggle is handled by DAX measures, all visuals on the page including Pie Charts and Bar Charts will update automatically based on the selected option (Month or Yesterday).

 

Just make sure you’re using the dynamic measures in the visual’s Values field.

 

The disconnected table is only used for selection it won’t affect the visuals directly, but your measures will control what data is shown.

The only thing to watch for is that DirectQuery might have some delay depending on your data source size, but functionally it works fine.

 

If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so

 other members can easily find it.

 

Best Regards,
Tejaswi.

 

 

 

View solution in original post

3 REPLIES 3
pankajnamekar25
Super User
Super User

Hello @mazeed92 

Try this

 implement a toggle between "Month to Date" and "Yesterday" in Power BI using buttons, you can follow this method entirely within one page using DAX and a disconnected table.

First, create a disconnected table to act as your toggle selector. Go to the Modeling tab and create a new table with this DAX:

DateFilter =

DATATABLE(

    "Period", STRING,

    {

        {"Month"},

        {"Yesterday"}

    }

)

This table will not be related to any other table in your model. Add this DateFilter[Period] column to a slicer visual, format it horizontally, and style it like buttons.

Now, create a measure that adjusts based on the selected period. Here’s an example for sales or amount collected:

SelectedAmount =

VAR SelectedPeriod = SELECTEDVALUE(DateFilter[Period])

VAR MaxDate = MAX('Date'[Date])

RETURN

    SWITCH(

        SelectedPeriod,

        "Month", CALCULATE(SUM('Sales'[Amount]), DATESMTD('Date'[Date])),

        "Yesterday", CALCULATE(SUM('Sales'[Amount]), 'Date'[Date] = MaxDate - 1)

    )

You can replicate similar logic for other KPIs. For example, if you have a KPI for Total Customers:

SelectedTotalCustomers =

VAR SelectedPeriod = SELECTEDVALUE(DateFilter[Period])

VAR MaxDate = MAX('Date'[Date])

RETURN

    SWITCH(

        SelectedPeriod,

        "Month", CALCULATE(SUM('CustomerData'[TotalCustomers]), DATESMTD('Date'[Date])),

        "Yesterday", CALCULATE(SUM('CustomerData'[TotalCustomers]), 'Date'[Date] = MaxDate - 1)

    )

Make sure your 'Date' table is marked as a date table and is properly related to your fact tables like 'Sales' or 'CustomerData'.

Once these measures are created, replace your existing measures in the visuals with these dynamic ones. Now, when the user selects either "Month" or "Yesterday" from the slicer, the entire page will update accordingly, showing the correct data context.

 

 

Thanks 

Pankaj Namekar | LinkedIn

If this solution helps, please accept it and give a kudos (Like), it would be greatly appreciated.

Thanks,I am connecting a DataSource via DirectQuery. How about the charts like Pie Charts, BarCharts used on the Page ?

Hi @mazeed92,

Thanks for reaching out to the Microsoft fabric community forum.

 

Yes, this method works with DirectQuery as well. Since the toggle is handled by DAX measures, all visuals on the page including Pie Charts and Bar Charts will update automatically based on the selected option (Month or Yesterday).

 

Just make sure you’re using the dynamic measures in the visual’s Values field.

 

The disconnected table is only used for selection it won’t affect the visuals directly, but your measures will control what data is shown.

The only thing to watch for is that DirectQuery might have some delay depending on your data source size, but functionally it works fine.

 

If the response has addressed your query, please Accept it as a solution and give a 'Kudos' so

 other members can easily find it.

 

Best Regards,
Tejaswi.

 

 

 

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