<?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 Cant generate proper table with percentage and BY clause together in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480009#M134545</link>
    <description>&lt;P&gt;Hi! First question and relative newbie, so bear with me! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
I created below query to show the number of missing server ID's per rack. But I can't get the &lt;CODE&gt;BY&lt;/CODE&gt; clause and percentage calculation to work in the same query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=servers
| eval serverId_present=if(isnotnull(serverId), "OK", "Missing server ID")
| stats count as totalServers, count(eval(serverId_present="Missing server ID")) as missingServers
| eval missingPercentage=round(100*missingServers/totalServers, 2) 
| chart sum(totalServers), sum(missingServers), sum(missingPercentage) by rack
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;No results found when using the &lt;CODE&gt;BY&lt;/CODE&gt; clause at the end of the chart pipe. But when I remove the &lt;CODE&gt;BY&lt;/CODE&gt; clause, it generates a table with only one row where the missingPercentage is correct.&lt;/P&gt;

&lt;P&gt;Resuslts without &lt;CODE&gt;BY&lt;/CODE&gt; clause:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sum(totalServers)   sum(missingServers) sum(missingPercentage)
854043  16326   1.91
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I created a second query to see if that worked instead, but no:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=servers
| eval serverId_present=if(isnotnull(serverId), "OK", "Missing server ID")
| chart count AS totalServers count(eval(serverId_present="Missing server ID")) AS missingServers count(eval(round(100*missingServers/totalServers,2))) AS missingPercentage by rack
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This query generates a table with rows for each rack where all the missingPercentage is just "0". Still a "0" if I remove the &lt;CODE&gt;BY&lt;/CODE&gt; clause. The &lt;CODE&gt;BY&lt;/CODE&gt; clause is working though and showing rows for each Instance.&lt;/P&gt;

&lt;P&gt;Resuslts with &lt;CODE&gt;BY&lt;/CODE&gt; clause:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Instance    totalOrders totalError  missingRate
Rack1 575555    2502    0
Rack2 278488    13824   0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Tried &lt;CODE&gt;stats&lt;/CODE&gt; command instead of &lt;CODE&gt;chart&lt;/CODE&gt; but no difference.&lt;/P&gt;</description>
    <pubDate>Thu, 27 Feb 2020 15:27:49 GMT</pubDate>
    <dc:creator>martinmasif</dc:creator>
    <dc:date>2020-02-27T15:27:49Z</dc:date>
    <item>
      <title>Cant generate proper table with percentage and BY clause together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480009#M134545</link>
      <description>&lt;P&gt;Hi! First question and relative newbie, so bear with me! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
I created below query to show the number of missing server ID's per rack. But I can't get the &lt;CODE&gt;BY&lt;/CODE&gt; clause and percentage calculation to work in the same query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=servers
| eval serverId_present=if(isnotnull(serverId), "OK", "Missing server ID")
| stats count as totalServers, count(eval(serverId_present="Missing server ID")) as missingServers
| eval missingPercentage=round(100*missingServers/totalServers, 2) 
| chart sum(totalServers), sum(missingServers), sum(missingPercentage) by rack
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;No results found when using the &lt;CODE&gt;BY&lt;/CODE&gt; clause at the end of the chart pipe. But when I remove the &lt;CODE&gt;BY&lt;/CODE&gt; clause, it generates a table with only one row where the missingPercentage is correct.&lt;/P&gt;

&lt;P&gt;Resuslts without &lt;CODE&gt;BY&lt;/CODE&gt; clause:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sum(totalServers)   sum(missingServers) sum(missingPercentage)
854043  16326   1.91
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So I created a second query to see if that worked instead, but no:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=servers
| eval serverId_present=if(isnotnull(serverId), "OK", "Missing server ID")
| chart count AS totalServers count(eval(serverId_present="Missing server ID")) AS missingServers count(eval(round(100*missingServers/totalServers,2))) AS missingPercentage by rack
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This query generates a table with rows for each rack where all the missingPercentage is just "0". Still a "0" if I remove the &lt;CODE&gt;BY&lt;/CODE&gt; clause. The &lt;CODE&gt;BY&lt;/CODE&gt; clause is working though and showing rows for each Instance.&lt;/P&gt;

&lt;P&gt;Resuslts with &lt;CODE&gt;BY&lt;/CODE&gt; clause:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Instance    totalOrders totalError  missingRate
Rack1 575555    2502    0
Rack2 278488    13824   0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Tried &lt;CODE&gt;stats&lt;/CODE&gt; command instead of &lt;CODE&gt;chart&lt;/CODE&gt; but no difference.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 15:27:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480009#M134545</guid>
      <dc:creator>martinmasif</dc:creator>
      <dc:date>2020-02-27T15:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Cant generate proper table with percentage and BY clause together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480010#M134546</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;index=servers
| eval serverId_present=if(isnotnull(serverId), "OK", "Missing server ID")
| stats count as totalServers, count(eval(serverId_present="Missing server ID")) as missingServers by rack
| eval missingPercentage=round(100*missingServers/totalServers, 2) 
| rename rack as Instance
| stats sum(totalServers) as totalOrders, sum(missingServers) as  totalError, sum(missingPercentage) as missingRate by Instance
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 27 Feb 2020 22:24:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480010#M134546</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-02-27T22:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: Cant generate proper table with percentage and BY clause together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480011#M134547</link>
      <description>&lt;P&gt;Didn't get that last &lt;CODE&gt;| as you want&lt;/CODE&gt;? And it's missing the &lt;CODE&gt;missingRate&lt;/CODE&gt; to get the percentage.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 11:26:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480011#M134547</guid>
      <dc:creator>martinmasif</dc:creator>
      <dc:date>2020-02-28T11:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: Cant generate proper table with percentage and BY clause together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480012#M134548</link>
      <description>&lt;P&gt;well, Should I make all your query?&lt;BR /&gt;
&lt;CODE&gt;Instance    totalOrders    totalError    missingRate&lt;/CODE&gt;&lt;BR /&gt;
where does these come from?&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 11:44:08 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480012#M134548</guid>
      <dc:creator>to4kawa</dc:creator>
      <dc:date>2020-02-28T11:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Cant generate proper table with percentage and BY clause together</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480013#M134549</link>
      <description>&lt;PRE&gt;&lt;CODE&gt; index=servers
 | eval serverId_NOT_present=if(isnotnull(serverId), 0, 1)
 | stats count as totalServers, sum(serverId_NOT_present) as missingServers by rack
 | eval missingPercentage=round(100*missingServers/totalServers, 2) 
 | stats sum(totalServers), sum(missingServers), sum(missingPercentage) by rack
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Feb 2020 12:03:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cant-generate-proper-table-with-percentage-and-BY-clause/m-p/480013#M134549</guid>
      <dc:creator>jpalacian</dc:creator>
      <dc:date>2020-02-28T12:03:05Z</dc:date>
    </item>
  </channel>
</rss>

