Not sure I understood well (if you want to count occurrence from column field3
or if it's the column you want to fill with a count from another column).
I have considered you want to update the field3
using count from field1
. In this case, you need to try the following expression to update field3 with count of occurrences from field1
using QGIS field calculator.
aggregate(
layer:=@layer,
aggregate:='count',
expression:="field1"
,filter:="field1" = attribute(
@parent, 'field1'))
Translated as a sentence, above code says:
For each feature, loop on all other features to filter if any match the field1 value from current line. Keep only these features. Then, count how many there are for the particular feature.
Edit:
What you want to do is the same as counting on multiple columns from your comment. The following do exactly what you want (tested)
aggregate(
layer:=@layer,
aggregate:='count',
expression:="field1" || "field2"
,filter:="field1" || "field2" = attribute(
@parent, 'field1') || attribute(
@parent, 'field2'))
PS: for an unknown reason, I got crash after crash while using the recipe with virtual field but not when calculating to fill an existing or new column.