Arcade expression to exclude fields that are null

3000
4
11-18-2022 09:16 AM
Labels (1)
hhmpo
by
New Contributor

Hello,

I am quite a noobie to the expression labeling. I have done some traffic counts at an intersection and was wanting to label each direction according to the ADT and MPH. I am having trouble figuring out how to exclude any null data. I have attached a picture.
Here is my expression in arcade language. 
Thank your for your time.

$feature.North + ' NB ' + $feature.eightyfifth + ' MPH ' + TextFormatting.NewLine + $feature.South + ' SB ' + $feature.eightyfift + ' MPH ' + TextFormatting.NewLine + $feature.East + ' EB ' + $feature.eighty + ' MPH ' +
TextFormatting.NewLine + $feature.West + ' WB ' + $feature.eightfive + ' MPH '

0 Kudos
4 Replies
DuncanHornby
MVP Notable Contributor

See Q&A here.

0 Kudos
KenBuja
MVP Esteemed Contributor

You'll have to build your expression by checking the values for each of the attributes. This example assumes that if the ADT is empty, its speed will also be empty. If not, you'll have to check for those separately. It also uses template literals.

 

var output;
if (!IsEmpty($feature.North)) output += `${$feature.North} NB ${$feature.eightyfifth} MPH\n`;
if (!IsEmpty($feature.South)) output += `${$feature.South} SB ${$feature.eightyfift} MPH\n`;
if (!IsEmpty($feature.East)) output += `${$feature.East} EB ${$feature.eighty} MPH\n`;
if (!IsEmpty($feature.West)) output += `${$feature.West} WB ${$feature.eightfive} MPH\n`;

return Left(output, Count(output) - 1); //this removes the last carriage return

 

 

 

0 Kudos
hhmpo
by
New Contributor

Hello, thank you.

You are correct, if ADT is empty then Speed is empty.
but I am getting invalid expression. error on line 7. expected array or feature set

0 Kudos
KenBuja
MVP Esteemed Contributor

Can you post the code you're using? I tested this code and it's working fine.

0 Kudos