Calculated Field Function and Operator Reference for Amazon QuickSight
You can use the following functions and operators to create calculated fields.
For information on aggregating calculated fields, see Using Aggregate Functions in Calculated Fields . You can only aggregate calculated fields in an analysis, not in a data set.
Topics
Arithmetic and Comparison Operators
You can use the following arithmetic and comparison operators in calculated fields:

Addition (+)

Subtraction (−)

Multiplication (*)

Division (/)

Power (^)

Equal (=)

Not equal (<>)

Greater than (>)

Greater than or equal to (>=)

Less than (<)

Less than or equal to (<=)

AND

OR

NOT
Equal (=) and not equal (<>) comparisons are casesensitive. For
example, if the condition is state = 'WA'
and the value in the field is
wa
, those values are not considered to be equivalent.
Amazon QuickSight uses the standard order of operations: parentheses, exponents, multiplication, division, addition, subtraction.
To make lengthy calculations easier to read, you can use parenthesis to clarify groupings and precedence in calculations.
In the following statement, you don't need parentheses. The multiplication statement is processed first, and then the result is added to five, returning a value of 26. However, parentheses make the statement easier to read and thus maintain.
5 + (7 * 3)
Because parenthesis are first in the order of operations, you can change the order in which other operators are applied. For example, in the following statement the addition statement is processed first, and then the result is multiplied by three, returning a value of 36.
(5 + 7) * 3
Example: Arithmetic Operators
The following example uses multiple arithmetic operators to determine a sales total after discount.
(Quantity * Amount)  Discount)
Example: (=) Equal
Using = performs a casesensitive comparison of values. Rows where the comparison is TRUE are included in the result set.
In the following example, rows where the Region
field is
South
are included in the results. If the Region
is
south
, these rows are excluded.
Region = 'South'
In the following example, the comparison evaluates to FALSE.
Region = 'south'
The following example shows a comparison that converts Region
to all
uppercase (SOUTH
), and compares it to
SOUTH
. This returns rows where the region is
south
, South
, or
SOUTH
.
toUpper(Region) = 'SOUTH'
Example: (<>)
The not equal symbol <> means less than or greater than.
So, if we say x<>1
, then we are saying if x is less than 1 OR if x is greater than 1. Both < and
> are evaluated together. In other words, if x is any value
except 1. Or, x is not equal to 1.
Note
Use <>, not !=.
The following example compares Status Code
to a numeric value. This
returns rows where the Status Code
is not equal to
1
.
statusCode <> 1
The following example compares multiple statusCode
values. In this case,
active records have activeFlag = 1
. This example returns rows where one
of the following applies:

For active records, show rows where the status isn't 1 or 2

For inactive records, show rows where the status is 99 or 1
( activeFlag = 1 AND (statusCode <> 1 AND statusCode <> 2) ) OR ( activeFlag = 0 AND (statusCode= 99 OR statusCode= 1) )
Example: (^)
The power symbol ^
means to the power
of.
The following example is a simple expression of 2 to the power of 4 or (2 * 2 * 2 * 2). This returns a value of 16.
2^4
Example: AND, OR, and NOT
The following example uses AND, OR, and NOT to compare multiple expressions using conditional operators to tag top customers NOT in Washington or Oregon with a special promotion, who made more than 10 orders. If no values are returned, the value 'n/a' is used.
ifelse(( (NOT (State = 'WA' OR State = 'OR')) AND Orders > 10), 'Special Promotion XYZ', 'n/a')
Example: Creating Comparison Lists Like "in" or "not in"
This example uses operators to create a comparison to find values that exist, or don't exist, in a specified list of values.
The following example compares promoCode
a specified list of values.
This example returns rows where the promoCode
is in the list (1,
2, 3)
.
promoCode = 1 OR promoCode = 2 OR promoCode = 3
The following example compares promoCode
a specified list of values.
This example returns rows where the promoCode
is NOT in the list
(1, 2, 3)
.
NOT(promoCode = 1 OR promoCode = 2 OR promoCode = 3 )
Another way to express this is to provide a list where the promoCode
is
not equal to any items in the list.
promoCode <> 1 AND promoCode <> 2 AND promoCode <> 3
Example: Creating a "between" Comparison
This example uses comparison operators to create a comparison showing values that exist between one value and another.
The following example examines OrderDate
and returns rows where the
OrderDate
is between the first day and last day of 2016. In this case, we
want the first and last day included, so we use "or equal to" on the comparison
operators.
OrderDate >= "1/1/2016" AND OrderDate <= "12/31/2016"
Functions by Category
In this section, you can find a list of the functions available in Amazon QuickSight sorted by category.
Topics
Aggregate Functions
The aggregate functions for calculated fields in Amazon QuickSight include the following. These are only available during analysis and visualization. Each of these functions returns values grouped by the chosen dimension or dimensions.

avg averages the set of numbers in the specified measure, grouped by the chosen dimension or dimensions.

count calculates the number of values in a dimension or measure, grouped by the chosen dimension or dimensions.

distinct_count calculates the number of distinct values in a dimension or measure, grouped by the chosen dimension or dimensions.

max returns the maximum value of the specified measure, grouped by the chosen dimension or dimensions.

min returns the minimum value of the specified measure, grouped by the chosen dimension or dimensions.

percentile computes the nth percentile of the specified measure, grouped by the chosen dimension or dimensions.

sum adds the set of numbers in the specified measure, grouped by the chosen dimension or dimensions.

For each aggregation, there is also a conditional aggregation. These perform the same type of aggregation, based on a condition. Conditional aggregations include avgIf, countIf, distinct_countIf, maxIf, minIf, and sumIf.
Conditional Functions
The conditional functions for calculated fields in Amazon QuickSight include the following:

coalesce returns the value of the first argument that is not null.

ifelse evaluates a set of if, then expression pairings, and returns the value of the then argument for the first if argument that evaluates to true.

isNotNull evaluates an expression to see if it is not null.

isNull evaluates an expression to see if it is null. If the expression is null,
isNull
returns true, and otherwise it returns false. 
nullIf compares two expressions. If they are equal, the function returns null. If they are not equal, the function returns the first expression.
Date Functions
The date functions for calculated fields in Amazon QuickSight include the following:

addDateTime adds or subtracts a unit of time to the date or time provided.

dateDiff returns the difference in days between two date fields. (SPICE enabled)

epochDate converts an epoch date into a standard date. (SPICE enabled)

extract returns a specified portion of a date value. (SPICE enabled)

formatDate formats a date using a pattern you specify.

now returns the current date and time, using either settings for a database, or UTC for file and Salesforce.

truncDate returns a date value that represents a specified portion of a date. (SPICE enabled)
Numeric Functions
The numeric functions for calculated fields in Amazon QuickSight include the following:

ceil rounds a decimal value to the next highest integer. (SPICE enabled)

decimalToInt converts a decimal value to an integer. (SPICE enabled)

floor decrements a decimal value to the next lowest integer. (SPICE enabled)

intToDecimal converts an integer value to a decimal. (SPICE enabled)

round rounds a decimal value to the closest integer or, if scale is specified, to the closest decimal place. (SPICE enabled)
String Functions
The string (text) functions for calculated fields in Amazon QuickSight include the following:

concat concatenates two or more strings.

left returns the specified number of leftmost characters from a string.

locate locates a substring within another string, and returns the number of characters before the substring.

ltrim removes preceding white space from a string.

parseDate parses a string to determine if it contains a date value, and returns the date if found.

parseDecimal parses a string to determine if it contains a decimal value.

parseInt parses a string to determine if it contains an integer value.

parseJson parses values from a native JSON or from a JSON object in a text field.

replace replaces part of a string with a new string.

right returns the specified number of rightmost characters from a string.

rtrim removes following white space from a string.

split splits a string into an array of substrings, based on a delimiter that you choose, and returns the item specified by the position.

strlen returns the number of characters in a string.

substring returns the specified number of characters in a string, starting at the specified location.

toLower formats a string in all lowercase.

toString formats the input expression as a string.

toUpper formats a string in all uppercase.

trim removes both preceding and following white space from a string.
Table Calculations
Table calculations form a group of functions that provide context in an analysis. They provide support for enriched aggregated analysis. By using these calculations, you can address common business scenarios such as calculating percentage of total, running sum, difference, common baseline, and rank.
When you are analyzing data in a specific visual, you can apply table calculations to the current set of data to discover how dimensions influence measures or each other. Visualized data is your result set based on your current data set, with all the filters, field selections, and customizations applied. To see exactly what this result set is, you can export your visual to commaseparated value (CSV) format. A table calculation function performs operations on the data to reveal relationships between fields.
The table calculations available in Amazon QuickSight for both SPICE and direct query data include the following:
Lookupbased functions:

difference calculates the difference between a measure based on one set of partitions and sorts, and a measure based on another.

lag calculates the lag (previous) value for a measure.

lead calculates the lead (following) value for a measure.

percentDifference calculates the percentage difference between the current value and a comparison value.
Over functions:

avgOver calculates the average of a measure over one or more dimensions.

countOver calculates the count of a measure over one or more dimensions.

maxOver calculates the maximum of a measure over one or more dimensions.

minOver the minimum of a measure over one or more dimensions.

percentOfTotal calculates the percentage a measure contributes to the total.

sumOver calculates the sum of a measure over one or more dimensions.
Ranking functions:

rank calculates the rank of a measure or a dimension.

denseRank calculates the rank of a measure or a dimension, ignoring duplicates.

percentileRank calculates the rank of a measure or a dimension, based on percentile.
Running functions:

runningAvg calculates a running average for a measure.

runningCount calculates a running count for a measure.

runningMax calculates a running maximum for a measure.

runningMin calculates a running minimum for a measure.

runningSum calculates a running sum for a measure.
Custom Window functions:

windowAvg calculates the average of the aggregated measure in a custom window that is partitioned and sorted by specified attributes.

windowCount ccalculates the count of the aggregated measure in a custom window that is partitioned and sorted by specified attributes.

windowMax calculates the maximum of the aggregated measure in a custom window that is partitioned and sorted by specified attributes.

windowMin calculates the minimum of the aggregated measure in a custom window that is partitioned and sorted by specified attributes.

windowSum calculates the sum of the aggregated measure in a custom window that is partitioned and sorted by specified attributes.
Function Index
In this section, you can find a list of functions available in Amazon QuickSight. Some functions are available in SPICE, while you are in the analysis screen.
To view a list of functions sorted by category, with brief definitions, see Functions by Category.
Topics
Table Calculation Functions Index
When you are analyzing data in a specific visual, you can apply table calculations to the current set of data to discover how dimensions influence measures or each other. Visualized data is your result set based on your current data set, with all the filters, field selections, and customizations applied. To see exactly what this result set is, you can export your visual to commaseparated value (CSV) format. A table calculation function performs operations on the data to reveal relationships between fields.
In this section, you can find a list of the functions available in table calculations that you can perform on visualized data in Amazon QuickSight.
To view a list of functions sorted by category, with brief definitions, see Functions by Category.
Lookupbased functions:
Over functions:
Ranking functions:
Running functions:
Custom window functions: