I'm trying to write an SQL CASE expression for use within a FeatureSet/GroupBy function. I have a Date field that I'm grabbing using FeatureSetByPortalItem and I want to create a field that just puts the ages in classes.
Ideally, the dates would be dynamic as well, based on today's date and a defined age.
I'm pretty sure the indentation below is improper, but you get the idea of what I'm trying to achieve.
{
name: 'feature_age',
expression: 'CASE
WHEN date_stat => 2020 THEN 1
ELSE date_stat => 2012 THEN 2
ELSE date_stat => 1984 THEN 3
ELSE date_stat => 1850 THEN 4
ELSE NULL
END',
statistic: 'SUM'
},
Related to a previous post that I found the solution to: https://community.esri.com/t5/arcgis-dashboards-questions/data-too-big-for-a-featureset-calculation-...
Solved! Go to Solution.
For those playing at home, the answer is:
{
name: 'feature_age',
expression: 'CASE WHEN @today-date_stat < 1460 THEN 1 WHEN @today-date_stat < 4380 THEN 2 WHEN @today-date_stat < 14600 THEN 3 WHEN @today-date_stat > 14600 THEN 4 ELSE NULL END',
statistic: 'SUM',
},
Note: Number of days is used to calculate the age. Ie. 1460 = 4x365
Note2: @today is a var, outside the GroupBy function, defined as Now()
For those playing at home, the answer is:
{
name: 'feature_age',
expression: 'CASE WHEN @today-date_stat < 1460 THEN 1 WHEN @today-date_stat < 4380 THEN 2 WHEN @today-date_stat < 14600 THEN 3 WHEN @today-date_stat > 14600 THEN 4 ELSE NULL END',
statistic: 'SUM',
},
Note: Number of days is used to calculate the age. Ie. 1460 = 4x365
Note2: @today is a var, outside the GroupBy function, defined as Now()
haha
Thanks!