Pass-Through Functions (RAWSQL)

These RAWSQL pass-through functions send SQL expressions directly to the database, without first being interpreted by Tableau. If you have custom database functions that Tableau doesn't know about, you can use pass-through functions to call these custom functions.

Because Tableau doesn't interpret the expression, you must define the aggregation when necessary. You can use the RAWSQLAGG version of a function when you need to pass an aggregated expression.

RAWSQL pass-through functions may not work with federated (combined across different databases) or published data sources.

RAWSQL Syntax

RAWSQL functions have two types, disaggregated and aggregated. This is specified in the first part of the function name, RAWSQL or RAWSQLAGG. The final portion of the function name is the output type, such as BOOL, STR or INT. In all RAWSQL functions, the argument is "sql_expr", [arg1], ...[arg2]. When writing the function, you can use a substitution syntax %n to insert the correct field name or expression.

%n substitution syntax

Your database won't usually understand the field names that are shown in Tableau. Because Tableau doesn't interpret the SQL expressions in the pass-through functions, using the Tableau field names in your expression may cause errors. Use %n to insert the correct field name or expression for a Tableau calculation into pass-through SQL.

For example, if you had a function that computed the median of a set of values, you could call that function on the Tableau column [Sales] like this:

RAWSQLAGG_REAL("MEDIAN(%1)", [Sales])
  • REALSQLAGG because you want to specify the aggregation.
  • REAL because the output is numeric and not necessarily an integer.
  • MEDIAN is the aggregation.
  • %1 is the placeholder for [Sales].

RAWSQL Functions

The SQL expression is passed directly to the underlying database. Use %n in the SQL expression as a substitution syntax for database values.

The following RAWSQL functions are available in Tableau:

RAWSQL_BOOL

SyntaxRAWSQL_BOOL("sql_expr", [arg1], …[argN])
OutputBoolean
DefinitionReturns a Boolean result from a given SQL expression.
Example
RAWSQL_BOOL("%1 > %2", [Sales], [Profit])

In the example, %1 is equal to [Sales] and %2 is equal to [Profit].

RAWSQLAGG_BOOL

SyntaxRAWSQLAGG_BOOL("sql_expr", [arg1], …[argN])
OutputBoolean
DefinitionReturns a Boolean result from a given aggregate SQL expression.
Example
RAWSQLAGG_BOOL("SUM( %1) >SUM( %2)", [Sales], [Profit]) 

In the example, %1 is equal to [Sales] and %2 is equal to [Profit].

RAWSQL_DATE

SyntaxRAWSQL_DATE("sql_expr", [arg1], …[argN])
OutputDate
DefinitionReturns a date result from a given SQL expression.
Example
RAWSQL_DATE("%1", [Order Date])

In this example, %1 is equal to [Order Date].

RAWSQLAGG_DATE

SyntaxRAWSQLAGG_DATE("sql_expr", [arg1], …[argN])
OutputDate
DefinitionReturns a date result from a given aggregate SQL expression
Example
RAWSQLAGG_DATE("MAX(%1)", [Order Date])

In this example, %1 is equal to [Order Date].

RAWSQL_DATETIME

SyntaxRAWSQL_DATETIME("sql_expr", [arg1], …[argN])
OutputDatetime
DefinitionReturns a datetime result from a given SQL expression.
Example
RAWSQL_DATETIME("%1", [Order Date])

In this example, %1 is equal to [Order Date].

RAWSQLAGG_DATETIME

SyntaxRAWSQLAGG_DATETIME("sql_expr", [arg1], …[argN])
OutputDatetime
DefinitionReturns a datetime result from a given aggregate SQL expression.
Example
RAWSQLAGG_DATETIME("MIN(%1)", [Order Date])

In this example, %1 is equal to [Order Date].

RAWSQL_INT

SyntaxRAWSQL_INT("sql_expr", [arg1], …[argN])
OutputInteger
DefinitionReturns an integer result from a given SQL expression.
Example
RAWSQL_INT("500 + %1", [Sales])

In this example, %1 is equal to [Sales].

RAWSQLAGG_INT

SyntaxRAWSQLAGG_INT("sql_expr", [arg1,] …[argN])
OutputInteger
DefinitionReturns an integer result from a given aggregate SQL expression.
Example
RAWSQLAGG_INT("500 + SUM(%1)", [Sales])

In this example, %1 is equal to [Sales].

RAWSQL_REAL

SyntaxRAWSQL_REAL("sql_expr", [arg1], …[argN])
OutputNumeric
DefinitionReturns a numeric result from a given SQL expression.
Example
RAWSQL_REAL("-123.98 * %1", [Sales])

In this example, %1 is equal to [Sales]

RAWSQLAGG_REAL

SyntaxRAWSQLAGG_REAL("sql_expr", [arg1,] …[argN])
OutputNumeric
DefinitionReturns a numeric result from a given aggregate SQL expression.
Example
RAWSQLAGG_REAL("SUM( %1)", [Sales])

In this example, %1 is equal to [Sales].

RAWSQL_SPATIAL

SyntaxRAWSQL_SPATIAL("sql_expr", [arg1], …[argN])
OutputSpatial
DefinitionReturns a spatial result from a given SQL expression.
Example
RAWSQL_SPATIAL("%1", [Geometry])

In this example, %1 is equal to [Geometry].

NoteThere is no RAWSQLAGG version of this function.

RAWSQL_STR

SyntaxRAWSQL_STR("sql_expr", [arg1], …[argN])
OutputString
DefinitionReturns a string from a given SQL expression.
Example
RAWSQL_STR("%1", [Customer Name])

In this example, %1 is equal to [Customer Name].

RAWSQLAGG_STR

SyntaxRAWSQLAGG_STR("sql_expr", [arg1,] …[argN])
OutputString
DefinitionReturns a string from a given aggregate SQL expression.
Example
RAWSQLAGG_STR("AVG(%1)", [Discount])

In this example, %1 is equal to [Discount].

Thanks for your feedback!Your feedback has been successfully submitted. Thank you!