Select to view content in your preferred language

Return single text values in list from comma separated field

843
7
Jump to solution
06-05-2024 07:18 AM
dwold
by
Frequent Contributor

I am trying to display text that has multiple responses and populate them in a list individually. In the example below my goal is to have something shown below but single responses in each target, not all 5 listed for every one

dwold_0-1717596337299.png

Goal is to get Targets to read:

Target: Relocation_Assistance

Target: Relocation_Assistance_for_People_with_Access_and_Functional_Needs

Target: Community_Sheltering

Target: Community_Sheltering_for_People_with_Access_and_Functional_Needs

Target: Community_Sheltering_Animals

There may be only on "target" so if that is the case, I'd like the list to retunr that single text sting. Right now my list is doing this:

dwold_1-1717596700292.png

Here's what I currently have in my Advanced Formatting section:

 

var result = "";
if (!IsEmpty($datapoint.target)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target: </i></span>` +$datapoint.target;
}
if (!IsEmpty($datapoint.target_goal)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal;
}
if (!IsEmpty($datapoint.target_value)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value;
}
if (!IsEmpty($datapoint.gap_value)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value;
}
if (!IsEmpty($datapoint.gap_percent)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent+'%';
}
if (!IsEmpty($datapoint.target)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target: </i></span>` +$datapoint.target;
}
if (!IsEmpty($datapoint.target_goal_1)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal_1;
}
if (!IsEmpty($datapoint.target_value_1)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value_1;
}
if (!IsEmpty($datapoint.gap_value_1)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value_1;
}
if (!IsEmpty($datapoint.gap_percent_1)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent_1+'%';
}
if (!IsEmpty($datapoint.target)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target: </i></span>` +$datapoint.target;
}
if (!IsEmpty($datapoint.target_goal_2)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal_2;
}
if (!IsEmpty($datapoint.target_value_2)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value_2;
}
if (!IsEmpty($datapoint.gap_value_2)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value_2;
}
if (!IsEmpty($datapoint.gap_percent_2)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent_2+'%';
}
if (!IsEmpty($datapoint.target)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target: </i></span>` +$datapoint.target;
}
if (!IsEmpty($datapoint.target_goal_3)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal_3;
}
if (!IsEmpty($datapoint.target_value_3)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value_3;
}
if (!IsEmpty($datapoint.gap_value_3)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value_3;
}
if (!IsEmpty($datapoint.gap_percent_3)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent_3+'%';
}
if (!IsEmpty($datapoint.target)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target: </i></span>` +$datapoint.target;
}
if (!IsEmpty($datapoint.target_goal_4)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal_4;
}
if (!IsEmpty($datapoint.target_value_4)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value_4;
}
if (!IsEmpty($datapoint.gap_value_4)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value_4;
}
if (!IsEmpty($datapoint.gap_percent_4)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent_4+'%';
}

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     result
   }
}

 

This isn't correct but would I do something along the lines of:

var target_one = ([$datapoint.target] , 0)

var target_two = ([$datapoint.target] , 1)

var target_three = ([$datapoint.target] , 2)

 

@KenBuja I saw you commented on another post about using the OrderBy but I'm not sure if that would work in this situation?

0 Kudos
2 Solutions

Accepted Solutions
KenBuja
MVP Esteemed Contributor

If I understand how your fields are set up, give this a try:

**Edited to fix an error (i.e. "$datapoint[tg]" instead of "$datapoint.tg")**

var result = "";
if (!IsEmpty($datapoint.target)) {
  var targetArray = Split($datapoint.target, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
    
    var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')
    if (!IsEmpty($datapoint[tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[tg]}`;
    var tv = iif(i > 0, `target_value_${i}`, 'target_value')
    if (!IsEmpty($datapoint[tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[tv]}`;
    var gv = iif(i > 0, `gap_value_${i}`, 'gap_value')
    if (!IsEmpty($datapoint[gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[gv]}`;    
    var gp = iif(i > 0, `gap_percent_${i}`, 'gap_percent')
    if (!IsEmpty($datapoint[gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number) </i></span>${$datapoint[gp]}`;
  } 
}

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     result
   }
}

 

 

View solution in original post

KenBuja
MVP Esteemed Contributor

A little explanation of what my code is doing. It makes the array of targets and loops through them. The variable i is a number representing the position of the element in the array, so it will be 0 for the first loop, 1 for the second loop, and so on. That number gets tacked on the end of the field name if the number isn't equal to zero with this IIf function

var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')

 

 

Unfortunately, you're adding more complexity to this. Looking at the data, the employment fields are only going to be added for the targets "Short_Term_Unemployed_and_Underemployed" and "Long_Term_Unemployed_and_Underemployed. Also, the "Situational_Briefings" target uses a different naming convention. So this code searches for those cases and gets the fields differently.

var cap_target_text = Replace($datapoint.target, '_', ' ')

var result = "";
if (!IsEmpty(cap_target_text)) {
  var targetArray = Split(cap_target_text, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
    
    var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')
    if (!IsEmpty($datapoint[tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[tg]}`;
    var tv = iif(i > 0, `target_value_${i}`, 'target_value')
    if (!IsEmpty($datapoint[tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[tv]}`;
    var gv = iif(i > 0, `gap_value_${i}`, 'gap_value')
    if (!IsEmpty($datapoint[gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[gv]}`;    
    var gp = iif(i > 0, `gap_percent_${i}`, 'gap_percent')
    if (!IsEmpty($datapoint[gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[gp]}%`;

    if (Find('Unemployed', targetArray[i]) > -1) {
      var unemploy_tg = iif(i > 0, `unemploy_target_goal_${i}`, 'unemploy_target_goal')
      if (!IsEmpty($datapoint[unemploy_tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[unemploy_tg]}`;
      var unemploy_tv = iif(i > 0, `unemploy_target_value_${i}`, 'unemploy_target_value')
      if (!IsEmpty($datapoint[unemploy_tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[unemploy_tv]}`;
      var unemploy_gv = iif(i > 0, `unemploy_gap_value_${i}`, 'unemploy_gap_value')
      if (!IsEmpty($datapoint[unemploy_gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[unemploy_gv]}`;    
      var unemploy_gp = iif(i > 0, `unemploy_gap_percent_${i}`, 'unemploy_gap_percent')
      if (!IsEmpty($datapoint[unemploy_gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[unemploy_gp]}%`;
    }

    if (targetArray[i] == 'Situational_Briefings'){
      if (!IsEmpty($datapoint.sb_target_goal_5)) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint.sb_target_goal_5}`;
      if (!IsEmpty($datapoint.target_value_numeric_5)) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint.target_value_numeric_5}`;
      if (!IsEmpty($datapoint.sb_gap_value_5)) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint.sb_gap_value_5}`;
      if (!IsEmpty($datapoint.sb_gap_percent_5)) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint.sb_gap_percent_5}`;
    }
  } 
}

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     result
   }
}

 

View solution in original post

7 Replies
KenBuja
MVP Esteemed Contributor

You can use the Split function to separate out the comma-separated values into an array and loop through that array to get the list of targets. This will also work if there is just one target.

var result = "";
if (!IsEmpty($datapoint.target)) {
  var targetArray = Split($datapoint.target, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
  } 
}

 

dwold
by
Frequent Contributor

@KenBuja thanks for the suggestion/investigation this! I am on the right track, but it lists each target instead of the single one for each "section". I believe it is because the split values aren't empty?

Current list:

dwold_0-1717599730980.png

my goal is to have something like this:

dwold_1-1717600229194.png

Any suggestions on how to get that look?

var result = "";
if (!IsEmpty($datapoint.target)) {
  var targetArray = Split($datapoint.target, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
  } 
}
if (!IsEmpty($datapoint.target_goal)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal;
}
if (!IsEmpty($datapoint.target_value)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value;
}
if (!IsEmpty($datapoint.gap_value)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value;
}
if (!IsEmpty($datapoint.gap_percent)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent+'%';
}
if (!IsEmpty($datapoint.target)) {
  var targetArray = Split($datapoint.target, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
  } 
}
if (!IsEmpty($datapoint.target_goal_1)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal_1;
}
if (!IsEmpty($datapoint.target_value_1)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value_1;
}
if (!IsEmpty($datapoint.gap_value_1)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value_1;
}
if (!IsEmpty($datapoint.gap_percent_1)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent_1+'%';
}
if (!IsEmpty($datapoint.target)) {
  var targetArray = Split($datapoint.target, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
  } 
}
if (!IsEmpty($datapoint.target_goal_2)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal_2;
}
if (!IsEmpty($datapoint.target_value_2)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value_2;
}
if (!IsEmpty($datapoint.gap_value_2)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value_2;
}
if (!IsEmpty($datapoint.gap_percent_2)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent_2+'%';
}
if (!IsEmpty($datapoint.target)) {
  var targetArray = Split($datapoint.target, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
  } 
}
if (!IsEmpty($datapoint.target_goal_3)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal_3;
}
if (!IsEmpty($datapoint.target_value_3)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value_3;
}
if (!IsEmpty($datapoint.gap_value_3)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value_3;
}
if (!IsEmpty($datapoint.gap_percent_3)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent_3+'%';
}
if (!IsEmpty($datapoint.target)) {
  var targetArray = Split($datapoint.target, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
  } 
}
if (!IsEmpty($datapoint.target_goal_4)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Goal: </i></span>` +$datapoint.target_goal_4;
}
if (!IsEmpty($datapoint.target_value_4)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Target Value: </i></span>` +$datapoint.target_value_4;
}
if (!IsEmpty($datapoint.gap_value_4)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Value: </i></span>` +$datapoint.gap_value_4;
}
if (!IsEmpty($datapoint.gap_percent_4)) {
    result += "<br><br>" + `<span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>` +$datapoint.gap_percent_4+'%';
}

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     result
   }
}

 

0 Kudos
KenBuja
MVP Esteemed Contributor

If I understand how your fields are set up, give this a try:

**Edited to fix an error (i.e. "$datapoint[tg]" instead of "$datapoint.tg")**

var result = "";
if (!IsEmpty($datapoint.target)) {
  var targetArray = Split($datapoint.target, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
    
    var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')
    if (!IsEmpty($datapoint[tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[tg]}`;
    var tv = iif(i > 0, `target_value_${i}`, 'target_value')
    if (!IsEmpty($datapoint[tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[tv]}`;
    var gv = iif(i > 0, `gap_value_${i}`, 'gap_value')
    if (!IsEmpty($datapoint[gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[gv]}`;    
    var gp = iif(i > 0, `gap_percent_${i}`, 'gap_percent')
    if (!IsEmpty($datapoint[gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number) </i></span>${$datapoint[gp]}`;
  } 
}

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     result
   }
}

 

 

dwold
by
Frequent Contributor

@KenBuja that worked! as always very much appreciative for your time and help!

dwold_0-1717610498990.png

 

0 Kudos
dwold
by
Frequent Contributor

@KenBuja I added some more fields to the code and got it (mostly) working. After adding those additional fields, the list doesn't return the second Unemployment values (those are the fields I added). Do you see anything in the code that is preventing the list from displaying the second Unemployment values?

dwold_2-1717677250103.png

dwold_3-1717677263337.png

var cap_target_text = Replace($datapoint.target, '_', ' ')

var result = "";
if (!IsEmpty(cap_target_text)) {
  var targetArray = Split(cap_target_text, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
    
    var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')
    if (!IsEmpty($datapoint[tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[tg]}`;
    var tv = iif(i > 0, `target_value_${i}`, 'target_value')
    if (!IsEmpty($datapoint[tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[tv]}`;
    var gv = iif(i > 0, `gap_value_${i}`, 'gap_value')
    if (!IsEmpty($datapoint[gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[gv]}`;    
    var gp = iif(i > 0, `gap_percent_${i}`, 'gap_percent')
    if (!IsEmpty($datapoint[gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[gp]}%`;
    var sb_tg = iif(i > 4, `target_goal_${i}`, 'sb_target_goal_5')
    if (!IsEmpty($datapoint[sb_tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[sb_tg]}`;
    var sb_tv = iif(i > 4, `target_value_${i}`, 'target_value_numeric_5')
    if (!IsEmpty($datapoint[sb_tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[sb_tv]}`;
    var sb_gv = iif(i > 4, `gap_value_${i}`, 'sb_gap_value_5')
    if (!IsEmpty($datapoint[sb_gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[sb_gv]}`;    
    var sb_gp = iif(i > 4, `gap_percent_${i}`, 'sb_gap_percent_5')
    if (!IsEmpty($datapoint[sb_gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[sb_gp]}%`;
    var unemploy_tg = iif(i > 4, `unemploy_target_goal_${i}`, 'unemploy_target_goal')
    if (!IsEmpty($datapoint[unemploy_tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[unemploy_tg]}`;
    var unemploy_tv = iif(i > 4, `unemploy_target_value_${i}`, 'unemploy_target_value')
    if (!IsEmpty($datapoint[unemploy_tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[unemploy_tv]}`;
    var unemploy_gv = iif(i > 4, `unemploy_gap_value_${i}`, 'unemploy_gap_value')
    if (!IsEmpty($datapoint[unemploy_gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[unemploy_gv]}`;    
    var unemploy_gp = iif(i > 4, `unemploy_gap_percent_${i}`, 'unemploy_gap_percent')
    if (!IsEmpty($datapoint[unemploy_gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[unemploy_gp]}%`;
  } 
}

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     result
   }
}

Would splitting out Unemployment from the rest be a possible solution? I am new to arcade and not good with if statements but something like this:

in between lines 4 & 5: if cap_target_text != 'Short Term Unemployed and Underemployed' , 'Long Term Unemployed and Underemployed'

in between lines 29 & 30: if cap_target_text == 'Short Term Unemployed and Underemployed' , 'Long Term Unemployed and Underemployed'

var cap_target_text = Replace($datapoint.target, '_', ' ')
var unemploy_target_text = Replace($datapoint.target, '_', ' ')

var result = "";
if (!IsEmpty(cap_target_text)) {
  var targetArray = Split(cap_target_text, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
    
    var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')
    if (!IsEmpty($datapoint[tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[tg]}`;
    var tv = iif(i > 0, `target_value_${i}`, 'target_value')
    if (!IsEmpty($datapoint[tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[tv]}`;
    var gv = iif(i > 0, `gap_value_${i}`, 'gap_value')
    if (!IsEmpty($datapoint[gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[gv]}`;    
    var gp = iif(i > 0, `gap_percent_${i}`, 'gap_percent')
    if (!IsEmpty($datapoint[gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[gp]}%`;
    var sb_tg = iif(i > 4, `target_goal_${i}`, 'sb_target_goal_5')
    if (!IsEmpty($datapoint[sb_tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[sb_tg]}`;
    var sb_tv = iif(i > 4, `target_value_${i}`, 'target_value_numeric_5')
    if (!IsEmpty($datapoint[sb_tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[sb_tv]}`;
    var sb_gv = iif(i > 4, `gap_value_${i}`, 'sb_gap_value_5')
    if (!IsEmpty($datapoint[sb_gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[sb_gv]}`;    
    var sb_gp = iif(i > 4, `gap_percent_${i}`, 'sb_gap_percent_5')
    if (!IsEmpty($datapoint[sb_gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[sb_gp]}%`;
  } 
}

var unemploy_result = "";
if (!IsEmpty(unemploy_target_text)) {
  var targetArray = Split(unemploy_target_text, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
    
    var unemploy_tg = iif(i > 0, `unemploy_target_goal_${i}`, 'unemploy_target_goal')
    if (!IsEmpty($datapoint[unemploy_tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[unemploy_tg]}`;
    var unemploy_tv = iif(i > 0, `unemploy_target_value_${i}`, 'unemploy_target_value')
    if (!IsEmpty($datapoint[unemploy_tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[unemploy_tv]}`;
    var unemploy_gv = iif(i > 0, `unemploy_gap_value_${i}`, 'unemploy_gap_value')
    if (!IsEmpty($datapoint[unemploy_gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[unemploy_gv]}`;    
    var unemploy_gp = iif(i > 0, `unemploy_gap_percent_${i}`, 'unemploy_gap_percent')
    if (!IsEmpty($datapoint[unemploy_gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[unemploy_gp]}%`;
  } 
}

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     result,
     unemploy_result
   }
}

 

 

I've attached the data table I am using

 

0 Kudos
KenBuja
MVP Esteemed Contributor

A little explanation of what my code is doing. It makes the array of targets and loops through them. The variable i is a number representing the position of the element in the array, so it will be 0 for the first loop, 1 for the second loop, and so on. That number gets tacked on the end of the field name if the number isn't equal to zero with this IIf function

var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')

 

 

Unfortunately, you're adding more complexity to this. Looking at the data, the employment fields are only going to be added for the targets "Short_Term_Unemployed_and_Underemployed" and "Long_Term_Unemployed_and_Underemployed. Also, the "Situational_Briefings" target uses a different naming convention. So this code searches for those cases and gets the fields differently.

var cap_target_text = Replace($datapoint.target, '_', ' ')

var result = "";
if (!IsEmpty(cap_target_text)) {
  var targetArray = Split(cap_target_text, ",")
  for (var i in targetArray) {
    result += `<br><br><span style="color:#ffffbe"><i>Target: </i></span> ${Trim(targetArray[i])}`;
    
    var tg = iif(i > 0, `target_goal_${i}`, 'target_goal')
    if (!IsEmpty($datapoint[tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[tg]}`;
    var tv = iif(i > 0, `target_value_${i}`, 'target_value')
    if (!IsEmpty($datapoint[tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[tv]}`;
    var gv = iif(i > 0, `gap_value_${i}`, 'gap_value')
    if (!IsEmpty($datapoint[gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[gv]}`;    
    var gp = iif(i > 0, `gap_percent_${i}`, 'gap_percent')
    if (!IsEmpty($datapoint[gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[gp]}%`;

    if (Find('Unemployed', targetArray[i]) > -1) {
      var unemploy_tg = iif(i > 0, `unemploy_target_goal_${i}`, 'unemploy_target_goal')
      if (!IsEmpty($datapoint[unemploy_tg])) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint[unemploy_tg]}`;
      var unemploy_tv = iif(i > 0, `unemploy_target_value_${i}`, 'unemploy_target_value')
      if (!IsEmpty($datapoint[unemploy_tv])) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint[unemploy_tv]}`;
      var unemploy_gv = iif(i > 0, `unemploy_gap_value_${i}`, 'unemploy_gap_value')
      if (!IsEmpty($datapoint[unemploy_gv])) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint[unemploy_gv]}`;    
      var unemploy_gp = iif(i > 0, `unemploy_gap_percent_${i}`, 'unemploy_gap_percent')
      if (!IsEmpty($datapoint[unemploy_gp])) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint[unemploy_gp]}%`;
    }

    if (targetArray[i] == 'Situational_Briefings'){
      if (!IsEmpty($datapoint.sb_target_goal_5)) result += `<br><br><span style="color:#ffffbe"><i>Target Goal: </i></span>${$datapoint.sb_target_goal_5}`;
      if (!IsEmpty($datapoint.target_value_numeric_5)) result += `<br><br><span style="color:#ffffbe"><i>Target Value: </i></span>${$datapoint.target_value_numeric_5}`;
      if (!IsEmpty($datapoint.sb_gap_value_5)) result += `<br><br><span style="color:#ffffbe"><i>Gap Value: </i></span>${$datapoint.sb_gap_value_5}`;
      if (!IsEmpty($datapoint.sb_gap_percent_5)) result += `<br><br><span style="color:#ffffbe"><i>Gap Percent (rounded to the nearest whole number): </i></span>${$datapoint.sb_gap_percent_5}`;
    }
  } 
}

return {
  textColor: '',
  backgroundColor: '',
  separatorColor:'',
  selectionColor: '',
  selectionTextColor: '',
   attributes: {
     result
   }
}

 

dwold
by
Frequent Contributor

@KenBuja Awesome, Thank you!!!!

0 Kudos