Select to view content in your preferred language

Arcade: Calc Field - Average Values with Same Timestamp

356
1
Jump to solution
09-12-2023 06:14 AM
ArmstKP
Frequent Contributor

I am trying to mimic the Average field calculation in the below table, in Arcade.  Anybody lend a hand?

ArmstKP_0-1694524437509.png

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

For a field calculation, we're evaluating the expression per row of the table, and we only have to worry about matching values. By filtering the full layer based on the date field, you can easily get that subset, then use the Average function to get the numeric average of any field.

var fs = $layer

var matching_ts = Filter(fs, `date_field = ${$feature['date_field']}`)

return average(matching_ts, 'numeric_field')

Whether or not this works will depend on where the data is at, too. For some database providers, the timestamp needs to be wrapped in "timestamp '...'". Also, the variable $layer may not work there, so you may need to use a FeatureSet function to bring the rest of the layer's values in.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
1 Reply
jcarlson
MVP Esteemed Contributor

For a field calculation, we're evaluating the expression per row of the table, and we only have to worry about matching values. By filtering the full layer based on the date field, you can easily get that subset, then use the Average function to get the numeric average of any field.

var fs = $layer

var matching_ts = Filter(fs, `date_field = ${$feature['date_field']}`)

return average(matching_ts, 'numeric_field')

Whether or not this works will depend on where the data is at, too. For some database providers, the timestamp needs to be wrapped in "timestamp '...'". Also, the variable $layer may not work there, so you may need to use a FeatureSet function to bring the rest of the layer's values in.

- Josh Carlson
Kendall County GIS
0 Kudos