Calculations in Tableau
Agata Bak-Geerinck
Senior Data Analyst, Telenet
Data type - an attribute of a piece of data that tells a computer how to interpret its value.
Structured data sources: one column = one data type.
String - a sequence of one or more letters, numbers or other characters.
Examples of string data:
In calculations, string values are enclosed in " "
.
IF [Word] = "Apple" THEN "Fruit" END
+
Concatenation - joining two or more strings end-to end:
SPLIT()
- extracting parts of a string based on a delimiter:
LEFT()
, RIGHT()
, MID()
- extract requested, fixed number of characters, based on the position in the string:
Logical functions allow to determine if a certain condition is true or false and returns a requested value based on evaluation.
Boolean (True/False) conditions:
[Low activity ratio] < 0.1
returns "TRUE" or "FALSE"Possible to include several checks in the same condition, adding AND OR statements:
([Gender]="Female" AND [Age] = 30) OR ( [Gender]="Male" AND [Age] = 35 )
Negation:
[Category] = "Busy Mum" AND NOT [Occupation] = "Clerk"
[Category] = "Busy Mum" AND [Occupation] != "Clerk"
[Category] = "Busy Mum" AND [Occupation] <> "Clerk"
IF function:
IF test1 THEN ____ END
IF test1 THEN ____ ELSE ____ END
IF test1 THEN ____ ELSEIF ____ THEN ____ ELSE ____ END
IIF function
IIF (test, ____ , ____)
CASE function
CASE ____ WHEN ____ THEN ____ WHEN ___ THEN ____ ELSE ____ END
IF
allows algebra conditions, e.g :
IIF()
allows algebra conditions, e.g :
CASE
searches for an exact match, e.g :
ISNULL, ISDATE - checks if a value is "Null" or a date:
ISNULL([Steps])
returns "TRUE" or "FALSE"ISDATE([Activity Date])
returns "TRUE"IFNULL - checks if a value is "Null" and controls the output:
IFNULL ([Steps], 0)
IFNULL ([Steps], "No steps")
ZN - returns a 0
if a value is "Null"
ZN([Steps])
returns 0
Calculations in Tableau