Professional Documents
Culture Documents
User-defined Fields
Ramesh Kandela
rkandela@gitam.edu
Create a Simple Calculated Field
• Sometimes data source does not contain a field (or column) that you need for your
analysis.
• For example, your data source might contain fields with values for Sales and Profit,
but not for Profit Ratio. If this is the case, we can create a calculated field for Profit
Ratio using data from the Sales and Profit fields.
Step 1: Create the calculated field
• In a worksheet in Tableau, select Analysis > Create Calculated Field.
• In the Calculation Editor that opens, give the calculated field a name.
• In this example, the calculated field is called Profit Ratio.
Step 2: Enter a formula
Step 2: Enter a formula
1.In the Calculation Editor, enter a formula.
SUM([Profit])/SUM([Sales])
• Formulas use a combination of functions, fields, and operators.
• There are four basic components to calculations in Tableau:
• Functions - Statements used to transform the values or members in a field.
• Fields - Dimensions or measures (columns) from your data source.
• Operators - Symbols that denote an operation.
• Literal expressions - Constant values that are represented “as is”, such as "Profitable" and
"Unprofitable".
• When finished, click OK. The new calculated field is added to the Data pane. If the new field
computes quantitative data, it is added to Measures. If it computes qualitative data, it is
added to Dimensions.
Functions in Tableau
• Tableau supports many functions for use in Tableau calculations. Any data analysis
involves a lot of calculations. In Tableau, the calculation editor is used to apply
calculations to the fields being analyzed. Tableau has a number of inbuilt functions which
help in creating expressions for complex calculations.
• Number Functions
• String Functions
• Date Functions
• Aggregate Functions
• Logical Functions
• Type Conversion Functions
Number Functions
These built-in functions in Tableau allow to perform computations on the data values in fields. Number
functions can only be used with fields that contain numerical values.
SQRT
This function returns the square root of the given number.
Syntax
SQRT(number)
SQRT(25) = 5
MAX
• MAX(number, number)
• Returns the maximum of the two arguments, which must be of the same type. Returns Null if either
argument is Null. MAX can also be applied to a single field in an aggregate calculation.
Example
• Max(Sales,Profit)
Max(23,10)=23
ROUND
• ROUND(number, [decimals])
• Rounds numbers to a specified number of digits. The decimals argument specifies
how many decimal points of precision to include in the final result. If decimals is
omitted, number is rounded to the nearest integer.
• Example:
• This example rounds every Sales value to an integer:
• ROUND(Sales)
Aggregate Functions
• These built-in functions in Tableau allow to summarize or change the granularity
of data.
AVG: This function returns the mean of all the values in an expression, ignoring
the NULL values. AVG can be used with numeric fields only.
Syntax
AVG(expression)
CORR: This calculation returns the Pearson correlation coefficient of two
expressions.
Syntax
CORR(expr1, expr2)
COUNT
• Returns the number of items in a group. Null values are not counted.
• COUNT(expression)
COUNTD
• Returns the number of distinct items in a group. Null values are not counted.
• COUNTD(expression)
STDEV
• Returns the statistical standard deviation of all values in the given expression based on a sample of
the population.
• STDEV(expression)
MAX
• Returns the maximum of an expression across all records. If the expression is a string value, this
function returns the last value where last is defined by alphabetical order.
• MAX(expression)
String Functions
String functions are used to manipulate string data (i.e. data made of text).
LEN
Returns the length of the string.
LEN (string)
Example
LEN("Tableau") = 7
Manipulating Text
• At times, we are required to parse or manipulate text variables to get something meaningful out of those
variables; for example, a Full Name field may contain both the first name and last name of a sales
representative, but our reporting standards may require us to show two different columns for the first and last
names. With Tableau's string operators, we can easily manipulate the text to meet our requirements.
• To extract the customer's last name, right-click on Customer from Dimensions and select Create Calculated
Field.
• In the Name box, enter Customer Last Name.
• In the formula, SPLIT([Customer Name], ' ', 2)
The calculation might look something like this: SPLIT(‘Ramesh Kandela' , ' ', 2) = Kandela'.
UPPER
• UPPER(string)
• Returns string, with all characters uppercase.
• Example:
• UPPER(“Ramesh Kandela") = “RAMESH KANDELA"
Date Functions
• Type conversion functions allow to convert fields from one data type to another.
For example, you can convert numbers to strings, such as age values (numbers) to string
values so that Tableau does not try to aggregate them.
• The calculation for such a task might look similar to the following:
STR([Age])
Percentage options
• Percent of Table
• Percent of Column
• Percent of Row
• Percent of Pane
• Percent of Row in Pane
• Percent of Column in Pane
• Percent of Cell
Percent of Table