Select to view content in your preferred language

Sequentially/incrementally numbering a data point based on another value in that point

1316
2
Jump to solution
11-16-2022 05:47 PM
Labels (2)
CHSnowman
Occasional Contributor
Background:
I have an attribute rule that concatenates a Group Number ('Group_Number') with the date of activity ('CREATEDATE') to make ('Group_Date').
 
What I need:
I'd like to make an Attribute Rule that will take point submissions on any given Group_Date and increment the Sequential ID ('SEQID') and assign it to the new point, and restart for each day. Visually:
 
Group_Date A, Point 1
Group_Date A, Point 2
Group_Date A, Point 3
 
Group_Date B, Point 1
Group_Date B, Point 2
 
Group_Date C, Point 1
Group_Date C, Point 2
Group_Date C, Point 3
Group_Date C, Point 4
 
Group_Date D, Point 1
...and so on.
 
I know it can be done through geoprocessing tools and/or python scripts but I'm hoping to figure out an Attribute Rule to automate it so it doesn't have to be maintained. Ideally I'd also like for it to work while offline in Survey123 or Field Maps. Thanks in advance.
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Alum

You can calculate Group_Date and SEQID in the same rule:

// Calculation Attribute Rule
// triggers: Insert
// Field: empty

// Calculate Group_Date
var group_date = $feature.Group_Number + "_" + Text($feature.CREATEDATE, "Y-MM-DD")

// Find all existing features with the same Group_Date
var features_with_same_group_date = Filter($featureset, "Group_Date = @group_date")

// Calculate SEQID
var next_id = Count(features_with_same_group_date) + 1
var seq_id = group_date + "_" + next_id

// Return Group_Date and SEQID
return {
    "result": {"attributes": {
        "Group_Date": group_date, "SEQID": seq_id
    }}
}

 

 

No idea if this will work offline...


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Alum

You can calculate Group_Date and SEQID in the same rule:

// Calculation Attribute Rule
// triggers: Insert
// Field: empty

// Calculate Group_Date
var group_date = $feature.Group_Number + "_" + Text($feature.CREATEDATE, "Y-MM-DD")

// Find all existing features with the same Group_Date
var features_with_same_group_date = Filter($featureset, "Group_Date = @group_date")

// Calculate SEQID
var next_id = Count(features_with_same_group_date) + 1
var seq_id = group_date + "_" + next_id

// Return Group_Date and SEQID
return {
    "result": {"attributes": {
        "Group_Date": group_date, "SEQID": seq_id
    }}
}

 

 

No idea if this will work offline...


Have a great day!
Johannes
CHSnowman
Occasional Contributor

It worked great! I was trying to make NextSequenceValue work and didn't even consider just using a Count function. Brilliant. 

0 Kudos