<?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: calculating ratio of fields, grouping and plotting over time - cannot handle 'no results' searches in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321976#M160912</link>
    <description>&lt;P&gt;I think i was just overcomplicating it. &lt;BR /&gt;
Using fillnull value=100 instead of fillnull value=0 would ensure all null/null RATIO are reported at 100.&lt;/P&gt;

&lt;P&gt;Really appreciate your help. Thanks.&lt;/P&gt;</description>
    <pubDate>Tue, 30 May 2017 20:02:15 GMT</pubDate>
    <dc:creator>sirsyedian</dc:creator>
    <dc:date>2017-05-30T20:02:15Z</dc:date>
    <item>
      <title>calculating ratio of fields, grouping and plotting over time - cannot handle 'no results' searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321972#M160908</link>
      <description>&lt;P&gt;Hi All,&lt;BR /&gt;
We are using splunk to periodically index (every 5 mins) some CSV files containing the following type of data.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Time, Trunk, Event_Code, Total&lt;/STRONG&gt;&lt;BR /&gt;
timestamp, Trunk1, 0, 2&lt;BR /&gt;
timestamp,Trunk2,100, 30&lt;BR /&gt;
timestamp,Trunk3, 0, 3&lt;BR /&gt;
timestamp,Trunk1, 1, 3&lt;BR /&gt;
timestamp,Trunk2, 0, 4&lt;BR /&gt;
timestamp,Trunk3, 50, 5&lt;/P&gt;

&lt;P&gt;I want to calculate the following Ratio using this data and plot it over time for each Trunk.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;For each Trunk and within each 5 min time bucket:&lt;/STRONG&gt;&lt;BR /&gt;
RATIO = [Sum (Total) for events with EventCode of zero] / [Sum(Total) for all events for that trunk]&lt;/P&gt;

&lt;P&gt;I have tried search like following&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;sourcetype=test-csv |bucket span=5mins _time | stats sum(Total) as Total_Events by _time, Trunk| appendcols [search sourcetype=test-csv Event_Code=0| bucket span=5mins _time | stats sum(Total) as Total_EC0 by _time,Trunk] |eval RATIO = Total_EC0/Total_Events*100 | timechart span=5m values(RATIO) by Trunk&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;It works fine as long as there are some Events with Event_Code of zero for each trunk, However, i get into issues when there are NO events with Eventcode=0 within a 5min timebucket (for any trunk). This results in the subsearch to give 'no result' and hense i dont get any results.&lt;/P&gt;

&lt;UL&gt;
&lt;LI&gt;Is there a way to force Total_EC0 to have ZERO value for each time bucket and for each Trunk?&lt;/LI&gt;
&lt;LI&gt;Am i following the right approach or is there a simpler way of accomplishing this task.?&lt;/LI&gt;
&lt;/UL&gt;

&lt;P&gt;I am new to splunk search and any suggestions would be really appreciated.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:16:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321972#M160908</guid>
      <dc:creator>sirsyedian</dc:creator>
      <dc:date>2020-09-29T14:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: calculating ratio of fields, grouping and plotting over time - cannot handle 'no results' searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321973#M160909</link>
      <description>&lt;P&gt;since you're using the same sourcetype, you could probably avoid using appendcols. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype=test-csv |bucket span=5mins _time |eval Total_EC0=if(Event_Code=0,Total,0)| stats sum(Total) as Total_Events sum(Total_EC0) as Total_EC0 by _time, Trunk|eval RATIO = Total_EC0/Total_Events*100 | timechart span=5m values(RATIO) by Trunk
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;see where that gets you. you could also add in a &lt;CODE&gt;|makecontinuous|fillnull value=0&lt;/CODE&gt; in there to see if that helps&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 16:14:09 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321973#M160909</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-05-30T16:14:09Z</dc:date>
    </item>
    <item>
      <title>Re: calculating ratio of fields, grouping and plotting over time - cannot handle 'no results' searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321974#M160910</link>
      <description>&lt;P&gt;Thanks a lot cmerriman, A combination of both (updated search query, and |makecontinuous|fillnull value=0) did the trick. I can now see zero values and the timechart looks nice and continuous &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;For scenarios where I now get RATIO = 0/0 (ie where both Total_Events and Total_ECO are zero/null), I would like to update/show the RATIO to be equal to 100. Any idea how to accomplish it within the same query?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 14:16:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321974#M160910</guid>
      <dc:creator>sirsyedian</dc:creator>
      <dc:date>2020-09-29T14:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: calculating ratio of fields, grouping and plotting over time - cannot handle 'no results' searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321975#M160911</link>
      <description>&lt;P&gt;you could change your eval to &lt;CODE&gt;|eval RATIO = if(Total_EC0=0 OR Total_Events=0,100,Total_EC0/Total_Events*100)&lt;/CODE&gt;&lt;BR /&gt;
and see if that works.&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 19:32:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321975#M160911</guid>
      <dc:creator>cmerriman</dc:creator>
      <dc:date>2017-05-30T19:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: calculating ratio of fields, grouping and plotting over time - cannot handle 'no results' searches</title>
      <link>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321976#M160912</link>
      <description>&lt;P&gt;I think i was just overcomplicating it. &lt;BR /&gt;
Using fillnull value=100 instead of fillnull value=0 would ensure all null/null RATIO are reported at 100.&lt;/P&gt;

&lt;P&gt;Really appreciate your help. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2017 20:02:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/calculating-ratio-of-fields-grouping-and-plotting-over-time/m-p/321976#M160912</guid>
      <dc:creator>sirsyedian</dc:creator>
      <dc:date>2017-05-30T20:02:15Z</dc:date>
    </item>
  </channel>
</rss>

