Counting and sequentially enumerating in qgis

Hello, currently I have a project that sequentially numbers the markings of points I make. The numbering depends on the SER, which means that the expression counts the existing points of the SER that I enter in the form and adds them up, as shown in the attached expression. This expression works perfectly, but the problem arises when I need to modify a point. When I modify it, it counts all the existing points and adds 1 to the count. I tried disabling the default value checkbox, but when I do that, the formula stops working. It only works when the default value checkbox is activated.:

This is the expression I am using:

with_variable(‘count_infra’, aggregate(layer:=‘AGREGARINFRAESTRUCTURA’, aggregate:=‘count_distinct’,expression:=“CONSECUTIV”,filter:=“SER”=attribute(parent, ‘SER’)),count_infra)+1


Imported from GitHub discussion by @CACG1022 on 2023-06-10T15:42:50Z

Hi CACG1022 ,

In a very similar situation, I helped myself by querying in advance whether the sequential number has already been determined once.

If yes, the existing value should be kept. And only if not, the number should be determined.

So in your case, something like the following should help?

if(“[paste_your_variable_here]” IS NULL,

with_variable(‘count_infra’, aggregate(layer:=‘AGREGARINFRAESTRUCTURA’, aggregate:=‘count_distinct’,expression:=“CONSECUTIV”,filter:=“SER”=attribute(parent, ‘SER’)),count_infra)+1 ,

“[paste_your_variable_here]”)

At least for me it works very well this way, for you too?


Imported from GitHub comment by @lp-dj on 2023-06-13T12:32:29Z