Skip to main content

Expressions

This page helps you to understand how to use the expressions in the Dashboard widgets. You can enter expressions in the Numbers, Categories, and Pie chart widgets. We're listing and describing the expressions that you could use in GOAT.

They work the same way as in QGIS, and by combining them you can compute more complex calculations or filter your data.

info

When referring to a field, insert it only in paratheses: (FieldName).

Numeric functions

The following functions work with number fields only. The input and the output will be numeric values.

ExpressionFunctionExample
abs(x)returns the absolute value of a number = 5
sqrt(x)returns the square root of a number = 4
pow(x, y)raises x to the power of y = 8
exp(x)returns e raised to the power of x = 2,718...
ln(x)natural logarithm (base e) of x, inverse of exp = 2.303...
log10(x)logarithm base 10 of x = 2
round(x, n)rounds a number x to n decimal places = 1.24
ceil(x)rounds up to the next whole numer = 2
floor(x)rounds down to the previous whole numer = 1
pireturns the value of π = 3.142....
sin(x)returns the sine of x (radians) = 0.841...
cos(x)returns the cosine of x (radians) = 0.541...
tan(x)returns the tangent of x (radians) = 0.932...
asin(x)returns the arcsine of x (radians) = 1.571...
acos(x)returns the arccosine of x (radians) = 1.047...
atan(x)returns the arctangent of x (radians) = 0.785...
degrees(x)converts angle x from radians to degrees = 57.296...
radians(x)converts angle x from degrees to radians = 3.142...
rand(x, y)generates a random number between x and y = 3.17

String functions

The following functions work with text fields only. The input and the output will be text values.

ExpressionFunctionExample
length(string)returns the number of characters in a string excluding space = 8
char_length(string)returns the number of characters in a string including space = 9
upper(string)converts all letters to uppercase = WALKING
lower(string)converts all letters to lowercase = goat
trim(string)removes leading and trailing spaces = biking
ltrim(string)removes spaces only on the left side = biking
rtrim(string)removes spaces only on the right side = biking
substr(string, start, length)returns a substring starting at start position with optional length = mob
substring(string, start, length)returns a substring starting at start position with optional length = mob
left(string, n)returns the leftmost n characters = acce
right(string, n)retunrs the rightmost n characters = lity
replace(string, search, replace_with)replaces all occurences of one substring with another = bike lane
regexp_replace(string, pattern, replacement)uses regular expressions to find and replace part of a text = BusStop#
regexp_substr(string, pattern)extracts the first substring that matches a regular expression pattern = 45
strpos(string, substring)returns the position (index) where a substring first appears and returns 0 if not found = 5
concat(a,b...)joins multiple strings or fields together

Date time functions

The following functions work with date/time fields only. The input and the output will be date/time values.

ExpressionFunctionExample
now()returns the current date and time = 2025-10-07 11:35:00
age(date1, date2)returns the time interval between two dates = 25 years 3 mons 12 days
extract(part, date)extracts a specific component from a date (year, month, day, hour, minute, second) = 2025
date_part(part, date)similar to extract returns the specified part of a date = 10
mmake_date(year, month, day)creates a date from numeric year, month, day = 2025-10-08
make_time(hour, minute, second)creates a time from numeric hour, minute, second = 14:30:00
make_timestamp(year, month, day, hour, minute, second)combines date and time into a timestamp = 2025-10-08 14:30:00
to_date(string, format)converts a text string to a date using the given format = 2025-10-08
to_timestamp(string, format)converts a text string to a timestamp using the given format = 2025-10-08 14:30:00
to_char(date, format)converts a date or timestamp to a formatted text string = '2025-10-08'

Casting functions

The following functions convert a value from one type to another. The input and the output will be of different types.

ExpressionFunctionExample
to_int(x)converts x to an integer (whole number) = 3
to_real(x)converts x to a real (decimal) number = 3.9
to_string(x)converts x to a text string = '25'

Generic functions

The following functions work with any type of field. The input and the output will be of the same type.

ExpressionFunctionExample
coalesce(x, y, ...)returns the first non-null value from the given list of inputs
nullif(x, y)returns NULL if x equals y, otherwise returns x = NULL

Aggregate functions

The following functions work with any type of field. The input and the output will be of the same type.

ExpressionFunctionExample
sum(field)returns the total sum of all values in a field (or group) = 15230
avg(field)returns the average (mean) value of a field = 12.6
min(field)returns the smallest (minimum) value in a field = 0.5
max(field)returns the largest (maximum) value in a field = 18.2
count(field)returns the number of features or non-null values in a field = 347

Metric unary functions

ExpressionFunctionExample
$areareturns the area of a polygon feature in the layer’s coordinate units (e.g., m²) = 12500
ST_Area(geometry)returns the area of a specified geometry; used in expressions with geometry functions = 12500
$lengthreturns the length of a line feature in layer units (e.g., meters) = 275.3
ST_Length(geometry)returns the length of a given geometry (line or polygon boundary) = 275.3
perimeterreturns the perimeter length of a polygon feature = 490.6
ST_Perimeter(geometry)returns the perimeter of a geometry, similar to perimeter() but following the PostGIS standard naming = 490.6

Metric buffer function

ExpressionFunctionExample
buffer(geometry, distance)creates a polygon buffer around a geometry at the specified distance (in layer units, e.g. meters) = Polygon representing a 100 m buffer area

Geometry unary functions

ExpressionFunctionExample
centroid(geometry)returns the center point (geometric middle) of a feature = Point(13.41, 52.52)
ST_Centroid(geometry)same as centroid(), follows PostGIS naming convention = Point(13.41, 52.52)
convex_hull(geometry)creates the smallest convex polygon that encloses all parts of a geometry = Polygon(...)
ST_ConvexHull(geometry)same as convex_hull(), using PostGIS syntax = Polygon(...)
envelope(geometry)returns the minimum bounding rectangle of a geometry = Polygon((xmin, ymin), (xmax, ymax))
ST_Envelope(geometry)same as envelope(), in PostGIS form = Polygon(...)
make_valid(geometry)fixes invalid geometries (e.g. self-intersections, gaps) = Polygon(...)
ST_MakeValid(geometry)same as make_valid(), PostGIS version = Polygon(...)
is_empty(geometry)returns TRUE if geometry has no spatial content = FALSE
ST_IsEmpty(geometry)same as is_empty(), PostGIS form = FALSE
is_valid(geometry)returns TRUE if geometry is valid = TRUE
ST_IsValid(geometry)same as is_valid(), PostGIS version = TRUE
x(geometry)returns the X-coordinate of a point geometry = 13.405
ST_X(geometry)same as x(), PostGIS version = 13.405
y(geometry)returns the Y-coordinate of a point geometry = 52.520
ST_Y(geometry)same as y(), PostGIS version = 52.520
xmin(geometry)returns the minimum X-coordinate (left boundary) of a geometry = 13.30
ST_XMin(geometry)same as xmin(), PostGIS syntax = 13.30
xmax(geometry)returns the maximum X-coordinate (right boundary) of a geometry = 13.50
ST_XMax(geometry)same as xmax(), PostGIS syntax = 13.50
ymin(geometry)returns the minimum Y-coordinate (bottom boundary) of a geometry = 52.45
ST_YMin(geometry)same as ymin(), PostGIS version = 52.45
ymax(geometry)returns the maximum Y-coordinate (top boundary) of a geometry = 52.55
ST_YMax(geometry)same as ymax(), PostGIS version = 52.55

Here are some examples of combined expressions for more complex calculations: https://github.com/plan4better/goat/blob/main/apps/core/src/core/expression_converter.py

tip

Find further information in the QGIS documentation.