Kem Azlan Posted May 20 Share Posted May 20 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. Link to comment Share on other sites More sharing options...
Kirsten Smith (she/her) Posted May 20 Share Posted May 20 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 More sharing options...
Kem Azlan Posted May 20 Author Share Posted May 20 (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. Edited May 20 by Kem Azlan Link to comment Share on other sites More sharing options...
Kem Azlan Posted May 21 Author Share Posted May 21 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. Link to comment Share on other sites More sharing options...
Kem Azlan Posted May 21 Author Share Posted May 21 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)),'') 1 Link to comment Share on other sites More sharing options...
Solution Kem Azlan Posted May 21 Author Solution Share Posted May 21 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now