I have two layers. One is a shapefile of U.S. states where each state is labeled with the attribute STATE_NAME
, and the other is a CSV data layer named rid
with many points that are labeled with a State
attribute. In this CSV data layer, there are many points for each state.
I want to create a column in the shapefile that contains the count of points per state.
Using the field calculator in the shapefile, I've attempted
aggregate(layer:= 'rid',
aggregate:= 'count',
expression:='State',
filter:=attribute($currentfeature, 'STATE_NAME'))
but this results in 0
for each state. If I attempt without the filter, I get the total number of points regardless of state, resulting in the same number for each state.
Is there a filter that will allow me to count the number of points per state?