I had a similar issue and come up with a solution, though it is not perfect because having multiple editors collecting data in the same land segment while offline would throw off the count. For my survey, I am auto-incrementing the number of trees collected within different project location boundaries.
Solution:
**For me: Field_1 = Project_Location and Field_2 = Tree_Number
1 var numberlist = FeatureSetByName($map, "Map_Layer", ['Field_1','Field_2'])
2 var location = TextFormatting.SingleQuote + $feature.Field_1 + TextFormatting.SingleQuote
3 var location_sentence = Concatenate(["Field_1 LIKE", location], " " )
4 var current_tree_number = Max(Filter(numberlist, location_sentence), 'Field_2') + 1
5 return current_tree_number
To explain what I'm doing here:
Line 1: I'm creating a FeatureSet from the layer in my map that contains the fields I need for auto-incrementing. The first field I called was 'Project_Location' and the second field I called was 'Tree_Number'
Line 2: Later I will be setting up the Filter() expression to filter Project_Location in the FeatureSet to match the current Project_Location. I knew that I would be using a SQL92 expression in the Filter() function and for that I needed the current Project_Location to be formatted as text with the attribute I am filtering for in single quotations. I decided to make this a variable so that my later lines of code could be cleaner.
Line 3: The SQL92 expression that I am using in the Filter() function filters the Field with a sentence set up as "Field_1 LIKE 'Attribute'". So I am creating a variable that will read "Project_Location LIKE 'location'". This sentence filters the project location to only return the points in the current location. I made this a variable to keep the future code cleaner.
Line 4: I am creating my current_tree_number. In this line I am calling Filter() on the FeatureSet I created and filtering it by the current Project_Location. I am then looking for the Max() Tree_Number within that filtered list and then I increase the max by 1 to get my current Tree_Number for the Project_Location.
Line 5: I return the current_tree_number