Splunk Search

Convert number to string, to avoid being counted by addtotals/addcoltotals

AllenZhang
Explorer

Hi, I am creating a report with "chart field1 field2", field2 only has 2 values. So the result has 3 columns: Field1, Field2Value1, Field2Value2. And I'd like to use addtotals and addcoltotals for each row and each column.

The issue I am having now, is that value of field1 are numbers so they are counted by both addtotals and addcoltotals, which I don't want.

I believe the easiest way is to convert the type of Field1 to string, with certain format, like  number "12345"  to string "12345", number "123" to "00123". I have tried tostring. But they are still counted.

 

Labels (2)
Tags (1)
0 Karma

impurush
Contributor

Hi @AllenZhang,

Use the file name after the addcoltotals commands to calculate the totals only for the specified column.

<your query>
|table field1,field2,field3
|addcoltotals field2 field3

The above query will calculate the column totals for field2 and field3 only.

0 Karma

AllenZhang
Explorer

Hi impurush,

Thanks for your reply!
I've also found this "work-around" solution.  I actually added "col=true" which adds a row of total for the listed column as well. Good enough for what I need.

Still hard to believe why it's so hard to convert number to string in Splunk, which is much easier in other places, like Excel, Powershell, etc.

Thanks

Allen

0 Karma
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.
Get Updates on the Splunk Community!

Tech Talk Recap | Mastering Threat Hunting

Mastering Threat HuntingDive into the world of threat hunting, exploring the key differences between ...

Observability for AI Applications: Troubleshooting Latency

If you’re working with proprietary company data, you’re probably going to have a locally hosted LLM or many ...

Splunk AI Assistant for SPL vs. ChatGPT: Which One is Better?

In the age of AI, every tool promises to make our lives easier. From summarizing content to writing code, ...