6 Replies Latest reply on Jun 19, 2018 11:33 AM by Ken Flerlage

    Using DATEDIFF with CASE statement in Tableau

    Anjali Sn

      I'm trying to do the following calculation:

       

      DATEDIFF(CASE [Period] WHEN 'Day' THEN 'day' WHEN 'Week' THEN 'week' ELSE 'year' END, {EXCLUDE : MIN([Date])}, {EXCLUDE : MAX([Date])})

       

      Where Period is a Parameter with values 'Day', 'Week', 'Year' etc. I want to use CASE statement for the "date_part" in the DATEDIFF statement. Is it possible to do so?

       

      If not, then how can I achieve this calculation? I can't change the Parameter values to 'day', 'week' etc. because that breaks other worksheets, don't know why :/

       

      Please help.