1 Reply Latest reply on Aug 21, 2016 7:48 PM by S D

    Immediate Friday of current date

    S D

      Hi There,

      We have a requirement to show the immediate Friday for provided date in data source instead of actual date of transaction. Below is the code to derive the same using  the tableau date function(Datename).

       

      Immediate Friday Date :-

      if datename('weekday',max([Date])) = 'Friday' then max([Date])

      else if datename('weekday',max([Date])) = 'Monday' then date(max([Date]) + 4)

      else if datename('weekday',max([Date])) = 'Tuesday' then date(max([Date]) +3)

      else if datename('weekday',max([Date])) = 'Wednesday' then date(max([Date]) +2)

      else if datename('weekday',max([Date])) = 'Thursday' then date(max([Date]) +1)

      else if datename('weekday',max([Date])) = 'Saturday' then date(max([Date]) +6)

      else if datename('weekday',max([Date])) = 'Sunday' then date(max([Date]) +7)

      end end end end end end end

       

      Hope this helps other to derive date for such kind of requirements.

       

      Thanks & regards,

      SD

        • 1. Re: Immediate Friday of current date
          S D

          Better Performing Case statement to achieve Immediate Friday for give date. 

           

          CASE datename('weekday',max([Date]))

          WHEN 'Friday' then max([Date])

          WHEN 'Monday' then date(max([Date]) +4)

          WHEN 'Tuesday' then date(max([Date]) +3)

          WHEN 'Wednesday' then date(max([Date]) +2)

          WHEN 'Thursday' then date(max([Date]) +1)

          WHEN 'Saturday' then date(max([Date]) +6)

          WHEN 'Sunday' then date(max([Date]) +5)

          END

          @SD

          1 of 1 people found this helpful