<?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 edit my eval statement to extract values for the current day to find the percentage difference between dates? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202045#M187576</link>
    <description>&lt;P&gt;I reazlized the problems is that after running the Chart command, I couldnt see anymore fields so I worked backwards to extract eachfield I needed.  The problem is I can't seem to use or add these fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=csl_dblogs | rename TRUNC_CREATION_TIME as Date | rename SOURCE_SYSTEM_NAME as Source_System | eval Date=strftime('Date', "%m-%d-%Y") | eval t2=relative_time(now(), "-2d@d" ) | eval t2=strftime('t2', "%m-%d-%Y") | eval today_count=if(Date&amp;gt;=t2, COUNT, 0) | eventstats avg(COUNT) as Average sum(COUNT) as Sum by Source_System | eval ten_Day_Avg=round(Sum/10) | eval Diff=((ten_Day_Avg-today_count)/ten_Day_Avg)*100 | chart values(COUNT) as Vals over Source_System by Date 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So how can I add additionals Column fields afer using a Chart or Stats command? &lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2015 21:27:21 GMT</pubDate>
    <dc:creator>pmcfadden91</dc:creator>
    <dc:date>2015-10-29T21:27:21Z</dc:date>
    <item>
      <title>How to edit my eval statement to extract values for the current day to find the percentage difference between dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202044#M187575</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I posted this question before, but was unable to attach the picture later in the thread. I am looking to add a column that gives me the % Difference. The formula is this: &lt;CODE&gt;((5_Day_Avg - currentDay) /5_Day_Avg) *100&lt;/CODE&gt;.  &lt;/P&gt;

&lt;P&gt;My search looks like this:&lt;BR /&gt;
&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/764i000F7D38F3B15844/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=csl_dblogs   | rename TRUNC_CREATION_TIME as Date2  | rename SOURCE_SYSTEM_NAME as Source_System | Rename COUNT as Count  | eval Date=strftime('Date', "%m-%d-%Y")  | chart  values(COUNT) over Source_System by Date  | addtotals  fieldname=Total  | eval   5_Day_Avg=round(Total/5) |  eval  currentDay=if(Date&amp;gt;now(), 0, Count)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Based on the picture, I would need just 1 column that represents the difference based on the formula provided. However, I am having a problem extracting the values of the current day's field.  Right now, it shows 10/27/2015 as the current day, but the DB will index 10/28 files later today (which will be Current Day). I know I need an if statement, but i tried with  the one above and it doesn't exactly work.  Any help is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2015 14:25:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202044#M187575</guid>
      <dc:creator>pmcfadden91</dc:creator>
      <dc:date>2015-10-28T14:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statement to extract values for the current day to find the percentage difference between dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202045#M187576</link>
      <description>&lt;P&gt;I reazlized the problems is that after running the Chart command, I couldnt see anymore fields so I worked backwards to extract eachfield I needed.  The problem is I can't seem to use or add these fields.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=csl_dblogs | rename TRUNC_CREATION_TIME as Date | rename SOURCE_SYSTEM_NAME as Source_System | eval Date=strftime('Date', "%m-%d-%Y") | eval t2=relative_time(now(), "-2d@d" ) | eval t2=strftime('t2', "%m-%d-%Y") | eval today_count=if(Date&amp;gt;=t2, COUNT, 0) | eventstats avg(COUNT) as Average sum(COUNT) as Sum by Source_System | eval ten_Day_Avg=round(Sum/10) | eval Diff=((ten_Day_Avg-today_count)/ten_Day_Avg)*100 | chart values(COUNT) as Vals over Source_System by Date 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So how can I add additionals Column fields afer using a Chart or Stats command? &lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 21:27:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202045#M187576</guid>
      <dc:creator>pmcfadden91</dc:creator>
      <dc:date>2015-10-29T21:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statement to extract values for the current day to find the percentage difference between dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202046#M187577</link>
      <description>&lt;P&gt;Adding fields after stats or charting can look like this:&lt;/P&gt;

&lt;P&gt;base search | evals for new_field | chart chart values(COUNT) as Vals over Source_System by Date | table Date, Source_System, Values, new_field.&lt;/P&gt;

&lt;P&gt;It takes the new field names from chart, and any other still valid field, and lays them out in a table, all pretty and such.&lt;/P&gt;

&lt;P&gt;But why not include the field in the original chart step?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:46:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202046#M187577</guid>
      <dc:creator>ltrand</dc:creator>
      <dc:date>2020-09-29T07:46:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statement to extract values for the current day to find the percentage difference between dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202047#M187578</link>
      <description>&lt;P&gt;I think that using the &lt;CODE&gt;chart&lt;/CODE&gt; command has made it difficult to do what you want. If you aren't required to show all the individual days of data, you can try this:&lt;/P&gt;

&lt;P&gt;index=csl_dblogs&lt;BR /&gt;
| rename TRUNC_CREATION_TIME as Date&lt;BR /&gt;
| rename SOURCE_SYSTEM_NAME as Source_System&lt;BR /&gt;
| eval Date=strftime(Date, "%m-%d-%Y") &lt;BR /&gt;
| stats  count as Count  by Source_System Date&lt;BR /&gt;
| eval TodayCount=if(Date=strftime(now(), "%m-%d-%Y"),Count,0)&lt;BR /&gt;
| stats sum(TodayCount) as TodayCount avg(Count) as AvgCount sum(Count) as Total by Source_System&lt;BR /&gt;
| eval Difference = round(((AvgCount - TodayCount) /AvgCount) *100,2)&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:44:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202047#M187578</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2020-09-29T07:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statement to extract values for the current day to find the percentage difference between dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202048#M187579</link>
      <description>&lt;P&gt;I am required to show the days in that format unfortunately.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 22:47:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202048#M187579</guid>
      <dc:creator>pmcfadden91</dc:creator>
      <dc:date>2015-10-29T22:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my eval statement to extract values for the current day to find the percentage difference between dates?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202049#M187580</link>
      <description>&lt;P&gt;If you ARE required to show all the individual days of data, you can try this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=csl_dblogs
| rename TRUNC_CREATION_TIME as Date
| rename SOURCE_SYSTEM_NAME as Source_System
| eval Date=strftime(Date, "%m-%d-%Y") 
| stats count as Count by Source_System Date
| eval Today=strftime(now(), "%m-%d-%Y")
| eval TodayCount=if(Date=Today,Count,0)
| eventstats sum(TodayCount) as TodayCount avg(Count) as AvgCount sum(Count) as Total list(Date) as Dates list(Count) as "Daily Count" by Source_System
| eval AvgCount=round(AvgCount,2)
| eval Difference = round(((AvgCount - TodayCount) /AvgCount)*100,2)
| where Date=Today
| table Source_System Dates "Daily Count" Total AvgCount Today TodayCount Difference
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Oct 2015 00:18:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-eval-statement-to-extract-values-for-the-current/m-p/202049#M187580</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2015-10-30T00:18:20Z</dc:date>
    </item>
  </channel>
</rss>

