# Tableau Calculated Fields to Databricks SQL: Function Mapping and Conversion Reference

> Map Tableau calculated fields to Databricks SQL function by function: where each field lands in AI/BI, plus the null, date and type traps that change numbers.

- Canonical: https://getantares.io/tableau-calculated-fields-to-databricks-sql/
- Published: 2026-09-08
- Updated: 2026-09-08

---

A Tableau calculated field lands in one of three places in Databricks AI/BI: a column in the dataset SQL, a calculated dimension or measure on the dataset, or a measure in a Unity Catalog metric view. Which one you pick follows from whether the field is row-level, aggregate, or shared across dashboards.

The function names are the easy half. The argument orders and null rules below are what let a converted formula run cleanly and still return a different number.

## Where a calculated field lands in Databricks AI/BI

Tableau keeps every calculation inside the workbook. Databricks AI/BI spreads them across three layers, and the layer you choose decides who else can reuse the logic and when it runs. The third of them, a metric view, is a measure definition stored in Unity Catalog rather than inside a dashboard.

| Tableau calculated field | Where it goes in Databricks AI/BI | Why |
| --- | --- | --- |
| Row-level, used as a dimension, filter, or grouping | A column in the dataset SQL | The value belongs to the data, and other datasets can select it |
| Row-level, needed by one dashboard only | Calculated dimension | Added on the dataset without editing the query |
| Aggregate, such as `SUM`, `AVG`, `COUNTD` | Calculated measure | Re-aggregates automatically against whatever the chart groups by |
| Aggregate reused across dashboards and notebooks | Measure in a Unity Catalog metric view | Defined once, resolved at query time by every consumer |
| LOD expression | Window form of a custom calculation, or dataset SQL | [LOD expressions](/tableau-lod-expressions-to-databricks-sql/) |
| Table calculation | `AGGREGATE OVER` measure, or a SQL window function | [Table calculations](/tableau-table-calculations-to-databricks/) |

[Custom calculations](https://docs.databricks.com/aws/en/dashboards/manage/data-modeling/custom-calculations/) are scoped to the dataset and dashboard where they are defined, up to 200 per dataset, and results of 100,000 rows and 100MB or less compute in the browser rather than on the SQL warehouse (as of September 2026). Table visualizations accept calculated dimensions but not calculated measures, which bites in a rebuilt Tableau crosstab. [Dataset queries are read-only](https://docs.databricks.com/aws/en/dashboards/manage/data-modeling/datasets), so logic needing a temporary table belongs upstream.

## How the functions map

Signatures below come from the Databricks SQL language manual and [Tableau's function reference](https://help.tableau.com/current/pro/desktop/en-us/functions_all_categories.htm). Read the notes before any find and replace: `DATEDIFF` reverses its dates in one of its two Databricks forms and keeps them in the other.

| Tableau | Databricks SQL | Note |
| --- | --- | --- |
| `IF ... THEN ... ELSEIF ... ELSE ... END` | `CASE WHEN ... THEN ... ELSE ... END` | Tableau's `CASE [x] WHEN` maps to `CASE expr WHEN` |
| `IIF(test, then, else, [unknown])` | `iff(cond, expr1, expr2)` | Three arguments only; Tableau's optional unknown value needs its own branch |
| `ZN([x])` | `[zeroifnull(x)](https://docs.databricks.com/aws/en/sql/language-manual/functions/zeroifnull)` | A documented synonym for `coalesce(x, 0)`; prefer coalesce, since the `zeroifnull` page is labeled for Databricks Runtime 16.0 and above |
| `IFNULL(a, b)` / `ISNULL([x])` | `ifnull(a, b)`, `nvl(a, b)` or `coalesce(a, b)` / `isnull(x)` | Same argument order in all three; `isnull` returns a boolean |
| `DATEDIFF('day', [start], [end])` | `[datediff(end, start)](https://docs.databricks.com/aws/en/sql/language-manual/functions/datediff)` | **Argument order reverses**, and this form counts whole days only |
| `DATEDIFF('month', [start], [end])` | `[datediff(MONTH, start, end)](https://docs.databricks.com/aws/en/sql/language-manual/functions/datediff3)` | Keeps Tableau's order and takes an unquoted keyword; Databricks counts *whole elapsed units*, so check month and year differences against the workbook |
| `DATETRUNC('month', [d])` / `DATEPART('year', [d])` | `date_trunc('MONTH', d)` / `date_part('YEAR', d)` | Unit is a quoted string literal; `date_trunc` returns a `TIMESTAMP` |
| `DATEADD('month', 3, [d])` | `dateadd(MONTH, 3, d)` | Same order, unquoted unit, timestamp input |
| `CONTAINS` / `STARTSWITH` / `ENDSWITH` | `contains(expr, subExpr)`, `startswith`, `endswith` | Same order; matching is case-sensitive, so `endswith('SparkSQL', 'sql')` is false |
| `SPLIT(string, delimiter, token)` | `split_part(str, delim, partNum)` | A negative part number counts from the right in both |
| `REGEXP_EXTRACT(string, pattern)` | `regexp_extract(str, regexp [, idx])` | `idx` defaults to 1, the first capture group |
| `INT` / `FLOAT` / `STR` / `DATE` | `cast(x AS BIGINT / DOUBLE / STRING / DATE)` | `[try_cast](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_cast)` returns `NULL` instead of failing on bad input |
| `COUNTD([x])` | `count(DISTINCT x)` | `approx_count_distinct(x)` trades exactness for speed |
| `ATTR([x])` | No direct equivalent | Tableau returns an asterisk when values differ; in SQL pick `min(x)` or `any_value(x)` |
| `SUM([a]) / SUM([b])` | `[try_divide(SUM(a), SUM(b))](https://docs.databricks.com/aws/en/sql/language-manual/functions/try_divide)` | Plain division by zero raises `DIVIDE_BY_ZERO` |

## What changes about nulls, dates and types

A formula that compiles is not a formula that agrees with the old dashboard. These differences surface in a total rather than in an error message.

| Difference | What Databricks SQL does | What to write instead |
| --- | --- | --- |
| Nulls in comparisons | `x <> 'A'` is null when `x` is null, so the row fails the test, as in Tableau, but easy to lose when a workbook relied on a `[Field] != 'A'` quick filter | Handle nulls on purpose with `isnull(x)` or `coalesce(x, 'Unknown')` |
| Division by zero | Raises `[DIVIDE_BY_ZERO](https://docs.databricks.com/aws/en/error-messages/divide-by-zero-error-class)`, SQLSTATE 22012, rather than returning a null | `try_divide(a, b)`, which returns `NULL` for a zero divisor |
| Start of week | Weeks start Monday: `date_trunc('WEEK', d)` truncates to Monday | Check any Tableau formula that passed a `start_of_week` argument |
| Date part names | Quoted string for `date_trunc` and `date_part`, unquoted keyword for `dateadd` and unit-form `datediff` | Copy the unit list from each function page |

## When to promote a calculation to a metric view

A [Unity Catalog metric view](https://docs.databricks.com/aws/en/uc-semantics/metric-views/) separates measure definitions from the fields used to group, filter and aggregate them, so a metric is defined once and resolved at query time by notebooks, dashboards, Genie Agents and alerts. A formula that exists to make one chart work is a calculated measure; a formula three teams argue about is a metric view.

In a migration the useful test is duplication. When one revenue definition turns up in eleven workbooks with four slightly different filters, converting each copy faithfully rebuilds the disagreement inside a new tool. Promote the shared definitions first and leave one-off calculations local. Nobody wrote those eleven copies carelessly: a deadline is always closer than a modeling meeting.

## What Antares does with calculated fields

Reading a workbook's calculated fields by hand is the part of scoping nobody wants to do twice. The free Analyzer does that pass deterministically, on metadata alone, without touching the source environment, and returns an inventory of the estate. The Converter is deterministic-first with guardrailed, validated AI steps, and any construct it cannot verify is flagged instead of guessed at.

That division is the whole job of a BI migration tool: the mapping is mechanical, and the judgment calls, including which definitions deserve a metric view, stay yours. Tableau to Databricks AI/BI is a shipped route, at a flat $200 per source dashboard with LLM costs on top, typically under $20. [Try a sample conversion](https://try.getantares.io) before you scope your own workbooks.

Next in this cluster: [LOD expressions in Databricks SQL](/tableau-lod-expressions-to-databricks-sql/) for the pinned aggregates, [table calculations in Databricks AI/BI](/tableau-table-calculations-to-databricks/) for the window functions, and the [migration guide](/tableau-to-databricks-ai-bi-migration/) for the order of the work. The Power BI twin of this page is [Tableau calculated fields to DAX](/tableau-calculated-fields-to-dax/). Sources: the Databricks [custom calculation function reference](https://docs.databricks.com/aws/en/dashboards/manage/data-modeling/custom-calculations/function-reference), Tableau's [type conversion functions](https://help.tableau.com/current/pro/desktop/en-us/functions_functions_typeconversion.htm) and its guide to [aggregate calculations](https://help.tableau.com/current/pro/desktop/en-us/calculations_aggregation.htm).

## Related resources

- [Tableau to Databricks AI/BI Migration](/tableau-to-databricks-ai-bi-migration/)
- [LOD Expressions to Databricks SQL](/tableau-lod-expressions-to-databricks-sql/)
- [Table Calculations to Databricks AI/BI](/tableau-table-calculations-to-databricks/)
- [Calculated Fields to DAX](/tableau-calculated-fields-to-dax/)

## FAQ

### Where do Tableau calculated fields go in Databricks AI/BI?

Into one of three homes. Row-level fields used as dimensions belong in the dataset SQL or as a calculated dimension. Aggregate fields become calculated measures on the dataset. Definitions shared across dashboards, notebooks and Genie Agents belong in a Unity Catalog metric view, where they are resolved at query time.

### Does Databricks SQL DATEDIFF work like Tableau DATEDIFF?

Not in its two-argument form. Tableau writes DATEDIFF('day', start, end); the Databricks two-argument datediff(end, start) reverses those dates and counts whole days only. The unit form, datediff(unit, start, end), keeps Tableau's order and takes an unquoted keyword such as MONTH or QUARTER.

### What replaces ZN and IFNULL in Databricks SQL?

ZN(x) becomes zeroifnull(x), which Databricks documents as a synonym for coalesce(x, 0); coalesce is the portable form, since the zeroifnull page is labeled for Databricks Runtime 16.0 and above. IFNULL(a, b) becomes ifnull(a, b), nvl(a, b) or coalesce(a, b), all with the same argument order. For ratios, try_divide returns NULL rather than raising DIVIDE_BY_ZERO.

### Should a converted calculation be a custom calculation or a metric view?

Custom calculations are scoped to one dataset on one dashboard, capped at 200 per dataset as of September 2026. That fits a formula serving a single chart. A definition several dashboards depend on belongs in a Unity Catalog metric view, so Genie Agents and notebooks answer from the same numbers.
