<?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 insert rows with eval calculated fields in a time series table? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211530#M61896</link>
    <description>&lt;P&gt;You don't need to order your data because the appendpipe with the stats function is already grouping by Date and will take this into account.&lt;/P&gt;

&lt;P&gt;If data Type is dynamic then you might be better off using a join query, but there's a limit in the number of rows it can process. There are other options I'm sure but I would need to think a bit more about it.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2016 15:35:36 GMT</pubDate>
    <dc:creator>javiergn</dc:creator>
    <dc:date>2016-02-23T15:35:36Z</dc:date>
    <item>
      <title>How to insert rows with eval calculated fields in a time series table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211526#M61892</link>
      <description>&lt;P&gt;I have a set of time series data that looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Date  Type  Data
==================
12  A    1
12  B    2
12  C    3
13  A    1
13  B    2
13  C    3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I need to insert, for example, 2 calculated fields based on a formula like &lt;CODE&gt;D = A + B - C&lt;/CODE&gt;, &lt;CODE&gt;E  = A + B + C&lt;/CODE&gt; and insert back the date. The results should look like the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Date  Type  Data
==================
12  A    1
12  B    2
12  C    3
12  D    1+2-3
12  E    1+2+3
13  A    4
13  B    5
13  C    6
13  D    4+5-6
12  E    4+5+6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is Splunk able to achieve this?&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 13:03:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211526#M61892</guid>
      <dc:creator>Stevelim</dc:creator>
      <dc:date>2016-02-23T13:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert rows with eval calculated fields in a time series table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211527#M61893</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have replicated your sample with a csv file and then wrote the following query that hopefully will answer your question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputcsv mycsv.csv
| appendpipe [stats list(Data) as Data by Date | eval Type = "D, E"]
| eval Type = split(Type, ",")
| mvexpand Type
| eval Data = case(
    match(Type,"D"), tonumber(mvindex(Data,0)) + tonumber(mvindex(Data,1)) - tonumber(mvindex(Data,2)),
    match(Type,"E"), tonumber(mvindex(Data,0)) + tonumber(mvindex(Data,1)) + tonumber(mvindex(Data,2)),
    1 == 1, Data
)
| sort Date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Let me know if that helps.&lt;BR /&gt;
There are probably other ways to do this I'm sure. I'm thinking about join, maybe eventstats, etc.&lt;/P&gt;

&lt;P&gt;Thanks,&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 13:48:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211527#M61893</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-23T13:48:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert rows with eval calculated fields in a time series table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211528#M61894</link>
      <description>&lt;P&gt;Thank you so much! This works well for me! &lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:09:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211528#M61894</guid>
      <dc:creator>Stevelim</dc:creator>
      <dc:date>2016-02-23T15:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert rows with eval calculated fields in a time series table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211529#M61895</link>
      <description>&lt;P&gt;Am I right to say that this command will only work if the data order is consistent? What if the order of the data? i.e. the data Type may be dynamic as more data types are added to the search.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:29:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211529#M61895</guid>
      <dc:creator>Stevelim</dc:creator>
      <dc:date>2016-02-23T15:29:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert rows with eval calculated fields in a time series table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211530#M61896</link>
      <description>&lt;P&gt;You don't need to order your data because the appendpipe with the stats function is already grouping by Date and will take this into account.&lt;/P&gt;

&lt;P&gt;If data Type is dynamic then you might be better off using a join query, but there's a limit in the number of rows it can process. There are other options I'm sure but I would need to think a bit more about it.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 15:35:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211530#M61896</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-23T15:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert rows with eval calculated fields in a time series table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211531#M61897</link>
      <description>&lt;P&gt;UPDATE: Fixed an issue on my query above.&lt;/P&gt;

&lt;P&gt;Instead of &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats values(Data)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;It should say:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;stats list(Data)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Otherwise you'll be in trouble in there are common values as values will only return 1 entry per unique value.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2016 17:00:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211531#M61897</guid>
      <dc:creator>javiergn</dc:creator>
      <dc:date>2016-02-23T17:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert rows with eval calculated fields in a time series table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211532#M61898</link>
      <description>&lt;P&gt;UPDATE: Fix for dynamic &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Base search | 

 | eval temp =  case(                        
 match(Type ,"A"), Data * -1,                   &amp;lt;== Suppose you want -A,-B,-C
 match(Type ,"B"), Data * -1, 
 match(Type ,"C"), Data * -1, 
 match(Type ,"D"), 0,                                   &amp;lt;= Remove unwanted data if any
 1==1, Data
 ) 

| appendpipe [stats sum(temp) as Data by Date | eval Type  = "Others"]  | eval Type  = split(Type , ",") &amp;lt;== sums up temp and put it back to the correct Keys

 | eval temp2 =  case(                        &amp;lt;== Repeat for another variable
 match(Type ,"A"), Data * 1,                    
 match(Type ,"B"), Data * 1, 
 match(Type ,"C"), Data * 1, 
 match(Type ,"D"), 0,                                  
 1==1, Data
 ) 

| appendpipe [stats sum(temp2) as Data by Date | eval Type  = "Others"]  | eval Type  = split(Type , ",") &amp;lt;== sums up temp and put it back to the correct Keys
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2016 03:48:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-insert-rows-with-eval-calculated-fields-in-a-time-series/m-p/211532#M61898</guid>
      <dc:creator>Stevelim</dc:creator>
      <dc:date>2016-02-24T03:48:32Z</dc:date>
    </item>
  </channel>
</rss>

