Splunk Search

Renaming column at runtime without knowing at coding time their names.

andreafebbo
Communicator

Hi.
I have the following query

BASE QUERY earliest=-7d latest=now | bucket _time span=7d |  stats count as events by  source _time |chart sum(events) by source, _time 

this query gives me the column source and, in this case, 2 columns (that if i change earliest and span, become N columns).

the deal is that those columns are names by the time, in some strange format (1471557600 and 1472162400).

so, in this case, I have 3 columns: source - 1471557600 - 1472162400.

I need to dynamically rename the columns by position, without knowing their names at run time.

Is there some command like: rename the 2nd column = "this week" ans the 3rd column = "last week" ?

Thank you

1 Solution

sundareshr
Legend

Try this

 BASE QUERY earliest=-14d latest=now | eval when=if(_time>relative_time(now(), "-7d@d"), "Current Week, "Prev Week") |  stats count as events by  source when |chart sum(events) by source, when

View solution in original post

sundareshr
Legend

Try this

 BASE QUERY earliest=-14d latest=now | eval when=if(_time>relative_time(now(), "-7d@d"), "Current Week, "Prev Week") |  stats count as events by  source when |chart sum(events) by source, when

andreafebbo
Communicator

I works!
Thanks a lot!

0 Karma

martin_mueller
SplunkTrust
SplunkTrust

Have you considered using the timewrap command?

https://splunkbase.splunk.com/app/1645/

0 Karma

andreafebbo
Communicator

Thanks!
I didn't use the timewrap for solving this issue but I will use it for other issues.

0 Karma
Get Updates on the Splunk Community!

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 ...

Splunk MCP & Agentic AI: Machine Data Without Limits

Discover how the Splunk Model Context Protocol (MCP) Server can revolutionize the way your organization uses ...