Elements to read/display data from the 4 most recent years

344
2
Jump to solution
11-28-2023 11:08 AM
Jabousaw
New Contributor II

I am working on a dashboard with 3 indicators, 1 pie chart and 1 bar graph. I need each of these elements to only read data from the 4 most recent years so that the data they are displaying is constantly updated as more data is compiled. Is there a way to create a data expression or even filter data so it does this automatically or will I have to manually update the elements each time to only display data from a certain time period? A data expression for each indicator to automate this would be ideal. 

0 Kudos
2 Solutions

Accepted Solutions
jcarlson
MVP Esteemed Contributor

I don't know that you need a Data Expression at all. Any given widget lets you apply filters like "some date field is within the last 4 years". Does that not work?

You could still do it with a Data Expression and hard-code a Filter using the Now function to always have it relative to the current date, thus avoiding having to edit the expression in the future. But check out the built-in filter options first.

- Josh Carlson
Kendall County GIS

View solution in original post

KenBuja
MVP Esteemed Contributor

You can filter your records to return only the ones from the last four years like this

var fs = FeatureSetByPortalItem(
    Portal('your portal'), 
    'your item id', 
    0
);
var filterDate = Text(DateAdd(Today(), -4, 'years'), 'YYYY-MM-DD');
var filteredData = Filter(fs, "datefield > @filterDate");

 

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

I don't know that you need a Data Expression at all. Any given widget lets you apply filters like "some date field is within the last 4 years". Does that not work?

You could still do it with a Data Expression and hard-code a Filter using the Now function to always have it relative to the current date, thus avoiding having to edit the expression in the future. But check out the built-in filter options first.

- Josh Carlson
Kendall County GIS
KenBuja
MVP Esteemed Contributor

You can filter your records to return only the ones from the last four years like this

var fs = FeatureSetByPortalItem(
    Portal('your portal'), 
    'your item id', 
    0
);
var filterDate = Text(DateAdd(Today(), -4, 'years'), 'YYYY-MM-DD');
var filteredData = Filter(fs, "datefield > @filterDate");