Attribute analysis and statistics
Distinct counts, median and standard deviation by group
Go beyond totals: count distinct values, find the median, and measure the spread of values with the standard deviation for each group, and see how missing values are counted.
You will learn
- Count distinct values per group.
- Use the median when values are skewed.
- Choose between sample and population standard deviation.
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
| Field | Type | Description |
|---|---|---|
village_id | text | Identifier V001 to V025. |
village | text | Village name. Common names repeat (Rampur, Shivpur, Madhopur), as they do in real gazetteers. |
district | text | District: Rampur, Varanasi, Jaunpur, Patna or Gaya. |
state | text | State: Uttar Pradesh or Bihar. |
population | integer | Residents. One village (Amarpur) has no recorded population (NULL). |
households | integer | Households. |
has_school | text | yes or no. |
Licence: CC0 1.0. All tutorial data is synthetic and generated by Orbis. About the datasets
The task
Per state you want to know how many different village names occur, the typical (median) village population, how much populations vary, and how many villages lack a population value.
Steps
- Load
villages.zip, open the attribute table and click Group and summarize. Tick state.
Set up these aggregates (change the function of the default one, and add the others with Count and Median next to Add, then change their function and field):
Function Field Output name Count records villages Count distinct values village names Median population median_population Standard deviation (sample) population sd_population Count NULL values population no_population
Click Run.

Distinct counts, medians and standard deviations by state.
Expected result
| state | villages | names | median_population | sd_population | no_population |
|---|---|---|---|---|---|
| Bihar | 10 | 9 | 4225 | 2039.95 | 0 |
| Uttar Pradesh | 15 | 11 | 2900 | 2063.03 | 1 |
Standard deviations are shown to two decimals. Bihar has 10 villages but only 9 names because "Rampur" occurs in two of its districts. Uttar Pradesh has one village without a population, so its median and standard deviation use 14 values.
Common mistakes
- Expecting COUNT DISTINCT to count empty values. Distinct counts ignore NULL. Use Count NULL values to count missing values.
- Using the mean for skewed data. A few large villages raise the mean; the median is the value in the middle and is not affected by extremes.
Troubleshooting
- The standard deviation is empty. The group has fewer than two values (sample statistic). Use the population version or check the group size with Count values (non-NULL).
- Distinct counts look too high. Values that differ only in case or spaces are distinct. Clean them first.