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.
Solved! Go to Solution.
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.
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");
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.
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");