Skip to main content

Expressions and data-defined values

Outcome: create reusable expressions that derive display and analysis values while leaving source fields intact.

QGIS expressions appear throughout labels, field calculator, symbology, layouts, forms and Processing.

Start with safe display logic

For an ingoa wāhi layer:

coalesce("name_display", "name_official", "name_historical")

This chooses a display value. It does not delete the other names.

Build a source-aware label

coalesce("name_display", "name_official") ||
CASE
WHEN "location_status" = 'approximate' THEN ' ~'
ELSE ''
END

Use a symbol or label cue for approximate locations instead of pretending all points have equal certainty.

Calculate without permanently writing when appropriate

Virtual fields are useful where a value should update automatically. Permanent fields are better where the value is a recorded observation or needs to travel cleanly outside QGIS.

For area in hectares:

$area / 10000

Only use this when the layer CRS supports meaningful area calculation for the purpose.

Conditional classification

Example project status:

CASE
WHEN "last_checked" IS NULL THEN 'not checked'
WHEN days_between("last_checked", now()) > 180 THEN 'review due'
ELSE 'current'
END

Treat the 180-day rule as a project rule, not a universal GIS truth.

Data-defined cartography

Click the data-defined override button beside a symbol/label property. Useful examples:

  • label size from label_priority
  • line width from route class
  • opacity from confidence
  • symbol rotation from a direction field

Use expressions to make the map reflect structured attributes rather than manual per-feature styling.

Debug expressions

Use the expression preview and test several records, including null values. A working expression on the first row can still fail semantically on blank or unusual records.

Exercise

Add location_status and label_priority to a teaching place-name layer. Create a label expression that marks approximate locations and a data-defined font size based on priority.

Check

  • source name fields remain unchanged
  • null values do not produce NULL text in labels
  • rules can be explained in plain language
  • expression logic is recorded in project notes if it affects interpretation

Next: Advanced labels and symbology.

Official reference: QGIS expressions.

Last reviewed: 26 August 2026