Select to view content in your preferred language

create an interactive comparison of values between two user-selected years in ArcGIS Dashboard or Experience Builder

225
3
4 weeks ago
ShareUser
Esri Community Manager

Hello everyone,

I’m new to using ArcGIS Online apps and I’m trying to build an interactive visualization for well water level data. I have a point shapefile showing well locations with water levels recorded over multiple years (about a decade).

What I’d like to do is create a Dashboard or Experience Builder app that allows users to:

  • Select two different years (e.g., 2010 and 2020) from dropdown menus or selectors, and

  • Automatically update the map symbology based on the difference in water levels between those two selected years.

I was able to create selectors in Dashboard, but I couldn’t figure out how to link the selections to an Arcade expression that calculates the difference dynamically.
In Experience Builder, I tried using Select and Filter widgets, but they only seem to work with a single field or with predefined comparisons—not interactively between two user-selected years.

Has anyone done something similar, or is there a tutorial or workflow you can recommend for creating this type of two-year comparison using Arcade or another method in Dashboard or Experience Builder?

Thank you in advance for your help!

0 Kudos
3 Replies
Neal_t_k
Frequent Contributor

@Nedamohamadzadeh  are you set on having the difference displayed on a map? If you are open to displaying the difference number with an indicator, you could write a new data expression, bring in water level data twice,  subtract the two water level fields, returning the difference, which then you could display in an indicator, having it render only when the category selectors are activated.  With an indicator it would need to be on an individual site, but you could probably do a table similarly if you want to display multiple.  Not optimal but could get your functionality.

Edit - I don't think this will work, as there is no way to dynamically filter the years. You would have preprocess for every possible year combination.

Edit2 -  It would be possible to do, similar concept as below, in a new data expression but this would only work as a table or an indicator not a map.

// Load the dataset
var data = FeatureSetByPortalItem(
    Portal("https://www.arcgis.com"),
    "<layerID>",
    0, // layer index
    ["SiteID", "Year", "WaterLevel"]
)

// Get unique SiteIDs
var sites = GroupBy(data, ["SiteID"], [])

var results = []

for (var s in sites) {
    var siteID = s.SiteID

    // Get all records for this SiteID
    var siteRecords = Filter(data, "SiteID = @siteID")
    var recordsList = []

    // Convert to list for easier looping
    for (var r in siteRecords) {
        Push(recordsList, r)
    }

    // Compare each pair of years
    for (var i = 0; i < Count(recordsList); i++) {
        var recOld = recordsList[i]
        var yearOld = recOld.Year
        var levelOld = recOld.WaterLevel
        for (var j = 0; j < Count(recordsList); j++) {
            var recNew = recordsList[j]
            var yearNew = recNew.Year
            var levelNew = recNew.WaterLevel

            // Only include if yearNew > yearOld
            if (yearNew > yearOld) {
                var diff = levelNew - levelOld

                Push(results, {
                    attributes: {
                        SiteID: siteID,
                        YearOld: yearOld,
                        YearNew: yearNew,
                        Difference: diff
                    }
                })
            }
        }
    }
}



// Define the new FeatureSet structure
var output = {
    fields: [
        { name: "SiteID", type: "esriFieldTypeString" },
        { name: "YearOld", type: "esriFieldTypeInteger" },
        { name: "YearNew", type: "esriFieldTypeInteger" },
        { name: "Difference", type: "esriFieldTypeDouble" }
    ],
    geometryType: "",
    features: results
}

return FeatureSet(Text(output))

 

0 Kudos
Neal_t_k
Frequent Contributor

Thinking about this some more, easiest way might be to create a new feature layer with all the possible year -year combinations doing a 1 to many self join based on your site, and pre-calculate the differences in a in a new field in the resulting table.   Add that feature layer to your map and symbolize as you see fit. Then you would be able to use the two category selectors to filter in the dashboard.  This would appear dynamic, however it would need to be updated every time new data was added to the original dataset.  If that is frequent maybe a schedule python script to append new data. 

Depending what you want you could further pre-filter the data to get rid of and features where the first year selection is not more recent than the second year selection. 

0 Kudos
MiaWhite34
Emerging Contributor

You can achieve this by creating an Arcade expression that references both year selections through dashboard parameters or feature set filters. Then, bind the expression result to your map symbology. Experience Builder currently doesn’t support dynamic field-to-field comparisons directly, but using a data view or pre-calculated difference layer in ArcGIS Online can replicate that interaction effectively.

0 Kudos