Splunk Search

Adding commas to "stats sum"

rattyryan
Explorer

Hi,

I'm trying to add commas to the TotalPrints field as shown in the code below. I have tried the fieldformat=stringto but it just creates an empty additional TotalPrints field. Can someone please advise?

Also a quick one, how can I make the TotalPrints in descending order and limit it top top 10? I have tried sort- and limite=10 but it doesnt appear to do anything..

source="PrinterDemo.csv"
| multikv fields "IP Address", "Location", "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets"
| addtotals fieldname=TotalPrints "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets"
| table "IP Address", "Location", "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets", TotalPrints
| stats sum(TotalPrints) by "Location"

Tags (1)
1 Solution

somesoni2
Revered Legend

Try this

source="PrinterDemo.csv" | multikv fields "IP Address", "Location", "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets" | addtotals fieldname=TotalPrints "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets" | table "IP Address", "Location", "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets", TotalPrints | stats sum(TotalPrints) as TotalPrints by "Location" | fieldformat TotalPrints=tostring(TotalPrints,"commas") | sort 10 -TotalPrints 

View solution in original post

somesoni2
Revered Legend

Try this

source="PrinterDemo.csv" | multikv fields "IP Address", "Location", "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets" | addtotals fieldname=TotalPrints "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets" | table "IP Address", "Location", "Black Printed Impressions", "Black Printed Large Sheets", "Color Printed Impressions", "Printed Impressions", "Printed 2 Sided Sheets", TotalPrints | stats sum(TotalPrints) as TotalPrints by "Location" | fieldformat TotalPrints=tostring(TotalPrints,"commas") | sort 10 -TotalPrints 

rattyryan
Explorer

Thanks very much 🙂

0 Karma

David
Splunk Employee
Splunk Employee

Alternatively, you could use | fieldformat sum(TotalPrints) = tostring('sum(TotalPrints)', "commas") but I prefer somesoni2's approach!

rattyryan
Explorer

Yup... at the end I've added

| fieldformat TotalPrints=tostring(TotalPrints,"commas")

and

|fieldformat "sum(TotalPrints)"=tostring(TotalPrints,"commas")

no joy.

0 Karma

Ayn
Legend

Can you show what your search string when you tried to use fieldformat looked like?

0 Karma
Get Updates on the Splunk Community!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...