Summarize Features in a pop-up with Arcade

1959
5
01-29-2019 03:49 PM
FrancisHourigan1
Occasional Contributor

Let's say I have location points. Each Location has a unique name. In my point feature attribute table, I have multiple rows for each location name that corresponds to a year and total tons delivered. How can I use Arcade in both the Symbology and the Pop-up to display a summary of the total tons delivered across all years for a specific location? And, In the Pop-up, list the years and the tons delivered for each location?

Thanks!

Tags (1)
0 Kudos
5 Replies
XanderBakker
Esri Esteemed Contributor

So if I understand it correctly, the point is duplicated for each delivery. If the location has an ID you could filter the layer with that ID and create the list of years and total amount of tons delivered. What you will see is that one click will result in a list of points in that same location each with the same statistics (although the current delivery will vary).

What could be more common is to have a featureclass with only 1 point per location and a related table with the individual deliveries .

In this post you can see an example of how you could create the desired result, using Filter and FeatureSetByName functions: https://community.esri.com/docs/DOC-12773-using-featuresetby-functions-in-arcade-to-drill-down-to-ot... 

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Francis Hourigan ,

Based on what you send me by email, I would suggest something like this:

var tbl = FeatureSetByName($datastore,"WineryTonsRecbyYearandColor");
var ID = $feature["WineryName"];
var sql = "WineryName ='"+ ID +"'";
console(sql);
var Deliveries = Filter(tbl, sql);
var cnt = Count(Deliveries);
var historic = "";
if (cnt > 0) {
    historic = cnt + " Deliveries:";
    for (var Delivered in Deliveries) {
        var txt_date = Text(Delivered.Harvest_Year,'-(YYYY)');
        var tons = txt_date + " " + Delivered.DeliveredTonsQty;
        historic += TextFormatting.NewLine + tons;
    }
} else {
    historic = "No Grapes Delivered";
}

return historic;

Since I don't have access to the data I have no way to test if this actually works with your data.

0 Kudos
XanderBakker
Esri Esteemed Contributor

As response to your email. In order to include a summary of the amount of red and white grapes you could expand the code to this. It will include an indication for each delivery to state if it were red or white grapes and the total tons of red and white grapes will be included at the bottom:

var tbl = FeatureSetByName($datastore,"WineryTonsRecbyYearandColor");
var ID = $feature.Name;
var sql = "WineryName ='"+ ID +"'";
Console(sql);
var Deliveries = Filter(tbl, sql);
var cnt = Count(Deliveries);
var historic = "";
var red = 0;
var white = 0;
var other = 0;
if (cnt > 0) {
    historic = cnt + " Deliveries:";
    for (var delivered in Deliveries) {
        if (delivered.BIMS_Color=="R") {
            red += delivered.DeliveredTonsQty;
        } else if (delivered.BIMS_Color == "W") {
            white += delivered.DeliveredTonsQty;
        } else {
            other += delivered.DeliveredTonsQty;
        }
        var txt_date = Text(delivered.Harvest_Year,'-(YYYY)');
        var tons = txt_date + " " + delivered.DeliveredTonsQty;
        historic += TextFormatting.NewLine + tons + " (" + delivered.BIMS_Color + ")";
    }
    historic += TextFormatting.NewLine;
    if (red > 0) {
        historic += TextFormatting.NewLine + " - Red: " + Round(red,2) + " tons";
    }
    if (white > 0) {
        historic += TextFormatting.NewLine + " - White: " + Round(white, 2) + " tons";
    }
    if (other > 0) {
        historic += TextFormatting.NewLine + " - other: " + Round(other, 2) + " tons";
    }
} else {
    historic = "No Grapes Delivered";
}

return historic;
FrancisHourigan1
Occasional Contributor

Thanks again Xander! My pop-ups for this map are now perfect for what I was looking to represent in the map.

XanderBakker
Esri Esteemed Contributor

Glad to hear that!

0 Kudos