<?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 How to multiply values within each daily record but group by month? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502854#M195224</link>
    <description>&lt;P&gt;I'm trying hard to achive the following,&lt;BR /&gt;
assume i have this data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DATE=2020-01-01 ITEM1=1 ITEM2=10
DATE=2020-01-02 ITEM1=2 ITEM2=20
DATE=2020-01-03 ITEM1=3 ITEM2=30
....
DATE=2020-01-31 ITEM1=5 ITEM2=40
DATE=2020-02-01 ITEM1=1 ITEM2=10
DATE=2020-02-02 ITEM1=2 ITEM2=20
DATE=2020-02-03 ITEM1=3 ITEM2=20
...
DATE=2020-02-28 ITEM1=4 ITEM2=20
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'd like to multiply ITEM1 with ITEM2 and show it in the field dailytot,&lt;BR /&gt;
the table query looks then:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DATE=*
| rex field=_raw "DATE=\d+-(?&amp;lt;Month&amp;gt;(.*))-\d+ " 
| rex field=_raw "DATE=(?&amp;lt;Year&amp;gt;(.*))-\d+-\d+ "
| rex field=_raw "DATE=\d+-\d+-(?&amp;lt;Day&amp;gt;(.*)\s{1})ITEM1" 
| stats sum(ITEM1) as ITEM1  sum(ITEM2) as ITEM2 by Month, Year, Day
| eval Daytot = ( ITEM1 * ITEM2)
| addcoltotals ITEM1, ITEM2, Daytot labelfield=Month label=Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Month        Year   Day ITEM1       ITEM2       Daytot
01          2020    01  1           10          10
01          2020    02  2           20          40
01          2020    03  3           30          90
01          2020    31  5           40          200
02          2020    01  1           10          10
02          2020    02  2           20          40
02          2020    03  3           20          60
02          2020    28  4           20          80
Total                     21           170         530
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All good so fare but i would like to get monthly totals like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Month    Year     ITEM1 ITEM2 Daytot
01    2020  11   100    340
02     2020     10   70  190
Total   2020    21   170    530
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was thinking about to append one more search and do one more calculate:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DATE=*
| rex field=_raw "DATE=\d+-(?&amp;lt;Month&amp;gt;(.*))-\d+ " 
| rex field=_raw "DATE=(?&amp;lt;Year&amp;gt;(.*))-\d+-\d+ "
| rex field=_raw "DATE=\d+-\d+-(?&amp;lt;Day&amp;gt;(.*)\s{1})ITEM1" 
| stats sum(ITEM1) as ITEM1  sum(ITEM2) as ITEM2 by Month, Year
 | 
  append [
 | stats sum(ITEM1) as ITEM1  sum(ITEM2) as ITEM2 by Month, Year, Day
 | eval Daytot = ( ITEM1 * ITEM2)   ]
| addcoltotals ITEM1, ITEM2, Daytot labelfield=Month label=Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But the above try doesn't take me anywhere.&lt;/P&gt;

&lt;P&gt;Any idea how to solve this?&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2019 16:42:42 GMT</pubDate>
    <dc:creator>mkrauss1</dc:creator>
    <dc:date>2019-10-17T16:42:42Z</dc:date>
    <item>
      <title>How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502854#M195224</link>
      <description>&lt;P&gt;I'm trying hard to achive the following,&lt;BR /&gt;
assume i have this data:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DATE=2020-01-01 ITEM1=1 ITEM2=10
DATE=2020-01-02 ITEM1=2 ITEM2=20
DATE=2020-01-03 ITEM1=3 ITEM2=30
....
DATE=2020-01-31 ITEM1=5 ITEM2=40
DATE=2020-02-01 ITEM1=1 ITEM2=10
DATE=2020-02-02 ITEM1=2 ITEM2=20
DATE=2020-02-03 ITEM1=3 ITEM2=20
...
DATE=2020-02-28 ITEM1=4 ITEM2=20
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I'd like to multiply ITEM1 with ITEM2 and show it in the field dailytot,&lt;BR /&gt;
the table query looks then:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DATE=*
| rex field=_raw "DATE=\d+-(?&amp;lt;Month&amp;gt;(.*))-\d+ " 
| rex field=_raw "DATE=(?&amp;lt;Year&amp;gt;(.*))-\d+-\d+ "
| rex field=_raw "DATE=\d+-\d+-(?&amp;lt;Day&amp;gt;(.*)\s{1})ITEM1" 
| stats sum(ITEM1) as ITEM1  sum(ITEM2) as ITEM2 by Month, Year, Day
| eval Daytot = ( ITEM1 * ITEM2)
| addcoltotals ITEM1, ITEM2, Daytot labelfield=Month label=Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The output looks like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Month        Year   Day ITEM1       ITEM2       Daytot
01          2020    01  1           10          10
01          2020    02  2           20          40
01          2020    03  3           30          90
01          2020    31  5           40          200
02          2020    01  1           10          10
02          2020    02  2           20          40
02          2020    03  3           20          60
02          2020    28  4           20          80
Total                     21           170         530
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All good so fare but i would like to get monthly totals like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Month    Year     ITEM1 ITEM2 Daytot
01    2020  11   100    340
02     2020     10   70  190
Total   2020    21   170    530
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I was thinking about to append one more search and do one more calculate:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DATE=*
| rex field=_raw "DATE=\d+-(?&amp;lt;Month&amp;gt;(.*))-\d+ " 
| rex field=_raw "DATE=(?&amp;lt;Year&amp;gt;(.*))-\d+-\d+ "
| rex field=_raw "DATE=\d+-\d+-(?&amp;lt;Day&amp;gt;(.*)\s{1})ITEM1" 
| stats sum(ITEM1) as ITEM1  sum(ITEM2) as ITEM2 by Month, Year
 | 
  append [
 | stats sum(ITEM1) as ITEM1  sum(ITEM2) as ITEM2 by Month, Year, Day
 | eval Daytot = ( ITEM1 * ITEM2)   ]
| addcoltotals ITEM1, ITEM2, Daytot labelfield=Month label=Total
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But the above try doesn't take me anywhere.&lt;/P&gt;

&lt;P&gt;Any idea how to solve this?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 16:42:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502854#M195224</guid>
      <dc:creator>mkrauss1</dc:creator>
      <dc:date>2019-10-17T16:42:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502855#M195225</link>
      <description>&lt;P&gt;like this?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval data="DATE=2020-01-01 ITEM1=1 ITEM2=10;;;DATE=2020-01-02 ITEM1=2 ITEM2=20;;;DATE=2020-01-03 ITEM1=3 ITEM2=30;;;DATE=2020-01-31 ITEM1=5 ITEM2=40;;;DATE=2020-02-01 ITEM1=1 ITEM2=10;;;DATE=2020-02-02 ITEM1=2 ITEM2=20;;;DATE=2020-02-03 ITEM1=3 ITEM2=20;;;DATE=2020-02-28 ITEM1=4 ITEM2=20"
| makemv delim=";;;" data 
| mvexpand data
| eval _raw = data
| extract kvdelim="=" pairdelim=" "
| table DATE ITEM1 ITEM2
| rex field=DATE "(?&amp;lt;Year&amp;gt;[^\-]+)\-(?&amp;lt;Month&amp;gt;[^\-]+)\-(?&amp;lt;Day&amp;gt;[^\-]+)"
| eval day_tot = (ITEM1 * ITEM2)
| stats sum(ITEM1) as ITEM1 sum(ITEM2) as ITEM2 sum(day_tot) as Daytot  by Month Year
| addtotals col=true ITEM1 ITEM2 Daytot 
| fields - Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 16:58:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502855#M195225</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-10-17T16:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502856#M195226</link>
      <description>&lt;P&gt;Thanks for the very interesting solution.&lt;BR /&gt;
The above records where just a sample and they can be many more.&lt;BR /&gt;
Would there be a way to feed the data var dynamically  and even if, isn't&lt;BR /&gt;
there a size limit?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 17:38:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502856#M195226</guid>
      <dc:creator>mkrauss1</dc:creator>
      <dc:date>2019-10-17T17:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502857#M195227</link>
      <description>&lt;P&gt;Ahh! And many thanks for the improved regex, that looks much better than my one .. &lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 17:45:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502857#M195227</guid>
      <dc:creator>mkrauss1</dc:creator>
      <dc:date>2019-10-17T17:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502858#M195228</link>
      <description>&lt;P&gt;it supposed to scale nicely ...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults count=1
| eval data="DATE=2020-01-01 ITEM1=1 ITEM2=10;;;DATE=2020-01-02 ITEM1=2 ITEM2=20;;;DATE=2020-01-03 ITEM1=3 ITEM2=30;;;DATE=2020-01-31 ITEM1=5 ITEM2=40;;;DATE=2020-02-01 ITEM1=1 ITEM2=10;;;DATE=2020-02-02 ITEM1=2 ITEM2=20;;;DATE=2020-02-03 ITEM1=3 ITEM2=20;;;DATE=2020-02-28 ITEM1=4 ITEM2=20;;;ATE=2020-01-01 ITEM1=1 ITEM2=10;;;DATE=2020-01-02 ITEM1=2 ITEM2=20;;;DATE=2020-01-03 ITEM1=3 ITEM2=30;;;DATE=2020-03-31 ITEM1=5 ITEM2=40;;;DATE=2022-02-01 ITEM1=1 ITEM2=10;;;DATE=2021-02-02 ITEM1=2 ITEM2=2;;;DATE=2021-02-03 ITEM1=3 ITEM2=20;;;DATE=2021-02-28 ITEM1=4 ITEM2=2"
| makemv delim=";;;" data 
| mvexpand data
| eval _raw = data
| extract kvdelim="=" pairdelim=" "
| table DATE ITEM1 ITEM2
| rex field=DATE "(?&amp;lt;Year&amp;gt;[^\-]+)\-(?&amp;lt;Month&amp;gt;[^\-]+)\-(?&amp;lt;Day&amp;gt;[^\-]+)"
| eval day_tot = (ITEM1 * ITEM2)
| stats sum(ITEM1) as ITEM1 sum(ITEM2) as ITEM2 sum(day_tot) as Daytot  by Month Year
| addtotals col=true ITEM1 ITEM2 Daytot 
| fields - Total
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Oct 2019 18:18:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502858#M195228</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-10-17T18:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502859#M195229</link>
      <description>&lt;P&gt;Yes i'm sure that this scales nicely.&lt;BR /&gt;
The problem is that i don't know what records i have in my splunk database.&lt;BR /&gt;
Can i feed the data variable out of my search itself instead of specifying each record?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 18:27:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502859#M195229</guid>
      <dc:creator>mkrauss1</dc:creator>
      <dc:date>2019-10-17T18:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502860#M195230</link>
      <description>&lt;P&gt;not sure what you mean exactly ...&lt;BR /&gt;
can you elaborate?&lt;BR /&gt;
also, if this is a new question, kindly mark this one as answered so others will know it worked for you, you are also welcome to upvote any valuable comments. and then open up a new question&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 18:36:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502860#M195230</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-10-17T18:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502861#M195231</link>
      <description>&lt;P&gt;Not sure if this is a new question but its relating to.&lt;/P&gt;

&lt;P&gt;The &lt;STRONG&gt;eval data&lt;/STRONG&gt; variable is static so each of the record must be entered.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval data="DATE=2020-01-01 ITEM1=1 ITEM2=10;;;DATE=2020-01-02 ITEM1=2 ITEM2=20;;;...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But how can i add my records out of my search instead of specifying them in &lt;STRONG&gt;eval data&lt;/STRONG&gt; in a manual way? Sorry for the complicated description or maybe i'm missing something fundamental.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 19:00:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502861#M195231</guid>
      <dc:creator>mkrauss1</dc:creator>
      <dc:date>2019-10-17T19:00:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502862#M195232</link>
      <description>&lt;P&gt;just search for your data ...&lt;BR /&gt;
the entire &lt;CODE&gt;| makeresults ....&lt;/CODE&gt; just creates fake data&lt;BR /&gt;
you should put your search string ion the search bar &lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 19:07:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502862#M195232</guid>
      <dc:creator>adonio</dc:creator>
      <dc:date>2019-10-17T19:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to multiply values within each daily record but group by month?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502863#M195233</link>
      <description>&lt;P&gt;Excellent!&lt;BR /&gt;
I was not aware about the makeresults function. &lt;BR /&gt;
Sorry for all the questions, still a splunk search rookie but promise to get better.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2019 19:20:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-multiply-values-within-each-daily-record-but-group-by/m-p/502863#M195233</guid>
      <dc:creator>mkrauss1</dc:creator>
      <dc:date>2019-10-17T19:20:21Z</dc:date>
    </item>
  </channel>
</rss>

