MIN: from Tableau to SQL

Returns the least non-null value. Below, 8 sample rows go through the calculation and through the SQL, and both return the same numbers.

Calculated field

MIN([amount])

Sample data

idamountunitsscoreother
1-2.52-0.83
20004
31.530.252
4440.58
5950.811
6166114
7null7null9
848-0.5null

The same calculation as SQL

SELECT min(amount) AS result FROM input

Runs the example above.

Result

result
-2.5

Same rows from the calculation and from the SQL in DuckDB.

Where a naive translation goes wrong

  • Filtering out zero and negative observations can change the aggregate.

    Naive SQL

    SELECT min(amount) FILTER (WHERE amount>0) AS result FROM input
    result
    1.5

    Matches the calculation

    SELECT min(amount) AS result FROM input
    result
    -2.5

Signature

MIN(expression, [expression])