<?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 How to frame a table from stats data? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614706#M213635</link>
    <description>&lt;P&gt;I want to create a Bar chart with the logs where the key would be the stats count field name and value would be the sum value&lt;/P&gt;
&lt;P&gt;Query :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;search1 | eval has_error = if(match(_raw, "WARNING"),1,0)| stats sum(has_error) as field1| join instance [search2 | eval has_error = if(match(_raw, "WARNING"),1,0)| stats sum(has_error) as field2| join instance [search3 | eval has_error = if(match(_raw, "WARNING"),1,0)| stats sum(has_error) as field3|join instance [search4&amp;nbsp; | eval has_error = if(match(_raw, "WARNING"),1,0)| stats sum(has_error) as field4]]] | stats sum( field1), sum(field2), sum( field3), sum( field4)&lt;/P&gt;
&lt;P&gt;Current result:&lt;/P&gt;
&lt;TABLE border="0" width="256" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64" height="19"&gt;field1&lt;/TD&gt;
&lt;TD width="64"&gt;field2&lt;/TD&gt;
&lt;TD width="64"&gt;field3&lt;/TD&gt;
&lt;TD width="64"&gt;field4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;30&lt;/TD&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;TD&gt;122&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected result:&lt;/P&gt;
&lt;TABLE border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64" height="19"&gt;Field&lt;/TD&gt;
&lt;TD width="64"&gt;Count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;field1&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;field2&lt;/TD&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;field3&lt;/TD&gt;
&lt;TD&gt;122&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;field4&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 27 Sep 2022 14:14:53 GMT</pubDate>
    <dc:creator>ninja_panda</dc:creator>
    <dc:date>2022-09-27T14:14:53Z</dc:date>
    <item>
      <title>How to frame a table from stats data?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614706#M213635</link>
      <description>&lt;P&gt;I want to create a Bar chart with the logs where the key would be the stats count field name and value would be the sum value&lt;/P&gt;
&lt;P&gt;Query :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;search1 | eval has_error = if(match(_raw, "WARNING"),1,0)| stats sum(has_error) as field1| join instance [search2 | eval has_error = if(match(_raw, "WARNING"),1,0)| stats sum(has_error) as field2| join instance [search3 | eval has_error = if(match(_raw, "WARNING"),1,0)| stats sum(has_error) as field3|join instance [search4&amp;nbsp; | eval has_error = if(match(_raw, "WARNING"),1,0)| stats sum(has_error) as field4]]] | stats sum( field1), sum(field2), sum( field3), sum( field4)&lt;/P&gt;
&lt;P&gt;Current result:&lt;/P&gt;
&lt;TABLE border="0" width="256" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64" height="19"&gt;field1&lt;/TD&gt;
&lt;TD width="64"&gt;field2&lt;/TD&gt;
&lt;TD width="64"&gt;field3&lt;/TD&gt;
&lt;TD width="64"&gt;field4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;30&lt;/TD&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;TD&gt;122&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected result:&lt;/P&gt;
&lt;TABLE border="0" width="128" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64" height="19"&gt;Field&lt;/TD&gt;
&lt;TD width="64"&gt;Count&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;field1&lt;/TD&gt;
&lt;TD&gt;30&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;field2&lt;/TD&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;field3&lt;/TD&gt;
&lt;TD&gt;122&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="19"&gt;field4&lt;/TD&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 14:14:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614706#M213635</guid>
      <dc:creator>ninja_panda</dc:creator>
      <dc:date>2022-09-27T14:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Frame a table from stats data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614709#M213637</link>
      <description>&lt;P&gt;If I understand your search correctly, you want to search for the amount of errors over 4 different sources and show them in a bar chart.&lt;/P&gt;&lt;P&gt;If you already have a key that identifies the source in the separate searches and the "search1-4" is just index and source type etc then try:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets say each "search" comes from a seperate index.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;(search1 OR search2 OR search3 OR search4)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval has_error = if(match(_raw, "WARNING"),1,0)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| where has_error=1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats count by index&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Then you have the amount of errors from each key.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it is a more komplex base search try this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;search 1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval key = "search1"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| append [ search search2 | eval key = "search2"]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| append [ search search3 | eval key = "search3"]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| append [ search search3 | eval key = "search3"]&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| eval has_error = if(match(_raw, "WARNING"),1,0)&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| where has_error=1&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| stats count by key&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;_______________________________________&lt;/P&gt;&lt;P&gt;If this was helpful please consider awarding Karma. Thx!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 09:18:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614709#M213637</guid>
      <dc:creator>FelixLeh</dc:creator>
      <dc:date>2022-09-27T09:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Frame a table from stats data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614715#M213640</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/249835"&gt;@ninja_panda&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;using a search like the one you shared, you can launch your search and then go to walk for 30-60 minutes!&lt;/P&gt;&lt;P&gt;Splunk isn't a database, you have to avoid join command and use it only if you haven't any other solution and always with few data.&lt;/P&gt;&lt;P&gt;You can use stats and eval to hasve the same result in a quicker way,&lt;/P&gt;&lt;P&gt;the main problem is to identify a filter for each search, if e.g. in each search you have a different index, or another field it's the same thing, you can try something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index IN (index1, index2, index3, index4) "WARNING"
| stats count BY index
| eval field=case(index=index1,"field1",index=index2,"field2",index=index3,"field3",index=index4,"field4")
| table field count&lt;/LI-CODE&gt;&lt;P&gt;If you have to use a different condition to identify the four searches, you can use something like this:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index IN (index1, index2, index3, index4) "WARNING"
| stats 
   count(eval(condition1)) AS field 1
   count(eval(condition2)) AS field 2
   count(eval(condition3)) AS field 3
   count(eval(condition4)) AS field 4
| transpose&lt;/LI-CODE&gt;&lt;P&gt;Ciao.&lt;/P&gt;&lt;P&gt;Giuseppe&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 09:30:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614715#M213640</guid>
      <dc:creator>gcusello</dc:creator>
      <dc:date>2022-09-27T09:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Frame a table from stats data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614719#M213643</link>
      <description>&lt;P&gt;The second solution worked as a charm. thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 09:48:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614719#M213643</guid>
      <dc:creator>ninja_panda</dc:creator>
      <dc:date>2022-09-27T09:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Frame a table from stats data</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614722#M213645</link>
      <description>&lt;P&gt;Glad to hear that &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Sep 2022 09:57:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-frame-a-table-from-stats-data/m-p/614722#M213645</guid>
      <dc:creator>FelixLeh</dc:creator>
      <dc:date>2022-09-27T09:57:34Z</dc:date>
    </item>
  </channel>
</rss>

