Splunk Search

How to add commas into a number and make the final result a string?

maximusdm
Communicator

hi there, I need to add decimal comma separation for a long number such as 2546788 that is, 2,546,788
Then I need to concatenate a string such as " JAN" + "2,546,788" in the final results. Here is my code.
I just need to add the commas:

source=*DT* index=freewheel sourcetype=delta   earliest=-1mon@mon latest=@mon    
| convert rmcomma("duration")         
| eval previous_month = strftime(relative_time(now(), "-1mon"), "%b")       
| eventstats sum("duration") as Ads 
| fieldformat amount= "$" + tostring(Ads, "commas") <=== this is not working
| eval results = previous_month + ": " + Ads 
| table results amount

Thank you

Tags (3)
0 Karma
1 Solution

somesoni2
SplunkTrust
SplunkTrust

You are using command fieldformat, which just updates the display format of the value but not the underlying value. You should use EVAL instead.

source=DT index=freewheel sourcetype=delta earliest=-1mon@mon latest=@mon 
| convert rmcomma("duration") 
| eval previous_month = strftime(relative_time(now(), "-1mon"), "%b") 
| eventstats sum("duration") as Ads 
| eval amount= "$" + tostring(Ads, "commas")     | eval results = previous_month + ": " + Ads 
| table results amount

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

You are using command fieldformat, which just updates the display format of the value but not the underlying value. You should use EVAL instead.

source=DT index=freewheel sourcetype=delta earliest=-1mon@mon latest=@mon 
| convert rmcomma("duration") 
| eval previous_month = strftime(relative_time(now(), "-1mon"), "%b") 
| eventstats sum("duration") as Ads 
| eval amount= "$" + tostring(Ads, "commas")     | eval results = previous_month + ": " + Ads 
| table results amount

nick405060
Motivator

eval amount= "$" + tostring(amount, "commas")

ty

0 Karma

maximusdm
Communicator

oh crap and I thought I had tried that...guess not. Thanks bud

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...