1 Reply Latest reply on Jan 13, 2017 3:16 AM by Andrew Watson

    Current week/Previous week difference

    Giulia Viotto

      Hi Guys,


      I need to create 2 calculated fields for sessions Previous Week and Sessions Current Week but I am missing the exact function to use.

      At the beginning of the year, in order to compute the end of 2016 and the beginning of 2017 I created a calculated field containing DATETRUNC, and that is the same field I am using to define weeks in tableau for my weekly reports.


      Since to create Current Week and Previous Week the function to use is DATEPART, I think I am missing a step and I need to create a different calculated field out of my DATETRUNC before being able to create the other 2 I need to my analysis (current week/previous week).


      Does anyone have any tips for me?

      Thank you!

        • 1. Re: Current week/Previous week difference
          Andrew Watson

          Without data will guess at your field names. You can create calculated fields to have sessions for this week and sessions for last week:


          ThisWeek: IF DATETRUNC('week',[DateField]) = DATETRUNC('week',TODAY()) THEN [Sessions] END

          LastWeek: IF DATETRUNC('week',[DateField]) = DATETRUNC('week',DATEADD('week',-1,TODAY())) THEN [Sessions] END


          You can them use them to do any week on week calculations, for example SUM([ThisWeek]) - SUM([LastWeek])