I have a layer with a repeating field name, thus different groups of features (I also have a numerical group field). How can I add a field group_id, using QGIS expressions? What I want is kind of a uniqe identifier per group, counting from 1 to the last element contained in the group (see screenshot).
What I tried: Using array_length (array_agg( "group", "group")), I get the number of features per group (field no_in_group). With generate_series (1, [features per group]), I get an array, counting from 1 to the last no. of each group.
However, I'm stuck how to assign each element of the array to one feature of the group. I suppose that array_foreach () will do the job, but I'm unsure how to use it in this case.
Screenshot: the field with red outline is what I want to get: a unique, incrementing id, starting from 1 for each group. Here, I introduced the values manually to make clear what I'm looking for:


