Select to view content in your preferred language

Using Distinct function in Data Expression

557
5
Jump to solution
04-04-2024 08:21 AM
dwold
by
Frequent Contributor

I have a series of values in a field that I am trying to calculate the sum and display in an Indicator widget. Within that field, there are duplicate values that I do not want to include in the displayed total. Below is an example:

dwold_0-1712243516456.png

Currently, the value in my indicator reads 313. However, I want it to read 278 (subtraction of one 35 value).

I think using the Distinct function would allow me to do this, but I am having trouble getting that to work. Would I need to create a Data Expression and call out that new field to sum or can I do this in the Advanced formatting editor itself?

This is what I have started in a new Data Expression:

 

var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com/"),
  "384158f2ebe34f8ba8b0b39dfe5f5af5",
  0,
  ['target_goal'],
  false
);

var rem_dups = Distinct('target_goal')

return rem_dups

 

 

@jcarlson any thoughts on this?

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You have the syntax incorrect for the Distinct function. You have to include the FeatureSet. And you should also include the Location field, since you might have two different locations with the same values.

var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com/"),
  "384158f2ebe34f8ba8b0b39dfe5f5af5",
  0,
  ['Location', 'target_goal'],
  false
);

return Distinct(fs, ['Location', 'target_goal'])

 

View solution in original post

5 Replies
KenBuja
MVP Esteemed Contributor

You have the syntax incorrect for the Distinct function. You have to include the FeatureSet. And you should also include the Location field, since you might have two different locations with the same values.

var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com/"),
  "384158f2ebe34f8ba8b0b39dfe5f5af5",
  0,
  ['Location', 'target_goal'],
  false
);

return Distinct(fs, ['Location', 'target_goal'])

 

dwold
by
Frequent Contributor

@KenBuja worked perfectly. Thank you!!

0 Kudos
dwold
by
Frequent Contributor

@KenBuja follow-up question to this data expression. If I wanted to return Jurisdictions = All, rather than the 6 total in this dataset. What's the best way to do that?

var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com/"),
  "384158f2ebe34f8ba8b0b39dfe5f5af5",
  0,
  ['Jurisdiction', 'core_capability', 'target_goal'],
  false
);

return Distinct(fs, ['Jurisdiction', 'core_capability', 'target_goal'])

dwold_0-1712685175981.png

 

0 Kudos
KenBuja
MVP Esteemed Contributor

If I understand your question, the Filter function would do that.

dwold
by
Frequent Contributor

that worked, thank you!

0 Kudos