Jump to content

Convert real column to string formatted column (with dollar sign and thousands separator)


Kem Azlan
Go to solution Solved by Kem Azlan,

Recommended Posts

Hi, I just want to check it out whether is there a way to convert some column (in type real) into string with format where (can add $ and thousands separator) using Spotfire expression? I try to avoid using TERR or Python script to convert them since it may impact the engine in server when loading the dashboard.

image.png.7bac1cab9bda539db59d8f09fbd057c5.png

Link to comment
Share on other sites

Does the column have to be a String?  If no, you can click on Data/Column Properties, highlight this column, then click on the Formatting tab.   Select 'Currency' and check the "Use thousands separator" and Spotfire will re-format it as you have described above.

If it needs to be a string, then you can use the Data/Transform data option with "Calculate and replace column" and "Change data type" transformations.

Link to comment
Share on other sites

Posted (edited)

Hi Kirsten, yes, the column should be in String since I try to append the table later after I manage to convert as above. 

I tried on Data/Transform data option, but it not worked as expected.  

image.png.05e80ad2e556419344ba766ac7ca7cc3.png

Edited by Kem Azlan
Link to comment
Share on other sites

Hi @Kirsten Smith (she/her). I might figure out on the formula to convert the column. Here is:

If(Len(String([REVENUE]))<16,Concatenate('$',If(Len(Split(String([REVENUE]),'.',1))<=3,Split(String([REVENUE]),'.',1),If(Len(Split(String([REVENUE]),'.',1))<=6,Concatenate(left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 3),',',right(Split(String([REVENUE]),'.',1),3)),If(Len(Split(String([REVENUE]),'.',1))<=9,Concatenate(left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 6),',',Mid(Split(String([REVENUE]),'.',1),3,3),',',right(Split(String([REVENUE]),'.',1),3)),If(Len(Split(String([REVENUE]),'.',1))<=12,Concatenate(left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 9),',',Mid(Split(String([REVENUE]),'.',1),3,3),',',Mid(Split(String([REVENUE]),'.',1),6,3),',',right(Split(String([REVENUE]),'.',1),3)),' ')))),'.',Split(String([REVENUE]),'.',2)),'')

Noted that the formula works for only positive value and up to billions. 

image.png.3eb3b8327cc0d422f6f90a383f0de1a4.png

Link to comment
Share on other sites

Ignore formula above. Here is the correct formula: 

If(Len(String([REVENUE]))<16,Concatenate('$',If(Len(Split(String([REVENUE]),'.',1))<=3,Split(String([REVENUE]),'.',1),If(Len(Split(String([REVENUE]),'.',1))<=6,Concatenate(left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 3),',',Right(Split(String([REVENUE]),'.',1),3)),If(Len(Split(String([REVENUE]),'.',1))<=9,Concatenate(left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 6),',',Mid(Split(String([REVENUE]),'.',1),2,3),',',Right(Split(String([REVENUE]),'.',1),3)),If(Len(Split(String([REVENUE]),'.',1))<=12,Concatenate(left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 9),',',Mid(Split(String([REVENUE]),'.',1),2,3),',',Mid(Split(String([REVENUE]),'.',1),5,3),',',Right(Split(String([REVENUE]),'.',1),3)),' ')))),'.',Split(String([REVENUE]),'.',2)),'')

  • Thanks 1
Link to comment
Share on other sites

  • Solution

Ignore formula above. Here is the correct formula: 

If(Len(String([REVENUE]))<16,Concatenate('$',If(Len(Split(String([REVENUE]),'.',1))<=3,Split(String([REVENUE]),'.',1),If(Len(Split(String([REVENUE]),'.',1))<=6,Concatenate(Left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 3),',',Right(Split(String([REVENUE]),'.',1),3)),If(Len(Split(String([REVENUE]),'.',1))<=9,Concatenate(Left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 6),',',Mid(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 5,3),',',Right(Split(String([REVENUE]),'.',1),3)),If(Len(Split(String([REVENUE]),'.',1))<=12,Concatenate(Left(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 9),',',Mid(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 8,3),',',Mid(Split(String([REVENUE]),'.',1),Len(Split(String([REVENUE]),'.',1)) - 5,3),',',Right(Split(String([REVENUE]),'.',1),3)),' ')))),'.',Split(String([REVENUE]),'.',2)),'')

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...