<?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 Performing calculations on multi-valued fields in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453218#M128283</link>
    <description>&lt;P&gt;Hello, I am trying to perform calculations on multiple fields. &lt;/P&gt;

&lt;P&gt;I am working with data in the format of Key='value1,value2,value3,value4' which can contain anywhere from 1 to 4 values. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Input:&lt;/STRONG&gt; &lt;BR /&gt;
height='32,12,14,13' or width='32' &lt;BR /&gt;
   as well as variance='3.24e-2,4.23e+3,1.12e-4,1.01e-3'&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Query:&lt;/STRONG&gt;&lt;BR /&gt;
`&lt;BR /&gt;
index=myindex sourcetype=mysourcetype&lt;BR /&gt;
| transaction source &lt;BR /&gt;
| foreach *&lt;BR /&gt;
  [eval &amp;lt;&amp;gt;=if(match('&amp;lt;&amp;gt;', "[\d.,e+-]+"), '&amp;lt;&amp;gt;', '') &lt;BR /&gt;
  | eval total=0 | eval count=1&lt;BR /&gt;
  | eval &amp;lt;&amp;gt;=replace(&amp;lt;&amp;gt;,"\'","")&lt;BR /&gt;
  | makemv delim="," '&amp;lt;&amp;gt;' &lt;BR /&gt;
  | mvexpand '&amp;lt;&amp;gt;' &lt;BR /&gt;
  | foreach &amp;lt;&amp;gt;&lt;BR /&gt;
    [eval total_&amp;lt;&lt;FIELD&gt;&amp;gt;=total + &amp;lt;&lt;FIELD&gt;&amp;gt;&lt;BR /&gt;
    | eval count=count + 1]&lt;BR /&gt;
  | eval avg_&amp;lt;&amp;gt;=&amp;lt;&amp;gt;/count]&lt;BR /&gt;
| table *, total, count&lt;BR /&gt;
| transpose include_empty=false 10&lt;/FIELD&gt;&lt;/FIELD&gt;&lt;/P&gt;

&lt;P&gt;`&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Expected Output:&lt;/STRONG&gt;&lt;BR /&gt;
height=17.75&lt;BR /&gt;
width=32&lt;BR /&gt;
variance=1.0575e+3&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Actual Output:&lt;/STRONG&gt;&lt;BR /&gt;
height=032,12,14,13, width=32&lt;BR /&gt;
variance=03.24e-2,4.23e+3,1.12e-4,1.01e-3&lt;/P&gt;

&lt;P&gt;Thank you in advance for any help provided! &lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 23:47:26 GMT</pubDate>
    <dc:creator>ztayluh</dc:creator>
    <dc:date>2020-09-29T23:47:26Z</dc:date>
    <item>
      <title>Performing calculations on multi-valued fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453218#M128283</link>
      <description>&lt;P&gt;Hello, I am trying to perform calculations on multiple fields. &lt;/P&gt;

&lt;P&gt;I am working with data in the format of Key='value1,value2,value3,value4' which can contain anywhere from 1 to 4 values. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Input:&lt;/STRONG&gt; &lt;BR /&gt;
height='32,12,14,13' or width='32' &lt;BR /&gt;
   as well as variance='3.24e-2,4.23e+3,1.12e-4,1.01e-3'&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Query:&lt;/STRONG&gt;&lt;BR /&gt;
`&lt;BR /&gt;
index=myindex sourcetype=mysourcetype&lt;BR /&gt;
| transaction source &lt;BR /&gt;
| foreach *&lt;BR /&gt;
  [eval &amp;lt;&amp;gt;=if(match('&amp;lt;&amp;gt;', "[\d.,e+-]+"), '&amp;lt;&amp;gt;', '') &lt;BR /&gt;
  | eval total=0 | eval count=1&lt;BR /&gt;
  | eval &amp;lt;&amp;gt;=replace(&amp;lt;&amp;gt;,"\'","")&lt;BR /&gt;
  | makemv delim="," '&amp;lt;&amp;gt;' &lt;BR /&gt;
  | mvexpand '&amp;lt;&amp;gt;' &lt;BR /&gt;
  | foreach &amp;lt;&amp;gt;&lt;BR /&gt;
    [eval total_&amp;lt;&lt;FIELD&gt;&amp;gt;=total + &amp;lt;&lt;FIELD&gt;&amp;gt;&lt;BR /&gt;
    | eval count=count + 1]&lt;BR /&gt;
  | eval avg_&amp;lt;&amp;gt;=&amp;lt;&amp;gt;/count]&lt;BR /&gt;
| table *, total, count&lt;BR /&gt;
| transpose include_empty=false 10&lt;/FIELD&gt;&lt;/FIELD&gt;&lt;/P&gt;

&lt;P&gt;`&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Expected Output:&lt;/STRONG&gt;&lt;BR /&gt;
height=17.75&lt;BR /&gt;
width=32&lt;BR /&gt;
variance=1.0575e+3&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Actual Output:&lt;/STRONG&gt;&lt;BR /&gt;
height=032,12,14,13, width=32&lt;BR /&gt;
variance=03.24e-2,4.23e+3,1.12e-4,1.01e-3&lt;/P&gt;

&lt;P&gt;Thank you in advance for any help provided! &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:47:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453218#M128283</guid>
      <dc:creator>ztayluh</dc:creator>
      <dc:date>2020-09-29T23:47:26Z</dc:date>
    </item>
    <item>
      <title>Re: Performing calculations on multi-valued fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453219#M128284</link>
      <description>&lt;P&gt;can you share sample events and desired results?&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 18:31:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453219#M128284</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-03-22T18:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: Performing calculations on multi-valued fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453220#M128285</link>
      <description>&lt;P&gt;Hi Adonio, here is an example event. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;21-Mar-19 05:10:46 
total_Height_mm='66,41,29,28'
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Each event has a different multi-value pair.&lt;BR /&gt;
There are ~150+ events per source&lt;/P&gt;

&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 19:01:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453220#M128285</guid>
      <dc:creator>ztayluh</dc:creator>
      <dc:date>2019-03-22T19:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Performing calculations on multi-valued fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453221#M128286</link>
      <description>&lt;P&gt;I am still puzzled as to what is the desired output ...&lt;BR /&gt;
can you share at least 10 events and the desired output from search?&lt;/P&gt;</description>
      <pubDate>Sat, 23 Mar 2019 21:30:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453221#M128286</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-03-23T21:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Performing calculations on multi-valued fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453222#M128287</link>
      <description>&lt;P&gt;I apologize, hopefully this will be clearer&lt;/P&gt;

&lt;P&gt;If I had an event like this:&lt;BR /&gt;
&lt;CODE&gt;21-Mar-19 05:10:46 &lt;BR /&gt;
 total_Height_mm='66,41,29,28'&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;I would expect to get:&lt;/STRONG&gt;&lt;BR /&gt;
avg_total_Height_mm=(66 + 41 + 29 + 28)/4 = 41&lt;/P&gt;

&lt;P&gt;Here are some additional events and their desired output:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;21-Mar-19 05:10:46 &lt;BR /&gt;
 total_Pressure_psi='16.16,16.16,16.16,16.16'&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;BR /&gt;
avg_total_Pressure_psi = 16.16&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;21-Mar-19 05:10:46 &lt;BR /&gt;
total_Pressure_kpa='3.2405e+2,3.8095e+2,3.4152e+2,3.9155e+2'&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;BR /&gt;
avg_total_Pressure_kpa=3.595175e+2 &lt;/P&gt;

&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 23:52:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453222#M128287</guid>
      <dc:creator>ztayluh</dc:creator>
      <dc:date>2020-09-29T23:52:06Z</dc:date>
    </item>
    <item>
      <title>Re: Performing calculations on multi-valued fields</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453223#M128288</link>
      <description>&lt;P&gt;hope i understood your question, try this out.&lt;BR /&gt;
also, plenty will depend on how the data is indexed and the fields you extract&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval data = "21-Mar-19 05:10:46 total_Height_mm='66,41,29,28';;;21-Mar-19 05:10:46 total_Pressure_psi='16.16,16.16,16.16,16.16';;;21-Mar-19 05:10:46 total_Pressure_kpa='3.2405e+2,3.8095e+2,3.4152e+2,3.9155e+2'"
| makemv delim=";;;" data 
| mvexpand data
| rex field=data "(?&amp;lt;time&amp;gt;\S+\s\S+)\s(?&amp;lt;fields&amp;gt;[^\=]+)\=\'(?&amp;lt;values&amp;gt;[^\']+)"
| makemv delim="," values
| mvexpand values
| stats avg(values) as avg_value by fields
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 13:23:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Performing-calculations-on-multi-valued-fields/m-p/453223#M128288</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-03-26T13:23:27Z</dc:date>
    </item>
  </channel>
</rss>

