Splunk Search

Append showing result in new row

mcamilleri
Path Finder

If I understood correctly append returns the result in the same row as the previous query. Anyone knows why I get 2 separate rows in my results: 1 row with the foo number and another with the bar number? And no DiffPercent?

earliest=-5m@m latest=@m <my query> |stats sum(eval(MessageCount)) as foo | append [search earliest=-10m@m latest=-5m@m <same query> |stats sum(eval(MessageCount)) as bar] | append [eval DiffPercent = (bar - foo) / bar * 100]

alt text

Tags (2)
0 Karma
1 Solution

yannK
Splunk Employee
Splunk Employee

Yes this is what append does, append row of results after the existing ones.

If you want to add columns, you may want to look at appendcols (but they may not be aligns)
or the join function (using a common field for the join)

Or simply use the append, adding an extra stats or timechart after to reformat.

earliest=-5m@m latest=@m <my query>
|stats sum(eval(MessageCount)) as foo
| eval title="5monthsago"
| append [
search earliest=-10m@m <same query>
|stats sum(eval(MessageCount)) as bar
| eval title="10monthsago"
]
| stats values(foo) AS foo values(bar) AS bar
| eval DiffPercent = (bar - foo) / bar * 100

[edit value to values]

View solution in original post

yannK
Splunk Employee
Splunk Employee

Yes this is what append does, append row of results after the existing ones.

If you want to add columns, you may want to look at appendcols (but they may not be aligns)
or the join function (using a common field for the join)

Or simply use the append, adding an extra stats or timechart after to reformat.

earliest=-5m@m latest=@m <my query>
|stats sum(eval(MessageCount)) as foo
| eval title="5monthsago"
| append [
search earliest=-10m@m <same query>
|stats sum(eval(MessageCount)) as bar
| eval title="10monthsago"
]
| stats values(foo) AS foo values(bar) AS bar
| eval DiffPercent = (bar - foo) / bar * 100

[edit value to values]

mcamilleri
Path Finder

Just needed to change value to values. And it's 5minutesago instead of 5monthsago. Thanks @yannK!

0 Karma

mcamilleri
Path Finder

I get this error - Error in 'stats' command: The argument 'value(foo)' is invalid.

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

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Take Action Automatically on Splunk Alerts with Red Hat Ansible Automation Platform

 Are you ready to revolutionize your IT operations? As digital transformation accelerates, the demand for ...

Calling All Security Pros: Ready to Race Through Boston?

Hey Splunkers, .conf25 is heading to Boston and we’re kicking things off with something bold, competitive, and ...

Beyond Detection: How Splunk and Cisco Integrated Security Platforms Transform ...

Financial services organizations face an impossible equation: maintain 99.9% uptime for mission-critical ...