Every QGIS layer carries two halves: the geometry you see and the attribute table you mostly ignore, until the day you need a column that does not exist. Area in hectares. A label built from a name and a code. A category sorted out of a messy text field. The Field Calculator is the tool for that day: a dialog that applies an expression, a small formula in QGIS's expression language, to every feature in a layer at once, writing the results into a new field or updating an existing one. It is the single highest-leverage dialog in QGIS for data work, and it rewards learning properly, because its failure modes are silent: fields of NULLs, numbers stored as text, strings quietly amputated at a width you chose without thinking. This guide walks the dialog, teaches the starter expressions that cover most real work, and flags the traps before they bite.
Home / GIS and Open Map Data for Beginners
QGIS Field Calculator: Build and Fix Attributes With Expressions

Photo: Mikhail Nilov / Pexels
Calculate With a Net: The Field Calculator Checklist
Check off each step as you finish it. Your progress stays on this page.
0 of 8 complete
0% done
What the Field Calculator Is For
Reach for it whenever a value you need is a function of values you have. The canonical jobs: computing geometry properties, area, length, centroid coordinates, into real columns that other tools can read; cleaning and standardizing text, trimming, casing, extracting codes; deriving categories with conditional logic; building label strings from multiple fields; and converting units at scale. The alternative, editing cells by hand or exporting to a spreadsheet and back, fails on size, on repeatability, and on the join you will inevitably fumble. The Field Calculator keeps the operation inside the layer, applies it uniformly, and, crucially, shows you a preview of the result on a sample feature before committing, which makes it safer than it looks. It operates on the layer's own fields and geometry; when the value you need lives in a different layer entirely, that is a join's job, and our guide to joining attributes by field value covers the companion operation.
Anatomy of the Dialog
Open it from the attribute table toolbar or the layer menu; the abacus icon is its traditional mark. The dialog divides into decisions. First, the target: create a new field, or update an existing one. New fields demand a name, a type, integer, decimal number, text, or date, and for text and decimals, a width and precision, choices that become permanent for file-based formats and deserve a breath of thought. Second, the expression: a large editing box fed by the function list beside it, which is searchable and documents every function with examples, effectively a reference manual built into the tool. Double-clicking a field name inserts it in double quotes, functions arrive with their syntax skeleton, and operators line the top. Third, the preview: at the bottom, the dialog evaluates your expression against a sample feature and shows the result live, turning red-flag guesswork into a checkable fact before a single row is written. Finally, scope: by default the expression applies to all features, but with features selected in the attribute table, an option restricts the update to the selection, the safe way to fix a subset without touching the rest.

Your First Three Expressions
Learn three patterns and you can derive most of what beginners need. Geometry first: with a new decimal field named area_ha, the expression $area / 10000 computes each polygon's area in square meters from the geometry and converts it to hectares, provided your layer is in a projected CRS whose units are meters; in a degrees-based layer $area returns square degrees, a nonsense unit, which is why our area calculation guide insists on reprojection first. Text second: concatenation uses the double-pipe operator, so "name" || ' (' || "code" || ')' builds a label like Springfield (042) from two fields, with literal text in single quotes and field names in double quotes, the distinction the whole language hinges on. Logic third: CASE WHEN "population" >= 100000 THEN 'city' WHEN "population" >= 10000 THEN 'town' ELSE 'village' END classifies in one pass, evaluated top to bottom, first match wins. Each pattern previews before it writes; build the habit of reading that preview against a feature whose answer you already know.
The Mistakes That Bite
Four traps produce most Field Calculator misery. Type mismatch: storing a computed number into an integer field truncates decimals without complaint, and storing numbers as text makes them sort alphabetically, 1, 10, 2, and breaks later math; choose types deliberately and convert explicitly with to_int, to_real, or to_string when crossing. Width amputation: a text field created with width 10 will hold exactly ten characters of your twenty-character label in formats that enforce width; give text fields generous width. NULL propagation: any arithmetic touching a NULL returns NULL, so one missing source value silently hollows its row; guard with coalesce("field", 0) where a default is honest, and treat a column of fresh NULLs as the signature of a misspelled field name or a type clash, not bad luck. And the silent selection: running an update with a selection active, or an editing session in an unexpected state, can apply your expression to fewer rows than you think; glance at the feature count the dialog reports. Every one of these is cheap to check in the preview and expensive to discover downstream.
Verify Before You Trust the Column
Treat a calculated field like any measurement: prove it on samples before building on it. Sort the attribute table by the new column and eyeball the extremes, the largest area, the longest label, since errors concentrate at the edges. Spot-check three features by hand: recompute one area from known dimensions, read one concatenated label aloud, trace one CASE classification against its rule. Check the NULL count: filter the column for NULLs and ask whether each absence is a true missing value or a symptom. If the field feeds a join, a filter, or a delivered dataset, save and reopen the layer to confirm the values persisted as expected in the file, not just in the session. The Field Calculator is fast enough to redo anything, which is precisely why verification is affordable: the preview, three spot checks, and a NULL census take two minutes and stand between you and the particular embarrassment of a beautiful map built on a hollow column.
Expressions Worth Keeping: A Small Working Library
Beyond the starter patterns, a handful of expressions recur across real projects often enough to memorize. Cleaning text: trim("name") strips the leading and trailing spaces that poison joins and sorts, and upper or lower normalize case before matching. Extracting from codes: substr("code", 1, 2) pulls the first two characters of a composite code, and string functions like left, right, and regexp_replace dismantle the formatted identifiers every real dataset hoards. Rounding honestly: round($area / 10000, 2) reports hectares to two decimals for display fields, while the unrounded value stays in its own column for analysis, a separation worth keeping. Conditional repair: CASE WHEN "status" IS NULL THEN 'unknown' ELSE "status" END fills gaps with an honest label instead of a silent blank. Geometry extras: $x and $y write a point layer's coordinates into fields, the first step of every export to a spreadsheet, and x(centroid($geometry)) with its y twin does the same for polygons. Conditional geometry: CASE combined with buffer or other geometry functions can even build new shapes per category, a reminder that the expression engine treats geometry as a value like any other. None of these is exotic; that is the point. The Field Calculator rewards a small, fluent vocabulary applied confidently over a large one applied hopefully, and the preview line remains the tutor that never tires: try the expression, read the sample result, adjust, and only then let it loose on ten thousand rows.
Working on Real Data: A Short Safety Protocol
Because the Field Calculator writes at scale, professionals wrap it in a small protocol that costs two minutes and prevents the classic disasters. Work on a copy, or save the project before a destructive update to an existing field, because an expression applied to ten thousand rows is ten thousand edits with no undo worth trusting. Prefer creating a new field over updating in place whenever the old values have any evidentiary value; storage is cheap and regret is expensive, and a superseded column can be deleted later with full knowledge of what replaced it. Write the expression down outside the dialog, in the project notes or a text file, because six months later the question "how was this column computed" deserves a better answer than archaeology, and the expression is the complete, honest provenance of the data. Finally, after calculating, glance at the layer's field list and confirm the new column's type and width are what you intended, since several formats quietly renegotiate both on save. None of this slows real work in any way that matters. It simply acknowledges what the tool is: not a calculator in the pocket sense, but a small programming environment pointed at your data, deserving the same version-control instincts you would bring to code.
Related Guides
If this page answered part of the question, these GIS and open map data guides cover the rest of the same ground:
- Fix Geometry in QGIS: Find Invalid Polygons and Repair Them to Zero Errors: Invalid geometry, self-intersecting polygons, duplicate nodes, rings that cross themselves, quietly breaks area calculations, spatial joins, and...
- QGIS Hillshade: Turn a DEM Into Readable Terrain, and Fix the Z-Factor Trap: A hillshade fakes sunlight across a DEM so terrain reads at a glance: ridges, valleys, and scarps pop out of what was a flat gray ramp.
- QGIS Spatial Join: Join Attributes by Location, Explained With Its Predicates: A spatial join answers the question every GIS user meets in the first month: these points know what happened, those polygons know where it counts,...
- QGIS Expression Builder: The One Dialog Behind Selection, Fields, and Styles: the shared dialog behind the calculator
Frequently Asked Questions
How do I open the Field Calculator in QGIS?
From the attribute table's toolbar or the layer's context menu; its icon is an abacus. It opens a dialog where you choose a new or existing field, write an expression, and preview the result on a sample feature before applying it to the layer.
What is the difference between field names and text in expressions?
Field names go in double quotes, "population", and refer to the column's values. Literal text goes in single quotes, 'city', and means exactly those characters. Mixing them up is the most common beginner error: it produces NULLs or the literal word repeated down the column.
Why did my calculated field come out all NULL?
Usually a misspelled field name, a type mismatch such as math on a text column, or NULLs in the source data propagating through the expression. Check the preview line while building the expression; it shows the failure on a sample feature before you commit to the whole layer.
Can the Field Calculator update only some features?
Yes. Select the features in the attribute table or on the map first, and the dialog offers to update only the selected features. Without a selection it applies to every feature in the layer.
Why are my calculated areas wrong?
Almost always the CRS. $area computes in the layer's coordinate units; in a geographic CRS those units are degrees, producing meaningless numbers. Reproject the layer to a projected CRS with meter units first, then calculate.
Photo credits: Mikhail Nilov (Pexels); Lukas Blazek (Pexels). Photos are served from this site; follow the credit to the library page for the original.