Select to view content in your preferred language

Count Multiple Layers Data Expression

390
1
Jump to solution
10-17-2024 12:50 PM
Labels (1)
ONMaps
by
New Contributor

I'm trying to come up with a data expression to create a bar graph to simply show the count (number of records) within 5 different data layers. The layers represent the same type of data, just range from records from 2020-2024.

I'd like to end up with something like this:

ONMaps_0-1729194592488.png

Thanks for any guidance!

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

There's a GitHub site that contains many different types of data expressions for Dashboard, including one showing how to combine different dataset.

Here's a script that combines two different dataset, each with a Date field. I'm selecting all the dates that aren't null to populate the table. You can expand this to your five data sets.

var portal = Portal("your portal");
var fs1 = FeatureSetByPortalItem(
  portal,
  "itemId for first dataset",
  0,
  ["Date"],
  false
);
var fs2 = FeatureSetByPortalItem(
  portal,
  "itemId for first dataset",
  0,
  ["Date"],
  false
);
var features = [];
var feat;

function populateFeatures(fs) {
  for (var i in fs) {
    if (!IsEmpty(i.Date)) {
      feat = { attributes: { Year: Year(i.Date) } };
      Push(features, feat);
    }
  }
}

var featureSets = [fs1, fs2]

for (var fs in featureSets) {
  console(featureSets[fs])
  populateFeatures(featureSets[fs]);
}

var combinedDict = {
  fields: [{ name: "Year", type: "esriFieldTypeInteger" }],
  geometryType: "",
  features: features
};

return FeatureSet(combinedDict);

 

 

Snag_6d4b20.png

View solution in original post

1 Reply
KenBuja
MVP Esteemed Contributor

There's a GitHub site that contains many different types of data expressions for Dashboard, including one showing how to combine different dataset.

Here's a script that combines two different dataset, each with a Date field. I'm selecting all the dates that aren't null to populate the table. You can expand this to your five data sets.

var portal = Portal("your portal");
var fs1 = FeatureSetByPortalItem(
  portal,
  "itemId for first dataset",
  0,
  ["Date"],
  false
);
var fs2 = FeatureSetByPortalItem(
  portal,
  "itemId for first dataset",
  0,
  ["Date"],
  false
);
var features = [];
var feat;

function populateFeatures(fs) {
  for (var i in fs) {
    if (!IsEmpty(i.Date)) {
      feat = { attributes: { Year: Year(i.Date) } };
      Push(features, feat);
    }
  }
}

var featureSets = [fs1, fs2]

for (var fs in featureSets) {
  console(featureSets[fs])
  populateFeatures(featureSets[fs]);
}

var combinedDict = {
  fields: [{ name: "Year", type: "esriFieldTypeInteger" }],
  geometryType: "",
  features: features
};

return FeatureSet(combinedDict);

 

 

Snag_6d4b20.png