Forum Discussion

StoryDashboard's avatar
StoryDashboard
Frequent Visitor
7 years ago
Solved

Datediff range category defined by selectedvalue

Hi,   We all know the Datadiff function where we show the time difference between two dates. Of course we can calculate the difference in days, months etc.... But if I want the user to choose thei...
  • PattemManohar's avatar
    PattemManohar
    7 years ago

    StoryDashboard  As I've mentioned above, I've implemented the same for DateAdd and thought you will follow the same logic for DateDiff.... Anyway, here is the logic for Datediff.... Same Table Visual will show the dates difference in different values based on the type selection. Create a New Measure as below

     

    Test278_1 = 
    VAR _Selection = SELECTEDVALUE(Test278Type[Type])
    VAR _DateVal = MAX(Test278DateDiffDynamic[Date])
    VAR _Day = DATEDIFF(_DateVal,NOW(),DAY)
    VAR _Week = DATEDIFF(_DateVal,NOW(),WEEK)
    VAR _Month = DATEDIFF(_DateVal,NOW(),MONTH)
    VAR _Year = DATEDIFF(_DateVal,NOW(),YEAR)
    VAR _Quarter = DATEDIFF(_DateVal,NOW(),QUARTER)
    
    RETURN 
    SWITCH(_Selection,
            "DAY",_Day,
            "WEEK",_Week,
            "MONTH",_Month,
            "QUARTER",_Quarter,
            "YEAR",_Year
          )