3 Replies Latest reply on Apr 4, 2018 1:08 PM by Michael Niven

    How do I write the following without FOR statements?

    Michael Niven

      So let's say I have a dataset with the following:

       

      COLUMN A               COLUMN B    

      Fiscal Period             Total Sales

      201801                      1

      201802                      3

      201803                      19

      201804                      5

      201805                      6

       

      I am trying to create 3 calculated fields that sum the above as follows:

       

      • Latest Period
      • Last 4 Periods
      • Year-to-Date

       

      How would I get it to do this? I noticed Tableau doesn't seem to have FOR statements. Below is my thought process if FOR statements were possible (feel free to correct me):

       

      1. Create a Calculated field, "Max Period".
           {Fixed:max([Fiscal Period])}

       

      Latest Period:

      FOR(INT([Max Period]) = INT([Fiscal Period]))

           SUM([Total Sales]

       

      Last 4 Periods:

      FOR(INT([Fiscal Period]) >= [Max Period] - 3)

           SUM([Total Sales])

       

      Year-to-Date

      FOR(LEFT([Fiscal Period]),4) = "2018")

           SUM([Total Sales])

       

      I think this logic is right, but I'm wondering how to get it to translate this correctly into Tableau? My desired output (well, a very simplified version) is as follows:

       

       

      Latest PeriodLast 4 PeriodsYear-to-Date
      63334