Forum Discussion

murphm6's avatar
murphm6
Helper II
3 years ago
Solved

Dynamically change card visual based on date selection

Hey all,

 

I have a card visual which displays the 'Days Left in Month'. This is a measure that just takes the date difference between today and EOMONTH. 

 

My end-user wants to be able to see what numbers for next month look like. When they filter for Next Month in the 'Date Selection' filter, the 'Days left in Month' visual still only show the date diff between today and end of current month.

 

How can I set it up so that this visual will dynamically change? If they're looking at current month, it will take the date diff between today and end of month. And if they're looking at next month, it will just calculate total days in the month? I think a SWITCH() function will be used here, but not sure how to implement this.

 

 

 

  • rsbin's avatar
    rsbin
    3 years ago

    murphm6 ,

    You are close.   Please try this:

    DaysLeftinMonth = SWITCH(
                          TRUE(),
                          [MaxSelectedDate] = EOMONTH( TODAY(), 0 ), DATEDIFF( TODAY(), (EOMONTH( TODAY(), 0 )), DAY ),
                          DAY(EOMONTH(TODAY(), 1) ))
    
    Where
    MaxSelectedDate = MAX(DIM_Date[Date] )

    My quick test shows it works, but may need tweaking depending on how many Months in the future the user selects.

    Hope you can get this to work for you.

    Regards,

2 Replies

  • Switch(SELECTEDVALUE('Calendar'[Date]), MONTH(TODAY()), DATEDIFF(TODAY(), EOMONTH(TODAY(), 0), DAY), MONTH(TODAY()+1), Day(EOMONTH(TODAY() + 1,0)))

     

    Tried using this, but doesn't seem to be working correctly. Anyone have any suggestions?

    • rsbin's avatar
      rsbin
      Community Champion

      murphm6 ,

      You are close.   Please try this:

      DaysLeftinMonth = SWITCH(
                            TRUE(),
                            [MaxSelectedDate] = EOMONTH( TODAY(), 0 ), DATEDIFF( TODAY(), (EOMONTH( TODAY(), 0 )), DAY ),
                            DAY(EOMONTH(TODAY(), 1) ))
      
      Where
      MaxSelectedDate = MAX(DIM_Date[Date] )

      My quick test shows it works, but may need tweaking depending on how many Months in the future the user selects.

      Hope you can get this to work for you.

      Regards,