Select to view content in your preferred language

Advanced Formatting: Using the Filter function to return population values from identified counties

107
2
Jump to solution
Monday
dwold
by
Occasional Contributor III

I am trying to return a sum value of filtered population counts from counties noted in my filter function. I am having issues getting it to display in an indicator widget. See anything I am doing wrong with my code:

var filtered_pop = Filter($datapoint.sum_SUM_Population, 
    'Name == "Shelby County" || Name == "Tipton County" || Name == "Lauderdale County" || Name == "Dyer County" || Name == "Lake County" || Name == "Obion County" || Name == "Weakley County" || Name == "Gibson County" || Name == "Crockett County" || Name == "Haywood County" || Name == "Fayette County"')


return {
  //textColor:'',
  //backgroundColor:'',
  topText: 'Total Population',
  //topTextColor: '',
  //topTextOutlineColor: '',
  topTextMaxSize: 'medium',
  middleText: filtered_pop,
  middleTextColor: '',
  middleTextOutlineColor: '',
  middleTextMaxSize: 'large',
  bottomText: '(counties experiencing at least very strong shaking)',
  //bottomTextColor: '',
  //bottomTextOutlineColor: '',
  //bottomTextMaxSize: 'medium',
  //iconName:'',
  //iconAlign:'left',
  //iconColor:'',
  //iconOutlineColor:'',
  //noValue:false,
  //attributes: {
    // attribute1: '',
    // attribute2: ''
  // }
}

 

dwold_0-1719239288302.png

 

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

This has a few problem. SQL is picky about quotes, so you'll have to encase the entire thing in double quotes and use single quotes for each item. You have to use a single = sign. And you have to use "or" not "||"

var filtered_pop = Filter($datapoint.sum_SUM_Population, 
    "Name = 'Shelby County' or Name = 'Tipton County' or ..." 

 However, by using "in", you can make this much easier to read and much shorter.

var filtered_pop = Filter($datapoint.sum_SUM_Population, 
    "Name in ('Shelby County', 'Tipton County', ...)" 

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

This has a few problem. SQL is picky about quotes, so you'll have to encase the entire thing in double quotes and use single quotes for each item. You have to use a single = sign. And you have to use "or" not "||"

var filtered_pop = Filter($datapoint.sum_SUM_Population, 
    "Name = 'Shelby County' or Name = 'Tipton County' or ..." 

 However, by using "in", you can make this much easier to read and much shorter.

var filtered_pop = Filter($datapoint.sum_SUM_Population, 
    "Name in ('Shelby County', 'Tipton County', ...)" 

 

dwold
by
Occasional Contributor III

@KenBuja thank you!!

0 Kudos