GroupBy and left characters of a field in Dashbord data expression

408
5
Jump to solution
01-24-2024 12:55 PM
mfafard
New Contributor II

Hi

The following code work. But hard to believe that I can't groupby the 4 left characters of field "nojob"...

I tried lot of scenario, without success

 

var portail = Portal('https://xxxxx.ca/portal');
var fs = FeatureSetByPortalItem(
portail,
//itemid layer jobsignalisation
'250b512105df48169e8d01xxxxxxxxxx',
//layer id
0,
[
'nojob'
],
false);

var group_exp = [
{ name: 'jobsparannee', expression: 'nojob', statistic: 'COUNT'}]

return GroupBy(fs,['nojob'], group_exp)

return fs

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Yes, I used test data here...

Your expression would look like this:

var portail = Portal('https://xxxxx.ca/portal');
var fs = FeatureSetByPortalItem(
    portail,
    //itemid layer jobsignalisation
    '250b512105df48169e8d01xxxxxxxxxx',
    //layer id
    0,
    [
        'nojob'
    ],
    false);

return GroupBy(fs, 
  [{name: "test", expression: "SUBSTRING(nojob, 1, 4)"}], 
  [{name: "test_count", statistic: "COUNT", expression: "1"}]
)

Have a great day!
Johannes

View solution in original post

0 Kudos
5 Replies
JohannesLindner
MVP Frequent Contributor
var fs = Featureset({
  fields: [{name:"nojob", type:"esriFieldTypeString"}],
  features:[
    {attributes: {nojob: "abcdefg"}},
    {attributes: {nojob: "abcdabc"}},
    {attributes: {nojob: "abcd"}},
    {attributes: {nojob: "uvwx"}},
    {attributes: {nojob: "uvwxabc"}},
  ]
})

return GroupBy(fs, 
  [{name: "test", expression: "SUBSTRING(nojob, 1, 4)"}], 
  [{name: "test_count", statistic: "COUNT", expression: "1"}]
)

 

JohannesLindner_0-1706134984947.png

 


Have a great day!
Johannes
0 Kudos
mfafard
New Contributor II

Thank you Johannes, but my field "nojob" come from an attributes rule (year(now()) + - + sequentiel). So, I want to count how many job in 2024, etc.

0 Kudos
JohannesLindner
MVP Frequent Contributor

Yes, I used test data here...

Your expression would look like this:

var portail = Portal('https://xxxxx.ca/portal');
var fs = FeatureSetByPortalItem(
    portail,
    //itemid layer jobsignalisation
    '250b512105df48169e8d01xxxxxxxxxx',
    //layer id
    0,
    [
        'nojob'
    ],
    false);

return GroupBy(fs, 
  [{name: "test", expression: "SUBSTRING(nojob, 1, 4)"}], 
  [{name: "test_count", statistic: "COUNT", expression: "1"}]
)

Have a great day!
Johannes
0 Kudos
mfafard
New Contributor II

Yep, thank you! I didn't think about these two steps (substring then count...)

0 Kudos
JohannesLindner
MVP Frequent Contributor

Glad to help 🙂  If your question is answered, please mark the solution so that this thread shows as answered.


Have a great day!
Johannes
0 Kudos