<?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: Stats for multiple fields in the same table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632888#M219837</link>
    <description>&lt;LI-CODE lang="markup"&gt;| eval count=mvrange(0, count)
| mvexpand count
| untable count error status
| eval status=if(status="NA","Success","Failure")
| chart count by error status&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 01 Mar 2023 22:50:16 GMT</pubDate>
    <dc:creator>ITWhisperer</dc:creator>
    <dc:date>2023-03-01T22:50:16Z</dc:date>
    <item>
      <title>Stats for multiple fields in the same table?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632853#M219825</link>
      <description>&lt;P&gt;I have logs like below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{ [-]
   TransactionName: "my TransactionName"
   type1Error: NA
   eventTime: 2023-02-28 11:16:52.961
   type2Error: NA
   type3Error: NA
}&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;{ [-]
   TransactionName: "my TransactionName"
   type1Error: NA
   eventTime: 2023-02-28 11:16:52.961
   type2Error: Missing Field
   type3Error: NA
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have framed a below query:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;index=my_idx | stats count by type1Error, type2Error, type3Error&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which gives me result like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;---------------------------------------------------------
type1Error		type2Error		type3Error		count
---------------------------------------------------------
NA				NA				NA				1
NA				NA				Missing Field	1
---------------------------------------------------------&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But then, it would be better if I can bring it for success and failures separately. Like:&lt;/P&gt;
&lt;P&gt;Create 2 new queries for errors with NA and not NA:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;NA&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;----------------------------------------------------
Success count
----------------------------------------------------
type1Error 2
type2Error 2
type3Error 1
----------------------------------------------------&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Not NA&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;----------------------------------------------------
Failure count
----------------------------------------------------
type1Error 0
type2Error 0
type3Error 1
----------------------------------------------------&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can we achieve this? Not getting a clear picture on how to frame a query for this. Tried using chart, but no luck !!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 15:22:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632853#M219825</guid>
      <dc:creator>Nidd</dc:creator>
      <dc:date>2023-03-02T15:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Stats for multiple fields in the same table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632885#M219835</link>
      <description>&lt;P&gt;You could do something like this&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| foreach type*Error [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=if('&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;'="NA", 0, 1) ]
| stats count sum(*) as *
| eval type="Failures"
| appendpipe [
  | foreach type*Error [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;=count-&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; ]
  | eval type="Success"
]
| fields - count
| transpose 0 header_field=type column_name=Type&lt;/LI-CODE&gt;&lt;P&gt;which is generic and does not care how many types of error you have - in this case 3. It will put both success/fail in same table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 22:16:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632885#M219835</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-03-01T22:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Stats for multiple fields in the same table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632887#M219836</link>
      <description>&lt;P&gt;Or if you just want a single query for failures&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;... search ...
| stats sum(eval(if(type1Error!="NA",1,0))) as type1Error sum(eval(if(type2Error!="NA",1,0))) as type2Error sum(eval(if(type3Error!="NA",1,0))) as type3Error
| transpose 0 column_name=Type
| rename "row 1" as Failures&lt;/LI-CODE&gt;&lt;P&gt;and change the stats for successes. Note that this means you always need to know the field names.&lt;/P&gt;&lt;P&gt;You can always use the previous query for both if you're going to use this in a dashboard by making it a base search and then just removing the field you don't want in the post processing search.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2023 22:30:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632887#M219836</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-03-01T22:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: Stats for multiple fields in the same table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632888#M219837</link>
      <description>&lt;LI-CODE lang="markup"&gt;| eval count=mvrange(0, count)
| mvexpand count
| untable count error status
| eval status=if(status="NA","Success","Failure")
| chart count by error status&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 01 Mar 2023 22:50:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632888#M219837</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-01T22:50:16Z</dc:date>
    </item>
    <item>
      <title>Re: Stats for multiple fields in the same table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632906#M219843</link>
      <description>&lt;P&gt;I always knew there'd be a simple way - must play with untable...&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 04:45:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Stats-for-multiple-fields-in-the-same-table/m-p/632906#M219843</guid>
      <dc:creator>bowesmana</dc:creator>
      <dc:date>2023-03-02T04:45:38Z</dc:date>
    </item>
  </channel>
</rss>

