Splunk Search

How to use IF and ROUND together

ajmach343
Explorer

Hello,

I am trying to write a search query for responding byte sizes that is a catch all. Currently I have:

index=index  8.8.8.8
| stats sum(resp_bytes) as resp_bytes
| eval resp_bytes=if(resp_bytes=0, "0B",if(resp_bytes<1000000,resp_bytes/1024 . "KB",if(resp_bytes>1000000,resp_bytes/1024/1024 . "MB", null))) 

I have tested this and it works, but now i am trying to add in a "round" to the 2nd decimal spot. and Im not sure where it would go.  

Labels (2)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eval resp_bytes=if(resp_bytes=0, "0B",if(resp_bytes<1000000,round(resp_bytes/1024,2) . "KB",if(resp_bytes>1000000,round(resp_bytes/1024/1024,2) . "MB", null))) 

View solution in original post

ajmach343
Explorer

that worked thank you!

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Try something like this

| eval resp_bytes=if(resp_bytes=0, "0B",if(resp_bytes<1000000,round(resp_bytes/1024,2) . "KB",if(resp_bytes>1000000,round(resp_bytes/1024/1024,2) . "MB", null))) 
Get Updates on the Splunk Community!

Data Management Digest – December 2025

Welcome to the December edition of Data Management Digest! As we continue our journey of data innovation, the ...

Index This | What is broken 80% of the time by February?

December 2025 Edition   Hayyy Splunk Education Enthusiasts and the Eternally Curious!    We’re back with this ...

Unlock Faster Time-to-Value on Edge and Ingest Processor with New SPL2 Pipeline ...

Hello Splunk Community,   We're thrilled to share an exciting update that will help you manage your data more ...