Today Filter with Arcade

751
3
Jump to solution
10-04-2022 10:35 AM
Labels (1)
TamT
by
New Contributor III

I use a form for my features that I collect with the Field Maps App. In this form I have the NUMBER field, which I would like to have automatically filled. I also have a DATE/TIME field.

The number I want to have integrated automatically is the highest existing number from today. No problem to filter the highest number, but the today (not 24 hours) and the two conditions together cause some problems to me. Can somebody help? Thanks!

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Can you share what you've already tried? Maybe someone can spot where your current expression is not working.

You could also try using EXTRACT in the Filter's SQL expression. Using a backtick string with template literals lets you pipe values into the expression without any concatenation or creating extra variables, and also lets you include line breaks in your expression, which is nice for keeping longer expressions easy to read.

var today_records = Filter(
    $layer,
    `EXTRACT(DAY FROM datetime_field) = ${Day(Today())}
AND EXTRACT(MONTH FROM datetime_field = ${Month(Today())}
AND EXTRACT(YEAR FROM datetime_field) = ${Year(Today())}`
)

var max_number = Max(
    today_records,
    'number_field'
)

return max_number
  

 

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

Can you share what you've already tried? Maybe someone can spot where your current expression is not working.

You could also try using EXTRACT in the Filter's SQL expression. Using a backtick string with template literals lets you pipe values into the expression without any concatenation or creating extra variables, and also lets you include line breaks in your expression, which is nice for keeping longer expressions easy to read.

var today_records = Filter(
    $layer,
    `EXTRACT(DAY FROM datetime_field) = ${Day(Today())}
AND EXTRACT(MONTH FROM datetime_field = ${Month(Today())}
AND EXTRACT(YEAR FROM datetime_field) = ${Year(Today())}`
)

var max_number = Max(
    today_records,
    'number_field'
)

return max_number
  

 

- Josh Carlson
Kendall County GIS
0 Kudos
TamT
by
New Contributor III

I have problems with this code working offline. Can you work with it offline? Would be interested a lot in your answer. Thanks!

0 Kudos
TamT
by
New Contributor III

Thanks for your fast answer.  I saw an earlier post of you with your EXTRACT suggestion and tried this (https://community.esri.com/t5/arcgis-online-questions/using-a-date-in-an-arcade-filter-function/m-p/...

But didnt't work. For my post you sent me now a slightly different code - very elegant - works perfectly now! Thanks

0 Kudos