advanced label rounding in 10.2?

3225
3
Jump to solution
11-26-2015 07:42 AM
ChrisJ
by
New Contributor III

well, advanced to me anyway....thanks all for giving this a shot:

I have big dollar values in my data which will appear in the labels; some will be in the hundreds of thousands, some will be in the millions.  I've been asked to label then with suffixes depending on their amount:

$945728.73 should appear as $946M (in the hundreds of thousands)

$1726538.34 should appear as $1.7MM (in the millions)

I'm ok with simple vb label rounding, ie. round(value,2), easy, but I'm way out of my depth with this new one, can anyone guide me?

thanks!

cj

0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor

This should work as an Advanced Label expression using VB Script if you change the [Amount] field to your actual field name:

  1. Function FindLabel ( [Amount]  ) 
  2.   if [Amount] >= 1000000 Then 
  3.     FindLabel = "$" & Round( [Amount]/1000000, 1) & "MM" 
  4.   Else 
  5.     FindLabel = "$" & Round( [Amount]/1000, 0) & "M" 
  6.   End If 
  7. End Functio

I don't know what country you are in, but In America the suffixes would be M and K for millions and thousands.(Repeated in your duplicate post.)

The field name should be added to the expression from the field list to ensure the excel spreadsheet table prefix is added to the beginning of the field name properly.

View solution in original post

3 Replies
DarrenWiens2
MVP Honored Contributor

You can do all of this using a label expression with a VBScript or Python expression equivalent to: "if the number part of the dollar amount is greater than 100,000 but less than 1,000,000, divide it by 1,000, make it an integer, and concatenate that number between "$" and "M" characters. On the other hand, if the number part of the dollar amount is greater than or equal to 1,000,000, divide the number by 1,000,000, make it an integer, and concatenate that number between "$" and "MM"."

ChrisJ
by
New Contributor III

hey thanks for the info and link darren, this is probably going to take me to what I need...

if you or anyone has a moment, I would find a literal example to be extremely helpful - I'm pretty new to this and might not get this syntax on my own...

also: does it matter if the data fields in question are in an excel spreadsheet, joined to the map data?  I don't expect it will but thought I'd double check.

thanks again!

chris j

0 Kudos
RichardFairhurst
MVP Honored Contributor

This should work as an Advanced Label expression using VB Script if you change the [Amount] field to your actual field name:

  1. Function FindLabel ( [Amount]  ) 
  2.   if [Amount] >= 1000000 Then 
  3.     FindLabel = "$" & Round( [Amount]/1000000, 1) & "MM" 
  4.   Else 
  5.     FindLabel = "$" & Round( [Amount]/1000, 0) & "M" 
  6.   End If 
  7. End Functio

I don't know what country you are in, but In America the suffixes would be M and K for millions and thousands.(Repeated in your duplicate post.)

The field name should be added to the expression from the field list to ensure the excel spreadsheet table prefix is added to the beginning of the field name properly.