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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
ayanke
Regular Visitor

Button to Select Most Recent Date in a Dynamic Slicer

Greetings! 

 

I have been requested to create a button, called "Get Latest", that selects year and week number in their respective slicer panels. As the button's name suggests, selecting the button should make the most recent selection of year and week number (i.e., this week). To make a slicer selection from a button, I'd normally use a bookmark, but a bookmarked selection is always fixed to the values selected upon creation. My slicers for year & week number are dynamic, so the selection of the most recent year & week number will change as time progresses. Do you know how I can create a button that selects the most recent year & week number in a dynamically updated slicer?

 

Thanks, 

 

Andrew

1 ACCEPTED SOLUTION

Thank you @MFelix for the quick response. You definitely gave me a good starting point and came a solution, shown below. I had to make one modification to your pseudocode. The Table[Week]=MAX( Slicer[Week] ) part is not valid within the CALCULATE function because it throws an error related to using a boolean expression and table filtering at the same time.

 

My solution is the following:

 

 

Sales = 

VAR maxyear = MAX(Table[Year])
VAR maxweek= CALCULATE(MAX(Table[Week]),FILTER(Table,Table[Year]=maxyear ))

RETURN
 SWITCH(TRUE(),
    NOT(ISFILTERED(Table[Week])) && NOT(ISFILTERED(Table[Year])),
    CALCULATE(SUM(Table[Sales]),
        FILTER(Table,Table[Year]=maxyear && Table[Week]=maxweek)
        ),
    SUMX(Table,[Sales])
 )

 

 

View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi  @ayanke ,

 

Believe that the best option is to have your slicer not having any selections and if this happens then you get the most recent data on the visualizations.

 

I don't know how your model is setup but let's assume you have a visualization with the sales on a card if you do a measure similar to this:

Sales =
SWITCH (
    TRUE ();
    DISTINCTCOUNT ( SlicerTable[Week] )
        = CALCULATE ( DISTINCTCOUNT ( SlicerTable[Week] ) ); ALL ( SlicerTable[Week] );
    CALCULATE (
        SUM ( Table[Sales] );
        Table[Week] = MAX ( Slicer[Week] )
            && Table[Year] = MAX ( Slicer[Year] )
    )
)

In this case if you have no selection or all the rows selected for week it will return sales for maximum week and year.

 

Be aware that this formula may not work properly since it was made by heart and this needs to be adjusted to your calculations.

 

Another option can be create a filtering measure that checks if all weeks/years or more than one is selected and return the latest values for dates and filter you page base on that.

 

And then create a button that reset your slicers.

 

Believe this is a better option than always selecting the latest week as you refer bookmarks are not dinamic.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thank you @MFelix for the quick response. You definitely gave me a good starting point and came a solution, shown below. I had to make one modification to your pseudocode. The Table[Week]=MAX( Slicer[Week] ) part is not valid within the CALCULATE function because it throws an error related to using a boolean expression and table filtering at the same time.

 

My solution is the following:

 

 

Sales = 

VAR maxyear = MAX(Table[Year])
VAR maxweek= CALCULATE(MAX(Table[Week]),FILTER(Table,Table[Year]=maxyear ))

RETURN
 SWITCH(TRUE(),
    NOT(ISFILTERED(Table[Week])) && NOT(ISFILTERED(Table[Year])),
    CALCULATE(SUM(Table[Sales]),
        FILTER(Table,Table[Year]=maxyear && Table[Week]=maxweek)
        ),
    SUMX(Table,[Sales])
 )

 

 

Hi  @ayanke ,

 

As I refered Iwas doing it by heart, and without any data just putting out some workaroudn, glad I could help achieve a good result.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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