Splunk Search

How can i find difference b/w each MV Item?

reverse
Contributor

alt text

How can i find difference b/w each MV Item?
So far i was able to do only one difference ...

Tags (1)
1 Solution

woodcock
Esteemed Legend

OK, I get it now, you need diffs between the numbers inside of a single multi-value field! try this:

| makeresults 
| eval mvfield="10 30 100 234 64 432 3 632 87"
| makemv mvfield
| eval mvdiff = tonumber(mvindex(mvfield, 0)) - tonumber(mvindex(mvfield, 1))
| foreach 1 2 3 4 5 6 7 8 9 10 11 12 
    [eval _t3Mp = tonumber(mvindex(mvfield, <<FIELD>>)) - tonumber(mvindex(mvfield, <<FIELD>> + 1))
  | eval mvdiff = mvappend(mvdiff, _t3Mp) ]
| fields - _t3Mp
| eval mvdiff = mvappend(mvdiff, "N/A")

View solution in original post

theChain
Explorer
0 Karma

RobertEikel
Engager

This was much easier for me:

 

eval diff=mvmap(field1,if(isnull(mvfind(field2,field1)),field1,null))

 

 

pvarelab
Path Finder

Beware thet the second parameter for mvfind is a regex, so it should be limited by "^" and "$" if you want the best match.

0 Karma

Pamela
Engager

@RobertEikel 

Thanks for this small and easy one-liner that solved my issue. 

0 Karma

woodcock
Esteemed Legend

OK, I get it now, you need diffs between the numbers inside of a single multi-value field! try this:

| makeresults 
| eval mvfield="10 30 100 234 64 432 3 632 87"
| makemv mvfield
| eval mvdiff = tonumber(mvindex(mvfield, 0)) - tonumber(mvindex(mvfield, 1))
| foreach 1 2 3 4 5 6 7 8 9 10 11 12 
    [eval _t3Mp = tonumber(mvindex(mvfield, <<FIELD>>)) - tonumber(mvindex(mvfield, <<FIELD>> + 1))
  | eval mvdiff = mvappend(mvdiff, _t3Mp) ]
| fields - _t3Mp
| eval mvdiff = mvappend(mvdiff, "N/A")

reverse
Contributor

Awesome worked like a charm .. How can i project the differences on a chart now ?
Do i need to expand them first ?

0 Karma

woodcock
Esteemed Legend

I am not sure what you mean but maybe just ask a new question because this seems like a separate problem.

0 Karma

reverse
Contributor

Thanks @woodcock but not able to locate the appropriate solution. please guide

https://answers.splunk.com/answers/760695/generic-solution-to-same-column-value-difference.html

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!

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

Data Persistence in the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. What happens if the OpenTelemetry collector ...

Thanks for the Memories! Splunk University, .conf25, and our Community

Thank you to everyone in the Splunk Community who joined us for .conf25, which kicked off with our iconic ...