Select to view content in your preferred language

Arcade Expression to Calculate Field based on a Sort Date field

1795
12
05-24-2023 11:51 AM
Labels (1)
BrianHumphries1
New Contributor III

hello,

 

I am trying to use the SequentialNumber() for Calculate Field but I would like to calculate the Field based on the a field called  SampleDate in ascending order.

 

I have tried using the helpers and modify the code block but failed.

i tried a arcade expression(below) but got null values as retuned values

 

// Arcade  for SequentialNumber
var rec = 0;

function SequentialNumber() {
    var pStart = 1;
    var pInterval = 1;
    var SampleDate = $feature.SampleDate;  // Name of the field used for sorting
    
    // Access the global feature set
    var Opp_table = FeatureSetByName($datastore, 'SDEP.SDEADMIN.WaterSampleInspectionsOperator');

    // Sort the features based on "SampleDate" field
    var sortedFeatures = Sort(Opp_table, SampleDate, 'ASC');
    
    if (rec == 0) {
        rec = pStart;
    } else {
        rec = rec + pInterval;
    }
    
    // Assign the sequential number based on the sorted order
    return rec;
}

 

Any help would be much appreciated 

0 Kudos
12 Replies
JohannesLindner
MVP Frequent Contributor

Export your table to a gdb and run either the Field Calculator or the script on that exported table. If the errors persist, I'm absolutely out of ideas.


Have a great day!
Johannes
0 Kudos
BrianHumphries1
New Contributor III

Good morning Johannes,

I am able to run the Arcade expression on the table Inside of the FGDB

BrianHumphries1_1-1685109257706.png

My data does have identical values for the for the sample date 

see below

BrianHumphries1_0-1685109197564.png

 

Results after running the Calculation and sorting by Sample Date

BrianHumphries1_3-1685109910829.png

 

It seems that the codeworks after the first identical values change, Then its picks up the next record count after the first set of identical records are ran through.

So in this example I had 4 records that matched the same sample date in ascending order ,

then it picked up the count of 5 after the first set of identical passed.

 

Getting closer to making this work.

 

Thank you Johannes for all of your help so far I would be lost with out it?

 

I also ran the Python to see what results I would get and received this

BrianHumphries1_0-1685116312463.png

Again thank you for your support Sir.

Brian.

 

 

 

 

 

0 Kudos
RobynSnookCCB
New Contributor III

Is there a way to do this and have the numbering restart when a new date starts?

0 Kudos