Creating an expression for an indicator that only shows the most recent month's data

510
2
Jump to solution
09-02-2022 12:49 PM
WorcesterGTSS
New Contributor III

I'm trying to create an indicator in my dashboard that includes only the records in my dataset from the month associated with the most recent records. (I don't want to use the built in Last Month option in the Data options section of the indicator because there will be a lag at the beginning of each month when the dashboard is updated.)

I'm trying to write an Arcade expression for this but am a newcomer and am struggling a bit with this.

Right now my expressions runs but it only returns the records associated with the latest date, not all of the records in the latest month which is what I want. See expression below - if I change YYYY-MM-DD in the 4th line to MMM, then no records are returned.

I feel like there's probably a very simple solution to this but I can't seem to figure it out.

Any suggestions are appreciated.

Thank you,

Samara

var fields = ["objectid", "date", "category", "closed"]
var fs = FeatureSetByPortalItem(Portal("PORTAL NAME"), "LAYER ID", 0, fields)
var open_issues = Filter(fs, "closed = 'No'")

var maxDate = Text(Date(Max(open_issues, 'date')), 'YYYY-MM-DD')

var subsetByDate = Filter(open_issues, "date = @maxDate")
return subsetByDate

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

Do you want to return records from the last month as of today's date? You can use the DateAdd function to calculate that date, then use that date to filter the records.

var fields = ["objectid", "date", "category", "closed"]
var fs = FeatureSetByPortalItem(Portal("PORTAL NAME"), "LAYER ID", 0, fields)
var open_issues = Filter(fs, "closed = 'No'")

var lastMonth = Text(DateAdd(Today(), -1, 'months'), 'MM/DD/YYYY');
var subsetByDate = Filter(open_issues, "date > @lastMonth")
return subsetByDate

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

Do you want to return records from the last month as of today's date? You can use the DateAdd function to calculate that date, then use that date to filter the records.

var fields = ["objectid", "date", "category", "closed"]
var fs = FeatureSetByPortalItem(Portal("PORTAL NAME"), "LAYER ID", 0, fields)
var open_issues = Filter(fs, "closed = 'No'")

var lastMonth = Text(DateAdd(Today(), -1, 'months'), 'MM/DD/YYYY');
var subsetByDate = Filter(open_issues, "date > @lastMonth")
return subsetByDate

 

WorcesterGTSS
New Contributor III

Yes, this allows me to do what I'm aiming for - thank you so much!

Samara

0 Kudos