MAKELINE(MAKEPOINT([Lat], [Lon]), MAKEPOINT([DestLat], [DestLon])) draws a straight line from each depot to its destination: a two-point LineString. In SQL it is ST_MakeLine(ST_Point(Lon, Lat), ST_Point(DestLon, DestLat)), longitude first. If either point is missing there is no line. 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?
MAKELINE(start_point, end_point)
start_point, end_point
spatial points, usually MAKEPOINT(lat, lon) calls.
Returns a spatial line from the first point to the second. Null when either point 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.
SELECTCASEWHEN Lat ISNULLOR Lon ISNULLOR DestLat ISNULLOR DestLon ISNULLTHENNULLELSEjson_object('type', 'LineString', 'coordinates', [[Lon, Lat], [DestLon, DestLat] ])
ENDAS result
FROM input
ORDERBY id
Each line runs from the depot to the destination. Hue has no depot longitude, so it has no line.
Lat
Lon
DestLat
DestLon
Result
10.78
107
10.05
106
[object Object]
21.03
106
20.84
107
[object Object]
16.05
108
16.46
108
[object Object]
16.46
15.88
108
null
✓ The Tableau formula and the SQL return the same 4 rows.
SELECTCASEWHEN Lat ISNULLOR Lon ISNULLOR DestLat ISNULLOR DestLon ISNULLTHENNULLELSEjson_object('type', 'LineString', 'coordinates', [[DestLon, DestLat], [Lon, Lat] ])
ENDAS result
FROM input
ORDERBY id
The same line, drawn the other way: the first argument is where it starts.
Lat
Lon
DestLat
DestLon
Result
10.78
107
10.05
106
[object Object]
21.03
106
20.84
107
[object Object]
16.05
108
16.46
108
[object Object]
16.46
15.88
108
null
✓ The Tableau formula and the SQL return the same 4 rows.
Where does a straight translation go wrong?
Common mistake
Why does a route appear for a depot with no longitude?
MAKELINE needs both points; with one missing it returns null. A hand-built LineString still comes back as an object with a null coordinate inside. Return null when any coordinate is missing.
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.
Does the line follow the curve of the earth?
The line stores just two points. How it is drawn between them depends on the tool: a geography type in Snowflake or BigQuery treats it as the shortest path on the sphere; a planar GEOMETRY treats it as a straight line on the coordinate plane.