Learn one dialog in QGIS and you have quietly learned a dozen features. The Expression String Builder is the text engine room of the whole application: it opens when you select features by a rule, when the Field Calculator computes a new column, when a label needs to say something conditional, when a style property should vary feature by feature, and when a geometry generator conjures shapes from attributes. Most users meet it inside one host, learn just enough to escape, and then meet it again in the next host as a stranger. This guide takes the other path: it teaches the builder itself as the subject, its layout, its grammar, its preview, and its Function Editor, with the hosts visited as applications of one skill. Our field calculator guide goes deep on that single host; this guide is the map of the whole territory it belongs to.
Home / GIS and Open Map Data for Beginners
QGIS Expression Builder: The One Dialog Behind Selection, Fields, and Styles

Photo: Markus Spiske / Pexels
One Dialog, Every Tool: The Expression Builder Checklist
Check off each step as you finish it. Your progress stays on this page.
0 of 7 complete
0% done
Anatomy of the Dialog
However you arrive, the builder presents the same anatomy. On one side, the expression text area, where the expression is written and edited as ordinary text. Beside it, the function list, a searchable tree of everything the expression language can do, grouped by family: fields and values, conditionals, string functions, math, geometry, aggregates, dates, and more, each function carrying help that explains its arguments when selected. Double-clicking a function inserts it into the text; double-clicking a field name inserts it correctly quoted. Below or beside, the preview evaluates your expression against the current feature and shows the result, live, turning red or reporting an error when the expression is broken. That preview is the dialog's soul. It converts expression writing from a compile-and-pray ritual into a conversation: write a fragment, watch it evaluate, extend it, watch again. The last element, the Function Editor tab, is where expressions graduate into reusable custom functions, covered below. Learn to read the anatomy once and every host dialog afterward is a familiar room with the furniture rearranged.
The Grammar: Quotes, Fields, and Values
Expression errors are usually grammar errors, and the grammar has three rules worth burning in. Field names wear double quotes: "population", "area_km2". String values wear single quotes: 'urban', 'yes'. Numbers and functions wear nothing. Swap the quotes and the engine reads your field name as a literal string and your string as a missing field, and the preview's confusion becomes yours. Operators are the expected family, arithmetic, comparison, and the logical AND, OR, NOT, plus the workhorse conditional structures: the CASE WHEN ... THEN ... ELSE ... END for multi-way decisions, and IF(condition, then, else) for two-way ones. Two special citizens deserve introductions. The dollar functions address the feature's own geometry and identity: $area, $length, $id, and their kin, which is how a field calculator computes a polygon's area into a column. And the @ variables carry context from the project and layout, like the current map scale, for expressions that must adapt to where they are evaluated. Write expressions in small pieces and lean on the preview between pieces; the grammar is forgiving of everything except being guessed at in bulk.
Worked Examples From Real Hosts
Three examples, one per classic host, show the range. In Select By Expression, choosing every district where density exceeds a threshold is one line: "population" / "area_km2" > 5000, and the map highlights the answer set, ready to become its own layer. In the Field Calculator, building a clean label field from parts is string work: "name" || ' (' || "code" || ')' concatenates name, code, and punctuation into values like Riverside (RIV), and the || operator is the glue the whole language uses for text. As a data-defined override, the same language drives appearance: a label size that grows with population, a color that turns red when a reading exceeds its limit, each a small expression living inside the style instead of a static choice. Notice what the three share: fields in double quotes, strings in single, a result you can preview on one feature before applying it to ten thousand. Readers who met expressions through a live join should know that joined fields are citizens here too, readable by their prefixed names, so borrowed data can be selected, calculated, and styled exactly like native data.

The Function Editor: Saving Your Own Language
When an expression grows long enough to be pasted into a second project, it has earned promotion. The Function Editor tab lets you define a custom function, written in Python, with a name, arguments, and help text, after which it appears in the function list alongside the built-ins, in its own group, callable from every host. The classic candidates are the conversions and rules your organization repeats: a local land-cover reclassification, a risk score with your agency's exact weights, a formatting rule for the identifiers your national system uses. Custom functions live with your QGIS profile rather than inside a single project, which is both their power and their governance problem: a project that depends on your custom function will bewilder a colleague whose QGIS has never heard of it. The professional pattern is to keep the function's source in the project folder as a text file, load it where needed, and treat truly personal shortcuts as personal. Used that way, the Function Editor turns the builder from a dialog you visit into a language you extend, which is the moment QGIS starts feeling less like software you operate and more like an instrument you have tuned.
Habits That Keep Expressions Honest
Four habits separate expression writers whose work survives from those whose selections mysteriously empty. Preview against several features, not just the first: click through features with different shapes of data, an empty field, a zero, a NULL, because expressions meet their edge cases in the data's corners, and NULL in particular propagates: any arithmetic touching NULL returns NULL, which is honest but must be planned for with coalesce(field, 0) and its kin where a default is truly intended. Name output fields for their content and units, since the expression that computed them will be forgotten by Thursday. Keep a text file of proven expressions with the project; the builder has no memory across dialogs, and your future self deserves the recipe. And prefer readable expressions over clever ones: a CASE statement a colleague can audit beats a nested IF thicket that only its author can parse, because expressions in shared projects are documentation whether you intended them to be or not. The builder rewards this care disproportionately. It is the highest-leverage dialog in QGIS: an afternoon invested in it pays out in the field calculator, in selections, in labels, in styles, in the raster calculator's grid-side cousins, everywhere the application asks a question in its second language.
Geometry Generators and Data-Defined Everything
Two hosts deserve a closer look before we leave, because they show how far the language reaches. The geometry generator is a symbology option that draws shapes the layer does not store: buffers around points computed on the fly, lines connecting related features, the centroid of each polygon wearing a marker sized by an expression. Nothing is added to your data; the map simply draws what the expression describes, recalculated as the data changes, which makes it the right home for visualizations that are arguments rather than facts. Pair it with the restraint arguments deserve: a generated geometry is a claim about the data, and like the weighted sums of the raster world, its expression should be readable by the colleague who inherits the project. The second host is the humble data-defined override button, the small expression icon crouched beside nearly every property in the labeling and symbology panels: size, color, rotation, offset, visibility. Each one is a door from a static map to a responsive one, and each opens into this same dialog. A useful exercise for a quiet afternoon: open a familiar layer's label settings and count the override buttons. Every one you count is a place where a rule you write once will outperform a setting you would otherwise maintain by hand forever, and every one of them speaks the grammar this guide has been teaching.
Function Families Worth Meeting Early
The function list is long enough to intimidate, so meet it as families with jobs. Aggregates summarize across features: count the parcels per district, sum the areas, find the earliest date, the statistics of the zonal world speaking expression. Conditionals and logic, CASE and IF and their kin, turn rules into values and power half the symbology tricks in this guide. String functions clean the real world's text: trimming, casing, extracting the district code from the front of a messy address, the janitorial work every dataset needs exactly once and every expression writer needs weekly. Geometry functions measure and make: lengths, areas, centroids, buffers as values, the family the geometry generator host lives on. Array and map functions handle the multi-valued fields modern data loves, lists stored inside a single cell, and reward the patient disproportionately. Date and time functions parse the timestamps every sensor and survey produces. And the relation functions, the get_feature and overlay families, let an expression consult other layers, which is where expressions stop being formulas and start being small programs about the whole project. You do not need the catalog memorized; the dialog's search and help exist precisely so you do not. You need the families' shapes in your head, so that facing a new problem you can name which family's door to knock on, and let the reference pane handle the introductions.
Related Guides
Readers working through this topic usually need its closest companions too. These GIS and open data guides cover the neighboring ground:
- QGIS Field Calculator: Build and Fix Attributes With Expressions: The deepest single host: this dialog computing and repairing whole columns of attributes.
- QGIS Join by Attribute: The Live Joins Tab, From Shared Field to Saved Project: Joined fields are full citizens in expressions; this is how the borrowed data arrives.
- QGIS Raster Calculator: Band Math, Worked Expressions, and the Nodata Traps: The grid-side cousin, where expressions evaluate per cell instead of per feature.
- QGIS Zonal Statistics: Summarize a Raster by Polygon Zones: Where statistic columns come from, ready to be selected and styled by the expressions here.
- Rule-Based Symbology in QGIS: Styles Written as Conditions: The renderer where expressions stop selecting and start drawing.
Frequently Asked Questions
Where does the Expression Builder appear in QGIS?
Almost everywhere a rule is needed: Select By Expression, the Field Calculator, label and symbology data-defined overrides, geometry generators, and more. It is the same dialog in every host, so learning it once pays off across the application.
What is the difference between double and single quotes in expressions?
Double quotes mark field names, like "population". Single quotes mark literal string values, like 'urban'. Swapping them makes the engine read a field as text and a string as a field, the most common beginner error in the dialog.
How do I test an expression before applying it?
Use the live preview, which evaluates the expression against the current feature and reports errors immediately. Click through several features with different data, including empty and NULL values, before running anything across a whole layer.
What is the Function Editor for?
It lets you define custom functions in Python, with names and help text, which then appear in the function list like built-ins. Use it for the conversions and rules you repeat across projects, and keep the source file with the project so colleagues can load it too.
Why does my expression return NULL?
NULL propagates: any calculation touching a NULL field returns NULL. Where a default is intended, wrap the field with coalesce, as in coalesce("field", 0), and check the preview against features whose data has gaps.
Photo credits: Markus Spiske (Pexels); Rodrigo Santos (Pexels). Photos are served from this site; follow the credit to the library page for the original.