Attribute analysis and statistics

Filtering records before counting and summarising

Count or summarise only the records that meet a condition, for example villages with more than 5,000 people, by adding a filter to the Aggregate tool.

Intermediate2 min read

You will learn

  • Add a filter to a summary with the condition builder.
  • Understand why groups without matching records disappear.
  • Combine conditions with AND and OR.

Prerequisites

Data for this tutorial

Sample villages (synthetic) Download villages.zip

Format
ESRI Shapefile (ZIP: .shp, .shx, .dbf, .prj, .cpg)
Geometry
Point
CRS
EPSG:4326 (WGS 84 longitude, latitude)
Content
25 villages in 5 districts of 2 states
Fields used in the tutorials
FieldTypeDescription
village_idtextIdentifier V001 to V025.
villagetextVillage name. Common names repeat (Rampur, Shivpur, Madhopur), as they do in real gazetteers.
districttextDistrict: Rampur, Varanasi, Jaunpur, Patna or Gaya.
statetextState: Uttar Pradesh or Bihar.
populationintegerResidents. One village (Amarpur) has no recorded population (NULL).
householdsintegerHouseholds.
has_schooltextyes or no.

Licence: CC0 1.0. All tutorial data is synthetic and generated by Orbis. About the datasets

The task

You want the number of large villages, those with more than 5,000 residents, in each district.

Steps

  1. Load villages.zip, open the attribute table and click Group and summarize. Tick district and keep Count records.
  1. Find Only records where. Below its text box is a condition row: choose population as the field, greater than as the operator, type 5000 and click Add condition. The box now contains:

    "population" > 5000
    The filter of the Aggregate tool built with the condition row: population greater than 5000
    A filter added with the condition builder.
  1. Click Run. The notification says how many records passed the filter: 7 of 25.

Expected result

districtcount
Jaunpur1
Patna3
Rampur2
Varanasi1

Gaya is missing: none of its villages has more than 5,000 residents, so it has no records left after the filter and therefore no group. Amarpur (no population) is also left out, because NULL > 5000 is not true.

Common mistakes

  • Expecting zeros for missing groups. A filter removes records before grouping; a group with no remaining records does not appear. Compare with the unfiltered count to see which groups dropped out.
  • Text values without quotes. Text in conditions is written in single quotes: "has_school" = 'yes'. The condition builder adds them for you.

Troubleshooting

  • "The filter uses field(s) that do not exist". The field name is misspelled. Use the condition row or click a field name under the expression box to insert it.
  • Nothing passes the filter. Check the operator and the value against the field statistics of the field.