Tableau function Spatial

Tableau MAKEPOINT to SQL

MAKEPOINT([Lat], [Lon]) turns two coordinate columns into a point you can map. Tableau takes latitude first; SQL spatial functions take longitude first: DuckDB ST_Point(Lon, Lat), Snowflake ST_MAKEPOINT(Lon, Lat). A missing coordinate gives no point at all. The runnable SQL builds the same GeoJSON the engine returns with json_object, because this page's DuckDB has no spatial extension. With the extension loaded, the DuckDB call is shown in the FAQ.

Updated · Checked on the xmetric engine

What is the syntax?

MAKEPOINT(latitude, longitude)
latitude
degrees north, from -90 to 90.
longitude
degrees east, from -180 to 180.

Returns a spatial point (WGS84). Null when either coordinate is null.

What does it return, and what is the SQL?

Each example runs on the same 4 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.

Where is each depot?

Tableau

MAKEPOINT([Lat], [Lon])

SQL (DuckDB)

SELECT
  CASE
    WHEN Lat IS NULL OR Lon IS NULL THEN NULL
    ELSE json_object('type', 'Point', 'coordinates', [Lon, Lat])
    END AS result
FROM input
ORDER BY id

The GeoJSON coordinates are [longitude, latitude]. Hue has no longitude, so it gets no point.

LatLonResult
10.78107[object Object]
21.03106[object Object]
16.05108[object Object]
16.46null

The Tableau formula and the SQL return the same 4 rows.

Where is each delivery going?

Tableau

MAKEPOINT([DestLat], [DestLon])

SQL (DuckDB)

SELECT
  CASE
    WHEN DestLat IS NULL OR DestLon IS NULL THEN NULL
    ELSE json_object('type', 'Point', 'coordinates', [DestLon, DestLat])
    END AS result
FROM input
ORDER BY id

Every row has both destination coordinates.

DestLatDestLonResult
10.05106[object Object]
20.84107[object Object]
16.46108[object Object]
15.88108[object Object]

The Tableau formula and the SQL return the same 4 rows.

Where does a straight translation go wrong?

Common mistake

Why does a hand-built point exist for a row with no longitude?

MAKEPOINT returns null when a coordinate is missing, so Hue has no point. json_object builds an object anyway, with a null inside, and the row looks mapped. Return null when either coordinate is null; DuckDB's ST_Point does that on its own.

Tableau

ISNULL(MAKEPOINT([Lat], [Lon]))

Tempting SQL

SELECT
  json_object('type', 'Point', 'coordinates', [Lon, Lat]) IS NULL AS result
FROM input
ORDER BY id

SQL that matches

SELECT Lat IS NULL OR Lon IS NULL AS result
FROM input
ORDER BY id
LatLonTableauTempting SQLSQL that matches
10.78107falsefalsefalse
21.03106falsefalsefalse
16.05108falsefalsefalse
16.46truefalsetrue

The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.

How do I write it in Snowflake or BigQuery?

The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.

Snowflake

SELECT ST_MAKEPOINT(Lon, Lat) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT ST_GEOGPOINT(Lon, Lat) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own MAKEPOINT formula return?

Edit the formula and run it on the 4 sample rows. Fields: [id], [Depot], [Lat], [Lon], [DestLat], [DestLon], [Wkt], [Route].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about MAKEPOINT?

Which comes first, latitude or longitude?

Tableau's MAKEPOINT takes latitude first. SQL spatial functions and WKT take x first, which is longitude: DuckDB ST_Point(Lon, Lat), Snowflake ST_MAKEPOINT(Lon, Lat), BigQuery ST_GEOGPOINT(Lon, Lat). Swapping them puts Saigon (10.78 N, 106.70 E) off the map, since 106.70 is not a valid latitude.

What is the DuckDB call with the spatial extension?

INSTALL spatial; LOAD spatial; then ST_Point(Lon, Lat), which returns a GEOMETRY. ST_AsGeoJSON turns it into the same GeoJSON shown here.

Where is this documented?