Forum Discussion

ayanke's avatar
ayanke
Regular Visitor
6 years ago
Solved

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...
  • ayanke's avatar
    ayanke
    6 years ago

    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])
     )