Divide
Scalar
Divide(a, b [, fallback])
Returns a / b, but blank — or fallback if given — when the divisor is 0 or blank. This is the one place SquareX deliberately papers over SQL. Use it for every ratio; the plain / operator raises database errors on zero.
When to use it
Section titled “When to use it”- Every ratio you ever chart: average order value, conversion rate, margin %, share of total.
- Anywhere a zero-denominator group would otherwise crash the whole query.
Example
Section titled “Example”AvgOrderValue := Divide([Revenue], [Orders])Under the hood
Section titled “Under the hood”AvgOrderValue := Divide([Revenue], [Orders])CASE WHEN COUNT(DISTINCT "Sales"."order_id") = 0 OR COUNT(DISTINCT "Sales"."order_id") IS NULL THEN NULL ELSE CAST(SUM("Sales"."amount") AS FLOAT) / COUNT(DISTINCT "Sales"."order_id")ENDThe cast also guarantees real (not integer) division on every database.