If your admin has granted you the permissions to create table calculations, you can use the following features to quickly perform common functions without needing to create Looker expressions:
- Shortcut Calculations to quickly perform common calculations on numeric fields that are in an Explore's data table
If your admin has granted you the permissions to create custom fields, you can use the following features to quickly perform common functions without needing to create Looker expressions:
Custom groups to quickly group values under custom labels without needing to develop
CASE WHENlogic insqlparameters ortype: casefields
Custom bins to group numeric type dimensions in custom tiers without needing to develop
type: tierLookML fields
Looker expressions (sometimes referred to as Lexp) are used to perform calculations for:
- Table calculations (which include expressions used in data tests)
- Custom fields
- Custom filters
A major part of these expressions is the functions and operators that you can use in them. The functions and operators can be divided into a few basic categories:
- Mathematical: Number-related functions
- String: Word- and letter-related functions
- Dates: Date- and time-related functions
- Logical transformation: Includes boolean (true or false) functions and comparison operators
- Positional transformation: Retrieving values from different rows or pivots
Some functions are only available for table calculations
Looker expressions for custom filters and custom fields do not support Looker functions that convert datatypes, aggregate data from multiple rows, or refer to other rows or pivot columns. These functions are supported only for table calculations (including table calculations used in the expression parameter of a data test).
This page is organized to clarify which functions and operators are available, depending on where you are using your Looker expression.
Mathematical functions and operators
Mathematical functions and operators work in one of two ways:
- Some mathematical functions perform calculations based on a single row. For example, rounding, taking a square root, multiplying, and similar functions can be used for values in a single row, returning a distinct value for each and every row. All mathematical operators, such as +, are applied one row at a time.
- Other mathematical functions, like averages and running totals, operate over many rows. These functions take many rows and reduce them to a single number, then display that same number on every row.
Functions for any Looker expression
| Function | Syntax | Purpose | 
|---|---|---|
| abs | abs(value) | Returns the absolute value of value. For an example, see the Standard Deviation and Simple Time Series Outlier Detection Using Table Calculations Community post. | 
| ceiling | ceiling(value) | Returns the smallest integer greater than or equal to value. | 
| exp | exp(value) | Returns e to the power of value. | 
| floor | floor(value) | Returns the largest integer less than or equal to value. | 
| ln | ln(value) | Returns the natural logarithm of value. | 
| log | log(value) | Returns the base 10 logarithm of value. | 
| mod | mod(value, divisor) | Returns the remainder of dividing valuebydivisor. | 
| power | power(base, exponent) | Returns baseraised to the power ofexponent. For an example, see the Standard Deviation and Simple Time Series Outlier Detection Using Table Calculations Community post. | 
| rand | rand() | Returns a random number between 0 and 1. | 
| round | round(value, num_decimals) | Returns valuerounded tonum_decimalsdecimal places. For examples usinground, see the Usingpivot_indexin table calculations and Standard Deviation and Simple Time Series Outlier Detection Using Table Calculations Community posts. | 
| sqrt | sqrt(value) | Returns the square root of value. For an example, see the Standard Deviation and Simple Time Series Outlier Detection Using Table Calculations Community post. | 
Functions for table calculations only
Many of these functions operate over many rows and will only consider the rows returned by your query.
| Function | Syntax | Purpose | 
|---|---|---|
| acos | acos(value) | Returns the inverse cosine of value. | 
| asin | asin(value) | Returns the inverse sine of value. | 
| atan | atan(value) | Returns the inverse tangent of value. | 
| beta_dist | beta_dist(value, alpha,  beta, cumulative) | Returns the position of valueon the beta distribution with parametersalphaandbeta. Ifcumulative = yes, returns the cumulative probability. | 
| beta_inv | beta_inv(probability,  alpha, beta) | Returns the position of probabilityon the inverse cumulative beta distribution with parametersalphaandbeta. | 
| binom_dist | binom_dist(num_successes, num_tests, probability, cumulative) | Returns the probability of getting num_successessuccesses innum_teststests with the givenprobabilityof success. Ifcumulative = yes, returns the cumulative probability. | 
| binom_inv | binom_inv(num_tests,  test_probability, target_probability) | Returns the smallest number ksuch thatbinom(k, num_tests, test_probability, yes) >= target_probability. | 
| chisq_dist | chisq_dist(value, dof,  cumulative) | Returns the position of valueon the gamma distribution withdofdegrees of freedom. Ifcumulative = yes, returns the cumulative probability. | 
| chisq_inv | chisq_inv(probability, dof) | Returns the position of probabilityon the inverse cumulative gamma distribution withdofdegrees of freedom. | 
| chisq_test | chisq_test(actual,  expected) | Returns the probability for the chi-squared test for independence between actualandexpecteddata.actualcan be a column or a column of lists, andexpectedmust be the same type. | 
| combin | combin(set_size, selection_size) | Returns the number of ways of choosing selection_sizeelements from a set of sizeset_size. | 
| confidence_norm | confidence_norm(alpha, stdev, n) | Returns half the width of the normal confidence interval at significance level alpha, standard deviationstdev, and sample sizen. | 
| confidence_t | confidence_t(alpha,  stdev, n) | Returns half the width of the Student's t-distribution confidence interval at significance level alpha, standard deviationstdev, and sample sizen. | 
| correl | correl(column_1, column_2) | Returns the correlation coefficient of column_1andcolumn_2. | 
| cos | cos(value) | Returns the cosine of value. | 
| count | count(expression) | Returns the count of non- nullvalues in the column defined byexpression, unlessexpressiondefines a column of lists, in which case returns the count in each list. | 
| count_distinct | count_distinct(expression) | Returns the count of distinct non- nullvalues in the column defined byexpression, unlessexpressiondefines a column of lists, in which case returns the count in each list. | 
| covar_pop | covar_pop(column_1, column_2) | Returns the population covariance of column_1andcolumn_2. | 
| covar_samp | covar_samp(column_1,  column_2) | Returns the sample covariance of column_1andcolumn_2. | 
| degrees | degrees(value) | Converts valuefrom radians to degrees. | 
| expon_dist | expon_dist(value, lambda, cumulative) | Returns the position of valueon the exponential distribution with parameterlambda. Ifcumulative = yes, returns the cumulative probability. | 
| f_dist | f_dist(value, dof_1, dof_2, cumulative) | Returns the position of valueon the F distribution with parametersdof_1anddof_2. Ifcumulative = yes, returns the cumulative probability. | 
| f_inv | f_inv(probability, dof_1, dof_2) | Returns the position of probabilityon the inverse cumulative F distribution with parametersdof_1anddof_2. | 
| fact | fact(value) | Returns the factorial of value. | 
| gamma_dist | gamma_dist(value, alpha, beta, cumulative) | Returns the position of valueon the gamma distribution with parametersalphaandbeta. Ifcumulative = yes, returns the cumulative probability. | 
| gamma_inv | gamma_inv(probability,  alpha, beta) | Returns the position of probabilityon the inverse cumulative gamma distribution with parametersalphaandbeta. | 
| geomean | geomean(expression) | Returns the geometric mean of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the geometric mean of each list. | 
| hypgeom_dist | hypgeom_dist(sample_successes, sample_size, population_successes, population_size, cumulative) | Returns the probability of getting sample_successesfrom the givensample_size, number ofpopulation_successes, andpopulation_size. Ifcumulative = yes, returns the cumulative probability. | 
| intercept | intercept(y_column, x_column) | Returns the intercept of the linear regression line through the points determined by y_columnandx_column. For an example, see the How to Forecast in Looker with Table Calculations Community post. | 
| kurtosis | kurtosis(expression) | Returns the sample excess kurtosis of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the sample excess kurtosis of each list. | 
| large | large(expression, k) | Returns the kth largest value of the column created byexpressionunlessexpressiondefines a column of lists, in which case returns thekth largest value of each list. | 
| match | match(value, expression) | Returns the row number of the first occurrence of valuein the column created byexpressionunlessexpressiondefines a column of lists, in which case returns the position ofvaluein each list. | 
| max | max(expression) | Returns the max of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the max of each list. For examples usingmax, see the Using lists in table calculations and Grouping by a dimension in table calculations Community posts. | 
| mean | mean(expression) | Returns the mean of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the mean of each list. For examples usingmean, see the Calculating Moving Averages Community post and the Standard Deviation and simple time series outlier detection using Table Calculations Community post. | 
| median | median(expression) | Returns the median of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the median of each list. | 
| min | min(expression) | Returns the min of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the min of each list. | 
| mode | mode(expression) | Returns the mode of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the mode of each list. | 
| multinomial | multinomial(value_1,  value_2, ...) | Returns the factorial of the sum of the arguments divided by the product of each of their factorials. | 
| negbinom_dist | negbinom_dist(num_failures, num_successes, probability, cumulative) | Returns the probability of getting num_failuresfailures before gettingnum_successessuccesses, with the givenprobabilityof success. Ifcumulative = yes, returns the cumulative probability. | 
| norm_dist | norm_dist(value, mean,  stdev, cumulative) | Returns the position of valueon the normal distribution with the givenmeanandstdev. Ifcumulative = yes, returns the cumulative probability. | 
| norm_inv | norm_inv(probability, mean,  stdev) | Returns the position of probabilityon the inverse normal cumulative distribution. | 
| norm_s_dist | norm_s_dist(value,  cumulative) | Returns the position of valueon the standard normal distribution. Ifcumulative = yes, returns the cumulative probability. | 
| norm_s_inv | norm_s_inv(probability) | Returns the position of probabilityon the inverse standard normal cumulative distribution. | 
| percent_rank | percent_rank(column, value) | Returns the rank of valueincolumnas a percentage from 0 to 1 inclusive, wherecolumnis the column, field, list, or range containing the dataset to consider; andvalueis the column with the value for which the percentage rank will be determined.Sample Usage:percent_rank(${view_name.field_1}, ${view_name.field_1})percent_rank(list(1, 2, 3), ${view_name.field_1})percent_rank(list(1, 2, 3), 2) | 
| percentile | percentile(expression, percentile_value) | Returns the value from the column created by expressioncorresponding to the givenpercentile_value, unlessexpressiondefines a column of lists, in which case returns the percentile value for each list.percentile_valuemust be between 0 and 1; otherwise returnsnull. | 
| pi | pi() | Returns the value of pi. | 
| poisson_dist | poisson_dist(value, lambda, cumulative) | Returns the position of valueon the poisson distribution with parameterlambda. Ifcumulative = yes, returns the cumulative probability. | 
| product | product(expression) | Returns the product of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the product of each list. | 
| radians | radians(value) | Converts valuefrom degrees to radians. | 
| rank | rank(value, expression) | Returns the rank of valuein the column created byexpression. For example, if you want to rank orders by their total sale price, you could userank(${order_items.total_sale_price},${order_items.total_sale_price}), which gives a rank for each value oforder_items.total_sale_pricein your query when comparing it to the entire column oforder_items.total_sale_pricein your query. In the case where theexpressiondefines multiple lists, this function returns the relative size of thevaluein each list. For an example, see the Ranks with Table Calculations Community post. | 
| rank_avg | rank_avg(value, expression) | Returns the average rank of valuein the column created byexpressionunlessexpressiondefines a column of lists, in which case returns the average rank ofvaluein each list. | 
| running_product | running_product(value_column) | Returns a running product of the values in value_column. | 
| running_total | running_total(value_column) | Returns a running total of the values in value_column. For an example, see the Creating a Running Total Down Columns with Table Calculations Best Practices page. | 
| sin | sin(value) | Returns the sine of value. | 
| skew | skew(expression) | Returns the sample skewness of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the sample skewness of each list. | 
| slope | slope(y_column, x_column) | Returns the slope of the linear regression line through points determined by y_columnandx_column. For an example, see the How to Forecast in Looker with Table Calculations Community post. | 
| small | small(expression, k) | Returns the kth smallest value of the column created byexpressionunlessexpressiondefines a column of lists, in which case returns thekth smallest value of each list. | 
| stddev_pop | stddev_pop(expression) | Returns the standard deviation (population) of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the standard deviation (population) of each list. | 
| stddev_samp | stddev_samp(expression) | Returns the standard deviation (sample) of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the standard deviation (sample) of each list. | 
| sum | sum(expression) | Returns the sum of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the sum of each list. For examples usingsum, see the Aggregating Across Rows (Row Totals) in Table Calculations and How to Calculate Percent-of-Total Best Practices pages. | 
| t_dist | t_dist(value, dof, cumulative) | Returns the position of valueon the Student's t-distribution withdofdegrees of freedom. Ifcumulative = yes, returns the cumulative probability. | 
| t_inv | t_inv(probability, dof) | Returns the position of probabilityon the inverse normal cumulative distribution withdofdegrees of freedom. | 
| t_test | t_test(column_1, column_2,  tails, type) | Returns the result of a Student's t-test on the data from column_1andcolumn_2, using 1 or 2tails.type: 1 = paired, 2 = homoscedastic, 3 = heteroscedastic. | 
| tan | tan(value) | Returns the tangent of value. | 
| var_pop | var_pop(expression) | Returns the variance (population) of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the variance (population) of each list. | 
| var_samp | var_samp(expression) | Returns the variance (sample) of the column created by expressionunlessexpressiondefines a column of lists, in which case returns the variance (sample) of each list. | 
| weibull_dist | weibull_dist(value, shape, scale, cumulative) | Returns the position of valueon the Weibull distribution with parametersshapeandscale. Ifcumulative = yes, returns the cumulative probability. | 
| z_test | z_test(data, value, stdev) | Returns the one-tailed p-value of the z-test using the existing dataandstdevon the hypothesized meanvalue. | 
Operators for any Looker expression
You can use the following standard mathematical operators:
| Operator | Syntax | Purpose | 
|---|---|---|
| + | value_1 + value_2 | Adds value_1andvalue_2. | 
| - | value_1 - value_2 | Subtracts value_2fromvalue_1. | 
| * | value_1 * value_2 | Multiplies value_1andvalue_2. | 
| / | value_1 / value_2 | Divides value_1byvalue_2. | 
String functions
String functions operate on sentences, words, or letters, which are collectively called "strings." You can use string functions to capitalize words and letters, extract parts of a phrase, check to see if a word or letter is in a phrase, or replace elements of a word or phrase. String functions can also be used to format the data returned in the table.
Functions for any Looker expression
Functions for table calculations only
Date functions
Date functions enable you to work with dates and times.
Functions for any Looker expression
| Function | Syntax | Purpose | 
|---|---|---|
| add_days | add_days(number, date) | Adds numberdays todate. | 
| add_hours | add_hours(number, date) | Adds numberhours todate. | 
| add_minutes | add_minutes(number, date) | Adds numberminutes todate. | 
| add_months | add_months(number, date) | Adds numbermonths todate. | 
| add_seconds | add_seconds(number, date) | Adds numberseconds todate. | 
| add_years | add_years(number, date) | Adds numberyears todate. | 
| date | date(year, month, day) | Returns " year-month-day" date ornullif the date would be invalid. | 
| date_time | date_time(year, month, day, hours, minutes, seconds) | Returns year-month-day hours:minutes:secondsdate ornullif the date would be invalid. | 
| diff_days | diff_days(start_date, end_date) | Returns the number of days between start_dateandend_date. For an example, see the Using dates in table calculations Community post. | 
| diff_hours | diff_hours(start_date, end_date) | Returns the number of hours between start_dateandend_date. | 
| diff_minutes | diff_minutes(start_date, end_date) | Returns the number of minutes between start_dateandend_date. For an example, see the Using dates in table calculations Community post. | 
| diff_months | diff_months(start_date, end_date) | Returns the number of months between start_dateandend_date. For an example, see the Grouping by a dimension in table calculations Community post. | 
| diff_seconds | diff_seconds(start_date, end_date) | Returns the number of seconds between start_dateandend_date. | 
| diff_years | diff_years(start_date, end_date) | Returns the number of years between start_dateandend_date. | 
| extract_days | extract_days(date) | Extracts the days from date. For an example, see the Using dates in table calculations Community post. | 
| extract_hours | extract_hours(date) | Extracts the hours from date. | 
| extract_minutes | extract_minutes(date) | Extracts the minutes from date. | 
| extract_months | extract_months(date) | Extracts the months from date. | 
| extract_seconds | extract_seconds(date) | Extracts the seconds from date. | 
| extract_years | extract_years(date) | Extracts the years from date. | 
| now | now() | Returns the current date and time. For examples using now, see the Now() Table Calculation Function Has Better Timezone Handling Community post and theUsing dates in table calculations Community post. | 
| trunc_days | trunc_days(date) | Truncates dateto days. | 
| trunc_hours | trunc_hours(date) | Truncates dateto hours. | 
| trunc_minutes | trunc_minutes(date) | Truncates dateto minutes. | 
| trunc_months | trunc_months(date) | Truncates dateto months. | 
| trunc_years | trunc_years(date) | Truncates dateto years. | 
Functions for table calculations only
| Function | Syntax | Purpose | 
|---|---|---|
| to_date | to_date(string) | Returns the date and time corresponding to string(YYYY, YYYY-MM, YYYY-MM-DD, YYYY-MM-DD hh, YYYY-MM-DD hh:mm, or YYYY-MM-DD hh:mm:ss). | 
Logical functions, operators, and constants
Logical functions and operators are used to assess whether something is true or false. Expressions using these elements take a value, evaluate it against some criteria, return Yes if the criteria are met, and No if the criteria are not met. There are also various logical operators for comparing values and combining logical expressions.
Functions for any Looker expression
| Function | Syntax | Purpose | 
|---|---|---|
| case | case(when(yesno_arg, value_if_yes), when(yesno_arg, value_if_yes), ..., else_value) | Added 21.10
    
  
 Allows conditional logic with multiple conditions and outcomes. Returns value_if_yesfor the firstwhencase whoseyesno_argvalue isyes. Returnselse_valueif allwhencases areno. | 
| coalesce | coalesce(value_1, value_2, ...) | Returns the first non- nullvalue invalue_1,value_2,...,value_nif found andnullotherwise. For examples usingcoalesce, see the following Community posts: Creating a running total across rows with table calculations, Creating a percent of total across rows with table calculations, and Using pivot_index in table calculations. | 
| if | if(yesno_expression, value_if_yes, value_if_no) | If yesno_expressionevaluates toYes, returns thevalue_if_yesvalue. Otherwise, returns thevalue_if_novalue. For an example, see the Grouping by a dimension in table calculations Community post. | 
| is_null | is_null(value) | Returns Yesifvalueisnull, andNootherwise. For an example, see the Creating Looker expressions documentation page. For another example that usesis_nullwith theNOToperator, see the Using table calculations documentation page. | 
Operators for any Looker expression
The following comparison operators can be used with any data type:
| Operator | Syntax | Purpose | 
|---|---|---|
| = | value_1 = value_2 | Returns Yesifvalue_1is equal tovalue_2, andNootherwise. | 
| != | value_1 != value_2 | Returns Yesifvalue_1is not equal tovalue_2, andNootherwise. | 
The following comparison operators can be used with numbers, dates, and strings:
You also can combine Looker expressions with these logical operators:
These logical operators must be capitalized. Logical operators written in lowercase will not work.
Logical constants
You can use logical constants in Looker expressions. These constants are always written in lowercase and have the following meanings:
| Constant | Meaning | 
|---|---|
| yes | True | 
| no | False | 
| null | No value | 
Note that the constants yes and no are the special symbols that mean true or false in Looker expressions. In contrast, using quotes such as in "yes" and "no" creates literal strings with those values.
Logical expressions evaluate to true or false without requiring an if function. For example, this:
if(${field} > 100, yes, no)
is equivalent to this:
${field} > 100
You also can use null to indicate no value. For example, you may want to determine if a field is empty, or assign an empty value in a certain situation. This formula returns no value if the field is less than 1, or the value of the field if it is more than 1:
if(${field} < 1, null, ${field})
Combining AND and OR operators
AND operators are evaluated before OR operators, if you don't otherwise specify the order with parentheses. Thus, the following expression without additional parentheses:
if (
  ${order_items.days_to_process}>=4 OR
  ${order_items.shipping_time}>5 AND
  ${order_facts.is_first_purchase},
"review", "okay")
would be evaluated as:
if (
  ${order_items.days_to_process}>=4 OR
  (${order_items.shipping_time}>5 AND ${order_facts.is_first_purchase}),
"review", "okay")
Positional functions
When creating table calculations, you can use positional transformation functions to extract information about fields in different rows or pivot columns. You can also create lists and retrieve the current row or pivot column index.
Column and row totals for table calculations only
If your Explore contains totals, you can reference total values for columns and rows:
| Function | Syntax | Purpose | 
|---|---|---|
| :total | ${field:total} | Returns the column total of the field. | 
| :row_total | ${field:row_total} | Returns the row total of the field. | 
Row-related functions for table calculations only
Some of these functions use the relative positions of rows, so changing the sort order of the rows affects the results of the functions.
| Function | Syntax | Purpose | 
|---|---|---|
| index | index(expression, n) | Returns the value of the nth element of the column created byexpression, unlessexpressiondefines a column of lists, in which case returns thenth element of each list. | 
| list | list(value_1, value_2, ...) | Creates a list out of the given values. For an example, see the Using lists in table calculations Community post. | 
| lookup | lookup(value, lookup_column, result_column) | Returns the value in result_columnthat is in the same row asvalueis inlookup_column. | 
| offset | offset(column, row_offset) | Returns the value of row (n + row_offset)incolumn, wherenis the current row number. For examples usingoffset, see the Calculating Percent of Previous and Percent Change with Table Calculations Best Practices page. | 
| offset_list | offset_list(column, row_offset, num_values) | Returns a list of the num_valuesvalues starting at row(n + row_offset)incolumn, wherenis the current row number. For an example, see the Calculating Moving Averages Community post. | 
| row | row() | Returns the current row number. | 
Pivot-related functions for table calculations only
Some of these functions use the relative positions of pivot columns, so changing the sort order of the pivoted dimension affects the results of those functions.
| Function | Syntax | Purpose | 
|---|---|---|
| pivot_column | pivot_column() | Returns the index of the current pivot column. | 
| pivot_index | pivot_index(expression, pivot_index) | Evaluates expressionin the context of the pivot column at positionpivot_index(1 for first pivot, 2 second pivot, etc.). Returns null for unpivoted results. For examples usingpivot_index, see the Using pivot_index in table calculations and Creating a percent of total across rows with table calculations Community posts. | 
| pivot_offset | pivot_offset(pivot_expression, col_offset) | Returns the value of the pivot_expressionin position(n + col_offset), wherenis the current pivot column position.  Returns null for unpivoted results. For examples usingpivot_offset, see the Creating a running total across rows with table calculations Community post and the Calculating Percent of Previous and Percent Change with Table Calculations Best Practices page. | 
| pivot_offset_list | pivot_offset_list(pivot_expression, col_offset, num_values) | Returns a list of the num_valuesvalues inpivot_expressionstarting at position(n + col_offset), wherenis the current pivot index.  Returnsnullfor unpivoted results. | 
| pivot_row | pivot_row(expression) | Returns the pivoted values of expressionas a list.  Returnsnullfor unpivoted results. For examples usingpivot_row, see the Aggregating Across Rows (Row Totals) in Table Calculations and How to Calculate Percent-of-Total Best Practices pages. | 
| pivot_where | pivot_where(select_expression, expression) | Returns the value of expressionfor the pivot column that uniquely satisfiesselect_expressionornullif such a unique column does not exist. | 
The specific pivot functions you use determine whether the table calculation is displayed next to each pivoted column, or is displayed as a single column at the end of the table.
Filter functions for custom filters and custom fields
Filter functions let you work with filter expressions to return values based on filtered data. Filter functions work in custom filters, filters on custom measures, and custom dimensions, but are not valid in table calculations.
| Function | Syntax | Purpose | 
|---|---|---|
| matches_filter | matches_filter(field, filter_expression) | Returns Yesif the value of the field matches the filter expression,Noif not. |