<?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 Finding difference and percentage from 2 events withe same fields but difference index in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415086#M119515</link>
    <description>&lt;P&gt;I have this query that returns this:&lt;/P&gt;

&lt;P&gt;Sample event in index=idx_A:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;year=2018 month=04 day=10 hour=09 event_count=100 zone=zone_A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sample event in index=idx_B:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;year=2018 month=04 day=10 hour=09 event_count=110 zone=zone_B
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=idx_A OR index=idx_B | eval DateHour=year."-".month."-".day."-".hour  | chart values(event_count) over DateHour by zone
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The resulting output&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DateHour      | zone_A | zone_b
2018-04-10-09     100      110
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to create another column called difference and percentage that would look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DateHour      | zone_A | zone_b | difference | percentage
2018-04-10-09     100      110      10            10%    
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The difference column would be the absolute value of event_count from zone_A and zone_B and percentage would be &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;difference / {event_count with zone=zone_A} * 100
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 19:40:09 GMT</pubDate>
    <dc:creator>liondancer</dc:creator>
    <dc:date>2020-09-29T19:40:09Z</dc:date>
    <item>
      <title>Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415086#M119515</link>
      <description>&lt;P&gt;I have this query that returns this:&lt;/P&gt;

&lt;P&gt;Sample event in index=idx_A:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;year=2018 month=04 day=10 hour=09 event_count=100 zone=zone_A
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Sample event in index=idx_B:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;year=2018 month=04 day=10 hour=09 event_count=110 zone=zone_B
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Query:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=idx_A OR index=idx_B | eval DateHour=year."-".month."-".day."-".hour  | chart values(event_count) over DateHour by zone
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The resulting output&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DateHour      | zone_A | zone_b
2018-04-10-09     100      110
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I want to create another column called difference and percentage that would look something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;DateHour      | zone_A | zone_b | difference | percentage
2018-04-10-09     100      110      10            10%    
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The difference column would be the absolute value of event_count from zone_A and zone_B and percentage would be &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;difference / {event_count with zone=zone_A} * 100
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:40:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415086#M119515</guid>
      <dc:creator>liondancer</dc:creator>
      <dc:date>2020-09-29T19:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415087#M119516</link>
      <description>&lt;P&gt;Try to append this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval difference=abs(zone_A - zone_B)
| eval percentage=round(difference/zone_B*100), 2)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Make sure you actually want &lt;CODE&gt;abs()&lt;/CODE&gt; (this will always return a positive value), and which zone you want to base your percentage on.&lt;/P&gt;

&lt;P&gt;Hope that helps - if it does I'd be happy if you would upvote/accept this answer, so others could profit from it. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 19:14:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415087#M119516</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-05-22T19:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415088#M119517</link>
      <description>&lt;P&gt;My query is &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=idx_A OR index=idx_B | eval DateHour=year."-".month."-".day."-".hour  | chart values(event_count) over DateHour by zone
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval difference=abs(zone_A - zone_B)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;evaluate the difference between event_count of zone_A and event_count of zone_B? &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:40:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415088#M119517</guid>
      <dc:creator>liondancer</dc:creator>
      <dc:date>2020-09-29T19:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415089#M119518</link>
      <description>&lt;P&gt;Yes, and it will make it a positive value, so if:&lt;BR /&gt;
* zone_A is 50&lt;BR /&gt;
* zone_B is 60&lt;BR /&gt;
It will return 10, not -10. If you don't want this, just make it &lt;CODE&gt;eval difference=zone_A - zone_B&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:36:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415089#M119518</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2020-09-29T19:36:35Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415090#M119519</link>
      <description>&lt;P&gt;zone_A and zone_B is NOT a number. event_count IS the number of interest. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;year=2018 month=04 day=10 hour=09 event_count=100 zone=zone_A
year=2018 month=04 day=10 hour=09 event_count=110 zone=zone_B
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I distinguish the event_count from the event with zone_A with the event_count with zone_B&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:40:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415090#M119519</guid>
      <dc:creator>liondancer</dc:creator>
      <dc:date>2020-09-29T19:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415091#M119520</link>
      <description>&lt;P&gt;Ah, sorry, I overlooked that. Do you only have one event per hour and zone?&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 19:50:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415091#M119520</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-05-22T19:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415092#M119521</link>
      <description>&lt;P&gt;Good question! I might have more than 1 event per hour for the SAME ZONE. For that case, I would like to sum up all the event_count values for that HOUR&lt;/P&gt;

&lt;P&gt;ex:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; year=2018 month=04 day=10 hour=09 event_count=110 zone=zone_B
 year=2018 month=04 day=10 hour=09 event_count=50 zone=zone_B
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I would like to have event_count 160 because these two events are in the same HOUR and same ZONE&lt;/P&gt;

&lt;P&gt;For the sample HOUR, I should have 1 event PER zone:&lt;/P&gt;

&lt;P&gt;For example:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; year=2018 month=04 day=10 hour=09 event_count=10 zone=zone_A
 year=2018 month=04 day=10 hour=09 event_count=30 zone=zone_B
 year=2018 month=04 day=10 hour=10 event_count=50 zone=zone_A
 year=2018 month=04 day=10 hour=10 event_count=20 zone=zone_B
 year=2018 month=04 day=10 hour=11 event_count=70 zone=zone_A
 year=2018 month=04 day=10 hour=11 event_count=80 zone=zone_B
...
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 May 2018 20:01:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415092#M119521</guid>
      <dc:creator>liondancer</dc:creator>
      <dc:date>2018-05-22T20:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415093#M119522</link>
      <description>&lt;P&gt;I'd try this:&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;| chart   sum(event_count) over DateHour by zone&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 20:05:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415093#M119522</guid>
      <dc:creator>xpac</dc:creator>
      <dc:date>2018-05-22T20:05:08Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415094#M119523</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/117185"&gt;@liondancer&lt;/a&gt;, your query with chart ... &lt;CODE&gt;over DateHour by zone&lt;/CODE&gt;, gets the event_count for each zone for every date_hour. Based on your sample data, I expect that for each hour you will have only one event for each zone with the total event_count. Even if you had more than one event, you should use &lt;CODE&gt;sum(event_count)&lt;/CODE&gt; to get the total events for specific DateHour.&lt;/P&gt;

&lt;P&gt;Following is a run anywhere search based on sample data provided. Query from &lt;CODE&gt;makeresults&lt;/CODE&gt; till &lt;CODE&gt;| KV&lt;/CODE&gt; generate the dummy data as per the question:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval _raw="year=2018 month=04 day=10 hour=09 event_count=100 zone=zone_A" 
| append 
    [| makeresults 
    | eval _raw="year=2018 month=04 day=10 hour=09 event_count=110 zone=zone_B"] 
| KV 
| eval DateHour=year."-".month."-".day."-".hour 
| chart sum(event_count) over DateHour by zone 
| fillnull value=0 zone_A,zone_B
| eval percent= round((abs(zone_A-zone_B)/zone_B)*100,2)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:36:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415094#M119523</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T19:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415095#M119524</link>
      <description>&lt;P&gt;Up voting as I just noticed you beat me to it!&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 20:21:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415095#M119524</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2018-05-22T20:21:13Z</dc:date>
    </item>
    <item>
      <title>Re: Finding difference and percentage from 2 events withe same fields but difference index</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415096#M119525</link>
      <description>&lt;P&gt;The chart command create fields with name zone_B and zone_B which'll have event_count as their value. This enables you to apply mathematical operations using zone names. You'll see it better if you just run the search and see the output after the chart command.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 19:36:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Finding-difference-and-percentage-from-2-events-withe-same/m-p/415096#M119525</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-29T19:36:48Z</dc:date>
    </item>
  </channel>
</rss>

