Sum ARCADE with condition

668
3
04-01-2023 03:22 PM
Labels (1)
AurelienJOSSET
New Contributor II

Good morning, I'm looking to make a rather simple ARCADE formula:

the sum of the Shape__Length field with a filter on one field (frequency different from 0 in my case)

Here is where i am now

 

var Sum =Sum($layer, "Shape__Length")

var filter = Filter(Sum, $feature.FREQ_ENTRETIEN !=0)

return filter

 

thanks a lot for your help

Aurelian

3 Replies
JoshuaSharp-Heward
Occasional Contributor III

Hi Aurelian,

I think it'd work if you just flipped the first two lines, filtering the $feature.FREQ_ENTRETIEN !=0 values out before you sum them. Just make sure to then put the filter variable into the sum function instead of $layer.

Cheers,

Josh

0 Kudos
Omar_A
by Esri Contributor
Esri Contributor

Hi Aurelien,

The expression you have created is almost correct but needs a small correction to filter the layer before summing the Shape__Length field. 

var filter = Filter($layer, $feature.FREQ_ENTRETIEN != 0);

var Sum = Sum(filter, "Shape__Length");

return Sum;

Best,

Omar

0 Kudos
AurelienJOSSET
New Contributor II

Hello to both of you

Thanks for your help.

The solution was ultimately

var filter = Filter($layer, 'FREQ_MAINTENANCE <> 0');

var Sum = Sum(filter, 'Shape__Length');

return Sum;

In the Filter function, the condition must be in SQL.

Again thanks to you

Bye

0 Kudos