Hi Kathy Smikrud ,
To get the sum of the values in the repeat you can use the following expression:
var surveys = FeatureSetByRelationshipName($feature, "EscapementSurveys");
var cnt1 = Count(surveys);
var cnt2 = 0;
var mouth = 0;
var tidal = 0;
var live = 0;
var dead = 0;
if (cnt1 > 0) {
var surveyssorted = OrderBy(surveys, 'OBS_Date DES');
var survey = First(surveyssorted);
var repeats = FeatureSetByRelationshipName(survey, "repeat_SpeciesCounts");
cnt2 = Count(repeats);
if (cnt2 > 0) {
for (var repeat in repeats) {
mouth += repeat.MOUTH;
tidal += repeat.TIDAL;
live += repeat.LIVE;
dead += repeat.DEAD;
}
}
}
var result = "";
if (cnt2 > 0) {
result = "Mouth: " + mouth;
result += TextFormatting.NewLine + "Tidal: " + tidal;
result += TextFormatting.NewLine + "Live: " + live;
result += TextFormatting.NewLine + "Dead: " + dead;
} else {
result = "No counts available";
}
return result;
See below the result in the pop-up:
In case you want to show the counts per specie code, you can use the expression below:
var surveys = FeatureSetByRelationshipName($feature, "EscapementSurveys");
var cnt1 = Count(surveys);
var cnt2 = 0;
var result = "";
if (cnt1 > 0) {
var surveyssorted = OrderBy(surveys, 'OBS_Date DES');
var survey = First(surveyssorted);
var repeats = FeatureSetByRelationshipName(survey, "repeat_SpeciesCounts");
cnt2 = Count(repeats);
if (cnt2 > 0) {
var stats = GroupBy(repeats, ['SPECIES_CODE'], [
{name: 'sumMOUTH', expression: 'MOUTH', statistic: 'SUM'},
{name: 'sumTIDAL', expression: 'TIDAL', statistic: 'SUM'},
{name: 'sumLIVE', expression: 'LIVE', statistic: 'SUM'},
{name: 'sumDEAD', expression: 'DEAD', statistic: 'SUM'}]);
for (var stat in stats) {
result += TextFormatting.NewLine + TextFormatting.NewLine + "Specie code: " + stat["SPECIES_CODE"];
result += TextFormatting.NewLine + " - " + "Mouth: " + stat.sumMOUTH;
result += TextFormatting.NewLine + " - " + "Tidal: " + stat.sumTIDAL;
result += TextFormatting.NewLine + " - " + "Live: " + stat.sumLIVE;
result += TextFormatting.NewLine + " - " + "Dead: " + stat.sumDEAD;
}
} else {
result = "No counts available";
}
} else {
result = "No counts available";
}
return result;
The result will display as this:
In your email you mentioned that you want to access the previous survey counts, so not the latest record. In that case you would still have to sort the surveys on date but now loop through the surveys and take the second. This is a bit longer than using the First function, but it can be done.