<?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: Using Eval for calculated Metrics in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143399#M39824</link>
    <description>&lt;P&gt;Are you sure it doesn't work?  I actually tested it against faux data and it worked exactly as you described.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jun 2015 17:34:06 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-06-09T17:34:06Z</dc:date>
    <item>
      <title>Using Eval for calculated Metrics</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143396#M39821</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;I have the following search which returns the number of users logging onto a system for the previous month and groups them by a range of Days. The search is only for users onboarded before the start of the previous month.&lt;/P&gt;

&lt;P&gt;The append search gives me the total number of users that have ever logged onto the system, prior to that month.&lt;/P&gt;

&lt;P&gt;All searches are run off a summary index which is populated daily with | bucket span=1d _time |&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dbuserday earliest=-1mon@mon latest=@mon cs_username="EXT*" NOT [| inputlookup testers_lookup | fields cs_username] 
| lookup EXTdata cs_username OUTPUTNEW OnboardedDate 
| eval Onboarded=strptime(OnboardedDate,"%d/%m/%Y")  
| eval BegMonth=relative_time(now(), "-1mon@mon")  
| WHERE BegMonth&amp;gt;Onboarded  
| stats dc(_time) AS Days by cs_username
| eval Days=case(Days=1,"1",Days&amp;gt;=2 AND Days&amp;lt;=11,"2-11",Days&amp;gt;11,"12+")
| append [search index=dbuserday earliest=-32mon@mon latest=-1mon@mon cs_username=EXT* NOT [| inputlookup testers_lookup  | fields cs_username] | Eval Days="ALL" | dedup cs_username | table cs_username Days ]
| stats dc(cs_username) as Users by Days
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This give me the results...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Days      Users
1          1302
2-11      13543
12+       32075 
ALL       51024
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I use Eval to subtract the values in Days "1", "2-11", "12+" from "All" to return a Days ="0" Users=4014?&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    Days      Users
    0          4014
    1          1302
    2-11      13543
    12+       32075 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Hope you can help,&lt;/P&gt;

&lt;P&gt;Thanks,&lt;/P&gt;

&lt;P&gt;Dan&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2015 09:54:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143396#M39821</guid>
      <dc:creator>DanielFordWA</dc:creator>
      <dc:date>2015-06-05T09:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using Eval for calculated Metrics</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143397#M39822</link>
      <description>&lt;P&gt;It is whacky, but this will do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=dbuserday earliest=-1mon@mon latest=@mon cs_username="EXT*"
NOT [| inputlookup testers_lookup | fields cs_username] 
| lookup EXTdata cs_username OUTPUTNEW OnboardedDate 
| eval Onboarded=strptime(OnboardedDate,"%d/%m/%Y")  
| eval BegMonth=relative_time(now(), "-1mon@mon")  
| WHERE BegMonth&amp;gt;Onboarded  
| stats dc(_time) AS Days by cs_username
| eval Days=case(Days=1,"1",Days&amp;gt;=2 AND Days&amp;lt;=11,"2-11",Days&amp;gt;11,"12+")
| append [search index=dbuserday earliest=-32mon@mon latest=-1mon@mon cs_username=EXT*
NOT [| inputlookup testers_lookup
| fields cs_username] | Eval Days="ALL" | dedup cs_username | table cs_username Days ]
| stats dc(cs_username) as Users by Days
| transpose | eval "row 5" = $row 5$ - $row 4$ - $row 3$ - $row 2$ | eval "row 5" = coalesce($row 5$, 0)
| transpose | where column!="column" | fields row* | rename "row 1" AS Days | rename "row 2" AS Users
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Jun 2015 13:40:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143397#M39822</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-06-05T13:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using Eval for calculated Metrics</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143398#M39823</link>
      <description>&lt;P&gt;Thanks for the reply. &lt;/P&gt;

&lt;P&gt;I get the following results, but you have given me some ideas.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;0          0
1          1302
2-11      13543
12+       32075
ALL       51024
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Jun 2015 10:05:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143398#M39823</guid>
      <dc:creator>DanielFordWA</dc:creator>
      <dc:date>2015-06-09T10:05:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using Eval for calculated Metrics</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143399#M39824</link>
      <description>&lt;P&gt;Are you sure it doesn't work?  I actually tested it against faux data and it worked exactly as you described.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2015 17:34:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143399#M39824</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-06-09T17:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Using Eval for calculated Metrics</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143400#M39825</link>
      <description>&lt;P&gt;This may be my mistake, I'll try again. Thanks for checking against dummy data.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jun 2015 07:47:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Using-Eval-for-calculated-Metrics/m-p/143400#M39825</guid>
      <dc:creator>DanielFordWA</dc:creator>
      <dc:date>2015-06-10T07:47:22Z</dc:date>
    </item>
  </channel>
</rss>

