<?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: Urgent !! Complex case statements in eval in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130005#M35368</link>
    <description>&lt;P&gt;Forget the pivot.  Assuming the field names in your sample data are correct and assuming that you are timestamping based on your &lt;CODE&gt;Time&lt;/CODE&gt; field, this should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | sort 0 + _time | streamstats usecurrent=f last(Usage) AS PrevUsage by User | eval UsageThisHour=usage - coalesce(PrevUsage,0) | stats sum(UsageThisHour) by Time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 May 2015 19:41:45 GMT</pubDate>
    <dc:creator>woodcock</dc:creator>
    <dc:date>2015-05-28T19:41:45Z</dc:date>
    <item>
      <title>Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/129999#M35362</link>
      <description>&lt;P&gt;I have a field that captures the usage of every user. I want to write a case to get the usage of each user in that hour, which is the max(usage). But since this value is cumulative. I want to subtract the value of the previous hour. Foe example: In the timechart, for 2:00 the value will be sum( max(usage) by each user at 2:00) - sum(max(usage) by user at 1:00 ). This has to be dynamic, since this is a timechart it has to apply the same logic to each hour. &lt;BR /&gt;
Plz help. &lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 15:52:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/129999#M35362</guid>
      <dc:creator>sushmitha_mj</dc:creator>
      <dc:date>2015-05-28T15:52:00Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130000#M35363</link>
      <description>&lt;P&gt;can you provide 1 sample event?&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 16:15:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130000#M35363</guid>
      <dc:creator>aalanisr26</dc:creator>
      <dc:date>2015-05-28T16:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130001#M35364</link>
      <description>&lt;P&gt;@aalanisr26 &lt;/P&gt;

&lt;P&gt;Example: &lt;BR /&gt;
User----  Usage---   Time---------- Status &lt;BR /&gt;
A-----------10-----------1:00PM----- Start&lt;BR /&gt;
A-----------15----------2:00 PM------In progress&lt;BR /&gt;
A-----------25----------3:00 PM------In progress&lt;BR /&gt;
A-----------30----------4:00 PM------Stop&lt;BR /&gt;
B-----------15----------2:00 PM-------Start&lt;BR /&gt;
B------------20----------3:00 PM-------In Progress&lt;BR /&gt;
B------------25----------4:00 PM--------Stop&lt;/P&gt;

&lt;P&gt;The usage for each hour is cumulative for each user. &lt;/P&gt;

&lt;P&gt;So what I need is: &lt;BR /&gt;
Hour ------Usage &lt;BR /&gt;
1:00 ------10 (user A-10)&lt;BR /&gt;
2:00------20 ( User A-5 + User B 15) &lt;BR /&gt;
3:00----- 15 (User A- 10 + user B 5)&lt;BR /&gt;
4:00----- 10 (User A-5 + user B-5)&lt;/P&gt;

&lt;P&gt;Does that help you understand better? &lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 16:46:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130001#M35364</guid>
      <dc:creator>sushmitha_mj</dc:creator>
      <dc:date>2015-05-28T16:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130002#M35365</link>
      <description>&lt;P&gt;I believe that you need the &lt;CODE&gt;streamstats&lt;/CODE&gt; command; read about it and reclarify your needs if this won't work (or you are not sure how to make it work):&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&lt;A href="http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats" target="test_blank"&gt;http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/streamstats&lt;/A&gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2015 17:01:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130002#M35365</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-28T17:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130003#M35366</link>
      <description>&lt;P&gt;@woodcook &lt;BR /&gt;
I tried it, But I am unable to make it work. Could you give me an example of how to make this work? &lt;/P&gt;

&lt;P&gt;If this is my query: &lt;BR /&gt;
| pivotAccounting Accounting sum(Input) AS "Input" SPLITROW _time AS _time PERIOD hour LIMIT User_Name BY TOP 1 sum(Input) | eval usage=round(Input/1000,2)&lt;/P&gt;

&lt;P&gt;Note: In this query "User_Name BY TOP 1 sum(Input) "  is wrong. I want to actually get the max(sum(Input)) by user for this hour and subtract it from max(sum(Input)) for user of previous and finally add all this value to get overall usage. I do not know how to. &lt;BR /&gt;
Plz..... help....&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:05:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130003#M35366</guid>
      <dc:creator>sushmitha_mj</dc:creator>
      <dc:date>2020-09-28T20:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130004#M35367</link>
      <description>&lt;P&gt;Ok assuming the following dataset:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;05/28/2015 1:00PM User=A Usage=10 Status=Start
05/28/2015 2:00PM User=A Usage=15 Status=In progress
05/28/2015 3:00PM User=A Usage=25 Status=In progress
05/28/2015 4:00PM User=A Usage=30 Status=Stop
05/28/2015 2:00PM User=B Usage=15 Status=Start
05/28/2015 3:00PM User=B Usage=20 Status=In Progress
05/28/2015 4:00PM User=B Usage=25 Status=Stop
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;try the following query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source="sample.log"  sourcetype="sample" |stats sum(Usage) as Usage1 by _time |streamstats max(Usage1) as Usage2 current=f |eval TotalUsage=Usage1-coalesce(Usage2,0)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2015 19:10:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130004#M35367</guid>
      <dc:creator>aalanisr26</dc:creator>
      <dc:date>2015-05-28T19:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130005#M35368</link>
      <description>&lt;P&gt;Forget the pivot.  Assuming the field names in your sample data are correct and assuming that you are timestamping based on your &lt;CODE&gt;Time&lt;/CODE&gt; field, this should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | sort 0 + _time | streamstats usecurrent=f last(Usage) AS PrevUsage by User | eval UsageThisHour=usage - coalesce(PrevUsage,0) | stats sum(UsageThisHour) by Time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 May 2015 19:41:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130005#M35368</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-28T19:41:45Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130006#M35369</link>
      <description>&lt;P&gt;I do not think you meant &lt;CODE&gt;max(Usage1)&lt;/CODE&gt;, did you?&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 19:54:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130006#M35369</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-28T19:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130007#M35370</link>
      <description>&lt;P&gt;yes I did, load the data and run the query &lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 20:01:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130007#M35370</guid>
      <dc:creator>aalanisr26</dc:creator>
      <dc:date>2015-05-28T20:01:07Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130008#M35371</link>
      <description>&lt;P&gt;Let's say that in the 6pm hour user A started using again, would her usage start again at 0, or would it start at 30?&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 20:02:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130008#M35371</guid>
      <dc:creator>acharlieh</dc:creator>
      <dc:date>2015-05-28T20:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130009#M35372</link>
      <description>&lt;P&gt;@aalanisr26 &lt;BR /&gt;
First of all Thank you so much... This seems to kind of works. But 2 issues. &lt;/P&gt;

&lt;OL&gt;
&lt;LI&gt;We are not grouping this by user so it sums all usage as usage 1 and 2nd max of this as usage 2. I tried adding user in the "by" section along with _time. For some reason did not work. &lt;/LI&gt;
&lt;LI&gt;A new problem is that some users have a couple of start, in progress and stop sessions within the frame so this logic does not work.&lt;BR /&gt;
For example &lt;/LI&gt;
&lt;/OL&gt;

&lt;P&gt;05/28/2015 1:00PM User=A Usage=10 Status=Start&lt;BR /&gt;
 05/28/2015 2:00PM User=A Usage=15 Status=In progress&lt;BR /&gt;
 05/28/2015 3:00PM User=A Usage=25 Status=In progress&lt;BR /&gt;
 05/28/2015 4:00PM User=A Usage=30 Status=Stop&lt;BR /&gt;
 05/28/2015 2:00PM User=B Usage=15 Status=Start&lt;BR /&gt;
 &lt;STRONG&gt;05/28/2015 3:01PM User=B Usage=20 Status=In Progress&lt;BR /&gt;
 05/28/2015 3:05PM User=B Usage=25 Status=In Progress&lt;BR /&gt;
 05/28/2015 3:20PM User=B Usage=30 Status=Stop&lt;BR /&gt;
 05/28/2015 3:25PM User=B Usage=10 Status=Start&lt;BR /&gt;
 05/28/2015 3:30PM User=B Usage=15 Status=In Progress&lt;/STRONG&gt;&lt;BR /&gt;
 05/28/2015 4:00PM User=B Usage=25 Status=Stop&lt;/P&gt;

&lt;P&gt;So in this case, For the 3:00 PM time range: it has to take the usage of B to be stop value 30 + latest "In progress" value 15 &lt;/P&gt;

&lt;P&gt;Could you plz help? &lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 20:17:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130009#M35372</guid>
      <dc:creator>sushmitha_mj</dc:creator>
      <dc:date>2015-05-28T20:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130010#M35373</link>
      <description>&lt;P&gt;Did you try my solution (different from @aalanisr26)?&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 20:41:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130010#M35373</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-05-28T20:41:39Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130011#M35374</link>
      <description>&lt;P&gt;so you can't just&lt;/P&gt;

&lt;P&gt;| bin _time span=1h&lt;BR /&gt;
| stats max(Usage) as maxUser by _time User&lt;BR /&gt;
| stats sum(maxUser) by _time&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2015 20:47:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130011#M35374</guid>
      <dc:creator>tincupchalice</dc:creator>
      <dc:date>2015-05-28T20:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Urgent !! Complex case statements in eval</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130012#M35375</link>
      <description>&lt;P&gt;Thanks everyone. Finally this is the query I used&lt;/P&gt;

&lt;P&gt;bucket _time span=1h | stats first(Record) as Current, max(Input) as inp by  _time, User_Name | streamstats max(inp) as Usage2 by User_Name current=f  | eval delta=if(isnull(Usage2),0,Usage2 ) | eval usage=round((inp-delta)/1073741824,2)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 20:06:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Urgent-Complex-case-statements-in-eval/m-p/130012#M35375</guid>
      <dc:creator>sushmitha_mj</dc:creator>
      <dc:date>2020-09-28T20:06:21Z</dc:date>
    </item>
  </channel>
</rss>

