I am looking for help with a script to display only todays data unless todays data has not been displayed yet. If that is the case display yesterday data.
I am thinking it would be if today > 0 display today data if not display today-1
Are you doing this in a data expression? Or working with an existing layer? The former is possible, but the latter probably isn't.
I am trying to do this in a data expression.
Ah, well that's not too bad. It's very similar to the example shown here.
// Get layer
var portal = Portal('org-url')
var fs = FeatureSetByPortalItem(
portal,
'itemID',
0, // or whatever the layer index
[
'your',
'fields',
'some_date_field'
],
false
);
// Get most recent date, convert to SQL-compatible string
var maxDate = Text(Date(fs, 'some_date_field'), 'YYYY-MM-DD');
// Return records for max date
return Filter(fs, "some_date_field = @maxDate")
Thanks for the link.
One issue I have is that I have pre added dates for the year so I cannot pick the max date but maybe I can get it to work with todays date.
// Get layer
var portal = Portal('org-url')
var fs = FeatureSetByPortalItem(
portal,
'itemID',
0, // or whatever the layer index
[
'your',
'fields',
'some_date_field',
'some_value_field'
],
false
);
// Filter records with empty values (future dates)
var filt = Filter(fs, "some_value_field IS NOT NULL AND some_value_field <> ''")
// Sort filtered records for most recent first
var sorted = OrderBy(filt, "some_date_field DESC")
// Return top record
return First(sorted)
@RickeyFightyou're right, that was it. Though the AND was probably part of it, too. I've edited this code so that the OrderBy references filt instead of fs.
var portal = Portal("PortalID");
var fs = FeatureSetByPortalItem(
portal,
"Numbers",
1,
[
"Date_",
"W_F_MGD",
"E_F_MGD",
"TOTAL_W_E_MGD",
"TID_FLOW_MGD",
"REEDER_Percent_FULL",
"TAP_FLOW_MGD",
"PLANT_PRODUCTION_MGD",
"last_edited_date"
],
false
);
// Filter records with empty values (future dates)
var filt = Filter(fs, "REEDER_Percent_FULL IS NOT NULL OR REEDER_Percent_FULL <> ''")
// Sort filtered records for most recent first
var sorted = OrderBy(filt, "Date_ DESC")
// Return top record
return First(sorted)
Here is my full code minus the portal login info
Hmmm. Try throwing in some Console commands to output some intermediate things, try to see where it's failing.
After ln 18: Console(fs)
After ln 23: Console(filt)
After ln 26: Console(sorted)
@jcarlson
I think you were almost right.
This is what I got to work
// Filter records with empty values (future dates)
var filt = Filter(fs, "REEDER_Percent_FULL IS NOT NULL")
// Sort filtered records for most recent first
var sorted = OrderBy(filt, "Date_ DESC")
// Return top record
return First(sorted)
If you modify your post I will mark yours as correct