Select to view content in your preferred language

Arcade: Count days of data collection with Survey123 field app

2062
13
08-09-2022 02:43 PM
FedericoRiet_Sapriza
Occasional Contributor

Hi, 

I would like help with Arcade, I'm making a Dashboard and I need to count the days that data was collected with Survey123 and show this in a Indicator. 

Example: in a month I may have 27 surveys, that were collected in 16 days. how can I count this with Arcade?

So for instance in a period of 4 months in which the survey was performed I would like to know how many work days and now many days data was not collected

make sense?

Thanks

Cheers,

Federico 

 

 

 

@GeeFernando 

@JohannesLindner 

0 Kudos
13 Replies
MosquitoGIS
Frequent Contributor

Thanks, I will be scouring over this code learning.  You seriously have been extremely helpful.

One more question for you if you are willing, how is it the you work with or handle nulls?

0 Kudos
JohannesLindner
MVP Frequent Contributor

In this example, I excluded records with nulls in the user or date field from the input data, see line 6: 

layer = Filter(layer, `${name} IS NOT NULL AND ${datetime} IS NOT NULL`)

 

As this problem is all about working with dates, we have to exclude null values in the date field. But it could be interesting to know about null values in the user field. For that, we have to change the filter inside the function according to whether the user argument is null or not:

function specific(fs, user) {
    var sql = `${datetime} IS NOT NULL AND ${name} = @user`
    if(user == null) {
        sql = `${datetime} IS NOT NULL AND ${name} IS NULL`
    }
    var fs = Filter(fs, sql)
    var extract_date_string = `CONCAT(EXTRACT(YEAR FROM ${datetime}), '-', EXTRACT(MONTH FROM ${datetime}), '-', EXTRACT(DAY FROM ${datetime}))`
    var grouped_by_date = GroupBy(fs, 
        [{name: "DateString", expression: extract_date_string}],
        [{name: "Count", expression: "1", statistic: "COUNT"}])
    var edits = Sum(grouped_by_date, "Count")
    var days = Count(grouped_by_date)
    //return edits / days
    return {edits: edits, days: days, mean: edits/days}
}

 

If you use the editor tracking fields for this, you won't get any meaningful results, because when the user field is empty, the date field will obviously be empty, too.

 


Have a great day!
Johannes
MosquitoGIS
Frequent Contributor

Awesome, thank you so much!

0 Kudos
FedericoRiet_Sapriza
Occasional Contributor

Awesome, I'll try this and let you know

YOU ROCK!!!

0 Kudos