I have singleparts (pipes) with name and depth. I need to count the average depth based on name. So for e.g. pipe 'cont500str1' has average depth (2,93+2,03+1,99+1,17+2,12)/5 = 2,048.

The complication is that some singleparts have the same name. So e.g. the first pipe 'plastic200' has average depth '(2,76+1,58)/2 = 2,17', second pipe 'plastic200' has average depth '(1,16+1,35+2,00+1,07+1,20)/5 = 1,356'.

How can I solve this problem?

enter image description here

  • You need unique IDs for your groups, otherwise this wont work.
    – Erik
    Jun 17 '21 at 10:00
  • If I create unique ID for groups, how to count average based on groups then? I tried "aggregate" function, but it doesnt work.
    – pazelvak
    Jun 17 '21 at 10:06
  • thank you, it works.
    – pazelvak
    Jun 17 '21 at 10:17

As the first step you need to create a field containing a unique ID for each group. Once you got that, look at the "family" of aggregate expressions in the field calculator.

The specialized expression mean() does exactly what you want: I gives you the mean of a column, if desired grouped by another column or expression, and if necessary also filtered.

In your case the expression would be mean("your depth field","your group ID field") - this gives you for each unique group ID the mean.

If you had NULL values in your depth field, you could filter them out adding "your depth field" NOT LIKE NULL as third parameter of the expression.


You can use Groupstats plugin: https://plugins.qgis.org/plugins/GroupStats/

Use the name column as Row, and the value that you want to aggregate with the mean function. The interface is similar to the Excel Pivot table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.