---
schema_version: "1"
id: e171dfba7bab5016f0d1139e62c47edfe75d5871f59e39428ff5f73159af371f
title: Pass-Through Functions (RAWSQL)
collection: tableau
version: current
locale: en-gb
portal_url: https://docs.salesforce.com/tableau/current/en-gb/pro/desktop/functions_functions_passthrough.md
canonical_url: https://help.tableau.com/current/pro/desktop/en-gb/functions_functions_passthrough.htm
source_site: help.tableau.com
content_type: documentation
content_hash: bbbd0820d9fa9e7941e02a1379e1ab62434f68d34df6c22ac94bf45e4f07f379
description: Reference for RAWSQL pass-through functions that send SQL directly to the database.
---
[Skip to main content](#main-content)

# 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

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQL_BOOL("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Boolean</td></tr><tr><td>Definition</td><td>Returns a Boolean result from a given SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQL_BOOL("%1 &gt; %2", [Sales], [Profit])</pre><p>In the example, %1 is equal to [Sales] and %2 is equal to [Profit].</p></td></tr></tbody></table>

### RAWSQLAGG\_BOOL

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQLAGG_BOOL("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Boolean</td></tr><tr><td>Definition</td><td>Returns a Boolean result from a given aggregate SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQLAGG_BOOL("SUM( %1) &gt;SUM( %2)", [Sales], [Profit]) </pre><p>In the example, %1 is equal to [Sales] and %2 is equal to [Profit].</p></td></tr></tbody></table>

### RAWSQL\_DATE

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQL_DATE("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Date</td></tr><tr><td>Definition</td><td>Returns a date result from a given SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQL_DATE("%1", [Order Date])</pre><p>In this example, %1 is equal to [Order Date].</p></td></tr></tbody></table>

### RAWSQLAGG\_DATE

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQLAGG_DATE("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Date</td></tr><tr><td>Definition</td><td>Returns a date result from a given aggregate SQL expression</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQLAGG_DATE("MAX(%1)", [Order Date])</pre><p>In this example, %1 is equal to [Order Date].</p></td></tr></tbody></table>

### RAWSQL\_DATETIME

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQL_DATETIME("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Datetime</td></tr><tr><td>Definition</td><td>Returns a datetime result from a given SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQL_DATETIME("%1", [Order Date])</pre><p>In this example, %1 is equal to [Order Date].</p></td></tr></tbody></table>

### RAWSQLAGG\_DATETIME

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQLAGG_DATETIME("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Datetime</td></tr><tr><td>Definition</td><td>Returns a datetime result from a given aggregate SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQLAGG_DATETIME("MIN(%1)", [Order Date])</pre><p>In this example, %1 is equal to [Order Date].</p></td></tr></tbody></table>

### RAWSQL\_INT

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQL_INT("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Integer</td></tr><tr><td>Definition</td><td>Returns an integer result from a given SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQL_INT("500 + %1", [Sales])</pre><p>In this example, %1 is equal to [Sales].</p></td></tr></tbody></table>

### RAWSQLAGG\_INT

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQLAGG_INT("sql_expr", [arg1,] …[argN])</code></td></tr><tr><td>Output</td><td>Integer</td></tr><tr><td>Definition</td><td>Returns an integer result from a given aggregate SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQLAGG_INT("500 + SUM(%1)", [Sales])</pre><p>In this example, %1 is equal to [Sales].</p></td></tr></tbody></table>

### RAWSQL\_REAL

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQL_REAL("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Numeric</td></tr><tr><td>Definition</td><td>Returns a numeric result from a given SQL expression.</td></tr><tr><td>Example</td><td><pre>RAWSQL_REAL("-123.98 * %1", [Sales])</pre><p>In this example, %1 is equal to [Sales]</p></td></tr></tbody></table>

### RAWSQLAGG\_REAL

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQLAGG_REAL("sql_expr", [arg1,] …[argN])</code></td></tr><tr><td>Output</td><td>Numeric</td></tr><tr><td>Definition</td><td>Returns a numeric result from a given aggregate SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQLAGG_REAL("SUM( %1)", [Sales])</pre><p>In this example, %1 is equal to [Sales].</p></td></tr></tbody></table>

### RAWSQL\_SPATIAL

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQL_SPATIAL("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>Spatial</td></tr><tr><td>Definition</td><td>Returns a spatial result from a given SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQL_SPATIAL("%1", [Geometry])</pre><p>In this example, %1 is equal to [Geometry].</p></td></tr><tr><td>Note</td><td>There is no <code>RAWSQLAGG</code> version of this function.</td></tr></tbody></table>

### RAWSQL\_STR

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQL_STR("sql_expr", [arg1], …[argN])</code></td></tr><tr><td>Output</td><td>String</td></tr><tr><td>Definition</td><td>Returns a string from a given SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQL_STR("%1", [Customer Name])</pre><p>In this example, %1 is equal to [Customer Name].</p></td></tr></tbody></table>

### RAWSQLAGG\_STR

<table class="table--plain" style="width: 100%;"><colgroup><col style="width: 20%;"><col></colgroup><tbody><tr><td>Syntax</td><td><code>RAWSQLAGG_STR("sql_expr", [arg1,] …[argN])</code></td></tr><tr><td>Output</td><td>String</td></tr><tr><td>Definition</td><td>Returns a string from a given aggregate SQL expression.</td></tr><tr><td>Example</td><td><pre xml:space="preserve">RAWSQLAGG_STR("AVG(%1)", [Discount])</pre><p>In this example, %1 is equal to [Discount].</p></td></tr></tbody></table>