KNOWLEDGE BASE

Creating Year To Date and Month To Date Calculations


Published: 11 Mar 2017
Last Modified Date: 12 Nov 2018

Question

How to create and display Year to Date and Month to Date calculations. 

Environment

Tableau Desktop

Answer

Option 1 (YTD)

  1. Select Analysis Create Calculated Field 
  2. Name the field YTD Sales, enter the following calculation, then click OK: 
    [Order Date] <= TODAY() AND
    DATETRUNC( "year", [Order Date]) = DATETRUNC("year", TODAY() )
  3. Drag YTD onto the filter shelf and select "True"

Option 2 (MTD)

  1. Select Analysis Create Calculated Field 
  2. Name the field MTD Sales, enter the following calculation, then click OK: 
    [Order Date] <= TODAY() AND
    DATETRUNC( "month", [Order Date]) = DATETRUNC("month", TODAY() )
  3. Drag MTD onto the filter shelf and select "True"

Option 3 (Dynamic MTD/YTD)

  1. Create a parameter and name it "YTD/MTD" - String
  2. Create a parameter and name it "Anchor Date" - Date
  3. Create a parameter and name it "Offset" - Int
  4. Select Analysis Create Calculated Field 
  5. Name the field Dynamic Sales, enter the following calculation, then click OK: 
    [Order Date] <= DATEADD( [Date Part],[Offset], [Anchor Date] ) AND
    DATETRUNC( [Date Part], [Order Date]) = DATETRUNC([Date Part], DATEADD([Date Part], [Offset], [Anchor Date] ))
  6. Drag MTD onto the filter shelf and select "True"
Did this article resolve the issue?