Calculations in Tableau
Maarten Van den Broeck
Content Developer at DataCamp
Time series analysis - study of data in particular periods or intervals, which often includes trend analysis, seasonal comparisons of data and study of rolling time-periods
Date or DateTime data types:
Date can have various output formats:
Example:
MakeDate ([Year], [Month], [Day])
MakeTime ([Hour], [Minute], [Second])
MakeDateTime ([Date], [Time])
Parsing: analyzing a string into logical syntactic components
Example:
DateParse ( format, string )
Extracting a discrete year, but also possible with quarter, month, day, dayofyear, weekday, hour, minute, etc.
Example:
DATEPART ( 'year', [Order Date] )
DATEPART ( 'quarter', [Order Date] )
Truncating: shortening, cutting
Truncating the specified date to the accuracy specified by the date part.
DATETRUNC ( 'month', #2022-06-15# )
DATETRUNC ( 'quarter', #2022-06-15# )
Adding intervals to dates:
DATEADD (date_part, interval, [Date])
Adds specified amount of intervals (e.g., 3 months, 2 days, 10 weeks, etc.) to the date
Subtracting intervals from dates:
DATEDIFF ( date_part, date1, date2 )
E.g.
DATEADD ('month', 3, [Date])
DATEADD ('week', 10, [Date])
Returns a date
E.g.
DATEDIFF ('month', [Start], [End])
DATEDIFF ('day', [Start], [End])
Using hard-coded dates in calculations:
Enclose the date value between # #
E.g. #2010-12-31#
Calculations in Tableau