Adding & Calculating Fields in an Attribute Table

This tutorial covers adding a new field to a dataset’s attribute table and accessing options to calculate field values in a new or existing field.

 

Included in this tutorial:

  • Accessing and using the Add Field tool

  • Accessing and using the Field Calculator tool

Software version in examples: QGIS-LTR 3.40.5-Bratislava

Tutorial Data: The tutorial includes demonstration with sample data available here.

Credits: Sally Kaye and L. Meisterlin (2025)

 

Adding New Fields

Find and click the Toggle Editing pencil icon in the Attribute Table toolbar to toggle editing “on.” This will enable two field editing tools: Add Field and Delete Field. (When Toggle Editing is off, these icons are grayed out). 

To add a new field, click the Add Field icon. In the Add Field dialogue box, type the name of the new field and choose its type using the dropdown menu. In this example, we create a new text field named “NewText” and specify its length.

New fields are added in editing mode, meaning they can be deleted or edited before they are saved. To save new fields, click the save button in the toolbar of the attributes table or toggle editing off—you will be prompted to Save before leaving editing mode.

adding a new empty text field, called “NewText”


Calculating Field Values

Accessing the Field Calculator

Calculate values in an existing or new attribute table field using the Field Calculator. There are two options for accessing this tool—we demonstrate both below.

  1. Access the tool by clicking Open Field Calculator (an abacus icon) in the Attributes Toolbar.

  2. Find the same Open Field Calculator icon in the toolbar within the Attribute Table

accessing the field calculator from the attributes toolbar and the attribute table

NOTE: In both cases, the Field Calculator will operate upon the layer whose attribute table you started with. To calculate or add fields to a new table, close the Field Calculator dialogue box, select the name of or open the attribute table of a new layer, and reopen the Field Calculator as shown above.

Field Calculations and the Tool Dialogue Box

Field calculations in QGIS can be performed with Python expressions. Simple expressions can be typed directly into the Expression text box, while more complex functions might require the use of the Function Editor.

The basic outline of the dialogue box and its inputs are described below. A growing list of field calculation functions and helpers can be found here.

  • Use checkboxes to choose whether to Create a new field or Update existing field. 

    • If you are updating an existing field (calculating values in an existing field within your input table), use the dropdown menu to select which field to edit. 

    • If you are creating and calculating values in a new field, type a new output field name into the text box and use the dropdown menu to specify the output field type. (Note that you also have the option of creating a new “virtual” field which will not be saved to the dataset’s table but will be usable within the current project.)

  • Under the Expression tab, you can type directly into the text box and/or use a number of provided building blocks. 

    • The central panel of the Field Calculator includes functions, operators, and values you can use to build your expression. Most of these are accessed by expanding their headings within the panel. 

      • Any of these can be added to the expression text field by double-clicking on their name in the list. 

      • For example, you can call upon the values within any field of the input attribute table under the Fields and Values heading (expanding this heading is demonstrated below). 

    • Beneath the Expression text box is a small collection of the most common, familiar operator buttons. These include = equality, + addition, - subtraction, / division, and * multiplication, as well as others. You can click each of these to add the operator to your expression.

  • The Function Editor tab allows you to use Python to create a more complex expression, if needed. 

  • Click Apply or OK to execute the tool. 

Below, we demonstrate where to find basic field calculator inputs, but do not make any calculations.

displaying options in the Field Calculator dialogue box

 
Next
Next

Reprojecting Spatial Data