Select to view content in your preferred language

Dashboard table - data expression for wide format

61
2
Tuesday
Labels (1)
DataOfficer
Frequent Contributor

I'm wondering if anyone can assist with a data expression, or let me know if what I am aiming for is not possible. 

I have a dataset from wildlife monitoring, which captures the date of a species observation, the lifestage (e.g. adult, juvenile), the sex (male, female, unsexed) and the quantity (integer) observed. Multiple observations can occur on the same date. Each combination of the above fields is on a separate row (i.e. in 'long' format). Example below.

datelifestagesexquantity
01/03/2025adultmale2
01/03/2025adultmale5
01/03/2025juvenile 3
02/03/2025adultfemale8
05/03/2025metamorph 1
05/03/2025adultmale3
12/03/2025adult 12
14/03/2025adultfemale6
14/03/2025adultfemale4

 

I am trying to use the Dashboards Table element to produce a summary table of this data, where each date is represented as a row, and then subsequent columns show the daily total for each lifestage*sex combination. For example:

dateadult maleadult femaleadult unsexedjuvenilemetamorph
01/03/202570030
02/03/202508000
05/03/202530001
12/03/2025001200
14/03/82025010000

 

I've gotten so far using Filter and GroupBy statements to summarise counts by day (e.g. resulting in the table format below), but I've not been able to produce a 'wide' format table. Is there any way of doing this?

datetypetotal
01/03/2025adult male7
01/03/2025juvenile3
02/03/2025adult female8

 

I have based my code so far on this example: https://github.com/Esri/arcade-expressions/blob/master/dashboard/dashboard_data/CombineMultipleLayer... but instead of referencing different layers for each variable, I have tried setting up multiple FeatureSets from the same layer, each with a different filter applied (e.g. for each 'type' above). 

I have also produced something similar to my incorrect output above using the List element, but it still doesn't achieve what I am after.

Any help would be hugely appreciated.

 

 

0 Kudos
2 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Hi @DataOfficer,

So the closest recommendation that I can offer is to create a new featureset from a data expression. This would give you something akin to creating a new featureset from existing data and is populated to your output.

Here is an small example on how to construct a separate featureset as a datasource in Dashboards.

var customfields = [
    { 'name' : 'fieldsA' , 'type' : 'esriFieldTypeSmallInteger' },
    { 'name' : 'fieldsB' , 'type' : 'esriFieldTypeDouble' },
    { 'name' : 'fieldsC' , 'type' : 'esriFieldTypeString', Length:7 }
    ]
	
var Values = { 'attributes': {} }
var Geometry = ''
var FS = FeatureSet(Text({
    'fields': customfields,
    'geometryType':Geometry,
    'features' : Values
    }))
return FeatureSet()
0 Kudos
KenBuja
MVP Esteemed Contributor

This can be done with a single GroupBy statement.

GroupBy(
  fs,
  ["date"],
  [
    {
      name: "Adult Male",
      expression:
        "CASE WHEN lifestage = 'adult' and sex = 'male' THEN quantity ELSE 0 END",
      statistic: "Sum"
    },
    {
      name: "Adult Female",
      expression:
        "CASE WHEN lifestage = 'adult' and sex = 'female' THEN quantity ELSE 0 END",
      statistic: "Sum"
    },
    {
      name: "Adult Unsexed",
      expression:
        "CASE WHEN lifestage = 'adult' and sex is null THEN quantity ELSE 0 END",
      statistic: "Sum"
    },
    {
      name: "Juvenile",
      expression:
        "CASE WHEN lifestage = 'juvenile' THEN quantity ELSE 0 END",
      statistic: "Sum"
    },
    {
      name: "Metamorph",
      expression:
        "CASE WHEN lifestage = 'metamorph' THEN quantity ELSE 0 END",
      statistic: "Sum"
    }
  ]
);

I replicated your sample data in the Playground and got your table

KenBuja_1-1760033309646.png