<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to calculate the difference between two fields that contain a list in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315631#M163658</link>
    <description>&lt;P&gt;Oh I see, and just finally, will this query basically do what's mentioned in the link you provided? I.e. create new events with the same F1 number but different data for the other fields right?&lt;/P&gt;</description>
    <pubDate>Mon, 15 Jan 2018 10:37:30 GMT</pubDate>
    <dc:creator>mahbs</dc:creator>
    <dc:date>2018-01-15T10:37:30Z</dc:date>
    <item>
      <title>How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315626#M163653</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have a question regarding calculating the difference between two fields that are of a list type.&lt;/P&gt;

&lt;P&gt;Here is my query:&lt;/P&gt;

&lt;P&gt;index=indexsourcetype=csv source=src1 host=host1 | stats list(field1) AS F1list(field2) AS F2 list(field3) AS F3 list(field4) AS F4 | join F1 [search index=index sourcetype=csv source=src2 host=host2| stats list(f_1) AS F1 list(f_2) AS f2 list(f_3) AS f3 list(f_4) AS f4 | rename f_1 as F1] |eval DIFF= f2- f3 | sort by F1asc&lt;/P&gt;

&lt;P&gt;Now, if i have a list field that has 2 values:&lt;BR /&gt;
0&lt;BR /&gt;
0&lt;/P&gt;

&lt;P&gt;and I want to subtract each of those values with values form another field, how would I do that? Or is it possible to do so?&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 17:43:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315626#M163653</guid>
      <dc:creator>mahbs</dc:creator>
      <dc:date>2020-09-29T17:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315627#M163654</link>
      <description>&lt;P&gt;hey @mahbs&lt;/P&gt;

&lt;P&gt;If you have &lt;CODE&gt;f1,f2,f3, and f4&lt;/CODE&gt; from &lt;CODE&gt;source1&lt;/CODE&gt; in one event and same for &lt;CODE&gt;source2&lt;/CODE&gt; then you can use stats &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=index sourcetype=csv source=src1 host=host1 | stats count by field1 field2 field3 field4 | join field1 [search index=index sourcetype=csv source=src2 host=host2| stats count by f_1 f_2 f_3 f_4 | rename f_1 as field1 ] | eval difference=f2-f_3 | sort limit=0 field1 | table &amp;lt;the_fields_you_want_to_Show&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to stick to the &lt;CODE&gt;list&lt;/CODE&gt; then try this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=index sourcetype=csv source=src1 host=host1 
| stats list(field1) AS F1 list(field2) AS F2 list(field3) AS F3 list(field4) AS F4 
| eval source1= mvzip(F1,mvzip(F2,mvzip(F3,F4))) 
| mvexpand source1 
| rex field=source1 "(?&amp;lt;F1&amp;gt;\d+),(?&amp;lt;F2&amp;gt;\d+),(?&amp;lt;F3&amp;gt;\d+),(?&amp;lt;F4&amp;gt;\d+)" 
| join F1 
    [ search index=index sourcetype=csv source=src2 host=host2 
    | stats list(f_1) AS f_1 list(f_2) AS f_2 list(f_3) AS f_3 list(f_4) AS f_4 
    | eval source2=mvzip(f_1,mvzip(f_2,mvzip(f_3,f_4))) 
    | mvexpand source2 
    | rex field=source2 "(?&amp;lt;f_1&amp;gt;\d+),(?&amp;lt;f_2&amp;gt;\d+),(?&amp;lt;f_3&amp;gt;\d+),(?&amp;lt;f_4&amp;gt;\d+)" 
    | rename f_1 as F1] 
| eval diff=F2-f_3 
| sort limit=0 F1 
| table &amp;lt;the_fields_you_want_to_Show&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Refer this doc for more :&lt;BR /&gt;
&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Mvexpand"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Mvexpand&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Let me know if this helps you!&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jan 2018 18:43:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315627#M163654</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-01-14T18:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315628#M163655</link>
      <description>&lt;P&gt;Hi, there's a slight issue, the mvzip command doesn't accept more than 2 arguments&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 10:03:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315628#M163655</guid>
      <dc:creator>mahbs</dc:creator>
      <dc:date>2018-01-15T10:03:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315629#M163656</link>
      <description>&lt;P&gt;Also, why do we limit it to 0? Should we not create new events for all F1 data ?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 10:12:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315629#M163656</guid>
      <dc:creator>mahbs</dc:creator>
      <dc:date>2018-01-15T10:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315630#M163657</link>
      <description>&lt;P&gt;hey sorry I have changed my query so that mvzip can accept all the arguments.&lt;/P&gt;

&lt;P&gt;for limit=0 here is a description&lt;BR /&gt;
Specify the number of results to sort. If no count is specified, the default limit of 10000 is used. If "0" is specified, all results are returned.&lt;/P&gt;

&lt;P&gt;I hope this solves your query!&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 10:23:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315630#M163657</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-01-15T10:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315631#M163658</link>
      <description>&lt;P&gt;Oh I see, and just finally, will this query basically do what's mentioned in the link you provided? I.e. create new events with the same F1 number but different data for the other fields right?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 10:37:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315631#M163658</guid>
      <dc:creator>mahbs</dc:creator>
      <dc:date>2018-01-15T10:37:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315632#M163659</link>
      <description>&lt;P&gt;@mayurr98,&lt;/P&gt;

&lt;P&gt;Unfortunately, it's still not working. It's not creating new events with the same value for f1 where there are multiple values for a field.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 10:51:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315632#M163659</guid>
      <dc:creator>mahbs</dc:creator>
      <dc:date>2018-01-15T10:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315633#M163660</link>
      <description>&lt;P&gt;check the final query. I have updated my answer pls have a look at it and let me know .&lt;BR /&gt;
I think this query should work now!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=index sourcetype=csv source=src1 host=host1 
 | stats list(field1) AS F1 list(field2) AS F2 list(field3) AS F3 list(field4) AS F4 
 | eval source1= mvzip(F1,mvzip(F2,mvzip(F3,F4))) 
 | mvexpand source1 
 | rex field=source1 "(?&amp;lt;F1&amp;gt;\d+),(?&amp;lt;F2&amp;gt;\d+),(?&amp;lt;F3&amp;gt;\d+),(?&amp;lt;F4&amp;gt;\d+)" 
 | join F1 
     [ search index=index sourcetype=csv source=src2 host=host2 
     | stats list(f_1) AS f_1 list(f_2) AS f_2 list(f_3) AS f_3 list(f_4) AS f_4 
     | eval source2=mvzip(f_1,mvzip(f_2,mvzip(f_3,f_4))) 
     | mvexpand source2 
     | rex field=source2 "(?&amp;lt;f_1&amp;gt;\d+),(?&amp;lt;f_2&amp;gt;\d+),(?&amp;lt;f_3&amp;gt;\d+),(?&amp;lt;f_4&amp;gt;\d+)" 
     | rename f_1 as F1] 
 | eval diff=F2-f_3 
 | sort limit=0 F1 
 | table &amp;lt;the_fields_you_want_to_Show&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Jan 2018 12:00:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315633#M163660</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-01-15T12:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315634#M163661</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;
Unfortunately, its still not working, It's not seperating multivalue fields into new records. I'm still getting fields with multiple values. Are you sure we're not missing this bit:  rex field=fields "(?\d+),(?\d+)" | table _time alpha beta, i got it from &lt;A href="http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Mvexpand"&gt;http://docs.splunk.com/Documentation/SplunkCloud/6.6.3/SearchReference/Mvexpand&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;Dont we need to create new fields?&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 12:40:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315634#M163661</guid>
      <dc:creator>mahbs</dc:creator>
      <dc:date>2018-01-15T12:40:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate the difference between two fields that contain a list</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315635#M163662</link>
      <description>&lt;P&gt;we are creating new fields using rex command &lt;BR /&gt;
so try this running the above search in pieces and see where you do not get results. &lt;BR /&gt;
Try this run anywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults | eval F1="10 10 20 20 30 40 50" | makemv F1 | mvexpand F2 | appendcols [| makeresults | eval F2="2 5 5 10 15 20 25" | makemv F2  ] | appendcols [| makeresults | eval F3="2 5 5 10 15 20 25" | makemv F3 ] |  eval src1=mvzip(F1,mvzip(F2,F3)) | mvexpand src1 |  rex field=src1 "(?&amp;lt;f1&amp;gt;\d+),(?&amp;lt;f2&amp;gt;\d+),(?&amp;lt;f3&amp;gt;\d+)"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I have already tested this query and it is working fine! &lt;BR /&gt;
Try running this query and see if you are getting results in a single row?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  index=index sourcetype=csv source=src1 host=host1 
      | stats list(field1) AS F1 list(field2) AS F2 list(field3) AS F3 list(field4) AS F4 
      | eval source1= mvzip(F1,mvzip(F2,mvzip(F3,F4))) 
      | mvexpand source1 
      | rex field=source1 "(?&amp;lt;F1&amp;gt;\d+),(?&amp;lt;F2&amp;gt;\d+),(?&amp;lt;F3&amp;gt;\d+),(?&amp;lt;F4&amp;gt;\d+)" 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Thereafter try the second one and then join and see&lt;/P&gt;

&lt;P&gt;I am sure you will get where you are going wrong. I think join is not joining fields as there is nothing common. Or rex field is not working as the rex i have written is only for numberical values do you have strings in your fields? then you need to written &lt;CODE&gt;(?&amp;lt;F1&amp;gt;\w+)&lt;/CODE&gt; at appropriate place&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jan 2018 13:47:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-calculate-the-difference-between-two-fields-that-contain/m-p/315635#M163662</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-01-15T13:47:40Z</dc:date>
    </item>
  </channel>
</rss>

