<?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: how to add more than one matching criteria while getting the count in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301132#M90651</link>
    <description>&lt;P&gt;@surekhasplunk, since this question is for @somesoni2, I will wait for him to answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Seems like you are looking for this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup file1.csv 
| search field1="abc"
| stats count(eval(match(field2,"xyz") AND match(field4,"222"))) as myCount by field3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However performance wise you can try the following instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup file1.csv where field1="abc" field2="*xyz*" field4="*222*"
| stats count as myCount by field3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Since you have used &lt;CODE&gt;match()&lt;/CODE&gt; in your question I have used &lt;CODE&gt;asterisk ( * )&lt;/CODE&gt; for wildcard search using &lt;CODE&gt;where&lt;/CODE&gt; in the inputlookup command.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Inputlookup"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Inputlookup&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Nov 2017 14:46:17 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2017-11-22T14:46:17Z</dc:date>
    <item>
      <title>how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301131#M90650</link>
      <description>&lt;P&gt;Hi @somesoni2&lt;/P&gt;

&lt;P&gt;Can you help me with a simple search i have following requirement&lt;/P&gt;

&lt;P&gt;from a single input lookup file. Now am using below query to get the field2 count by field3 for a particular pattern math.&lt;/P&gt;

&lt;P&gt;|inputlookup file1.csv|search field1=abc|stats count(eval(match(field2,xyz) as output by field3&lt;/P&gt;

&lt;P&gt;How can i add another matching criteria to the same query something like this. &lt;BR /&gt;
|inputlookup file1.csv|search field1=abc|stats count(eval(match(field2,xyz AND filed4,222) as output by field3&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 13:42:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301131#M90650</guid>
      <dc:creator>surekhasplunk</dc:creator>
      <dc:date>2017-11-22T13:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301132#M90651</link>
      <description>&lt;P&gt;@surekhasplunk, since this question is for @somesoni2, I will wait for him to answer &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Seems like you are looking for this...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup file1.csv 
| search field1="abc"
| stats count(eval(match(field2,"xyz") AND match(field4,"222"))) as myCount by field3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However performance wise you can try the following instead:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup file1.csv where field1="abc" field2="*xyz*" field4="*222*"
| stats count as myCount by field3
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Since you have used &lt;CODE&gt;match()&lt;/CODE&gt; in your question I have used &lt;CODE&gt;asterisk ( * )&lt;/CODE&gt; for wildcard search using &lt;CODE&gt;where&lt;/CODE&gt; in the inputlookup command.&lt;/P&gt;

&lt;P&gt;&lt;A href="https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Inputlookup"&gt;https://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Inputlookup&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 14:46:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301132#M90651</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-22T14:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301133#M90652</link>
      <description>&lt;P&gt;These would be my answers too, with a typo correction of &lt;CODE&gt;as field3&lt;/CODE&gt; with &lt;CODE&gt;by field3&lt;/CODE&gt;. &lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 14:59:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301133#M90652</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-22T14:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301134#M90653</link>
      <description>&lt;P&gt;Oh it was intentional alias for &lt;CODE&gt;count(eval(...))&lt;/CODE&gt;. But I missed in the question whether it was originally &lt;CODE&gt;as field3&lt;/CODE&gt; or &lt;CODE&gt;by field3&lt;/CODE&gt; let me correct. Now I know why the question was directed specifically towards you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 15:04:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301134#M90653</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-22T15:04:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301135#M90654</link>
      <description>&lt;P&gt;Hi @niketnilay, &lt;/P&gt;

&lt;P&gt;Thanks for your response but stats count(eval(match(field2,"xyz") AND match(field4,"222")))  doesn't seem to be working i am getting syntax error Error in 'stats' command: You must specify a rename for the aggregation specifier on the dynamically evaluated field &lt;/P&gt;

&lt;P&gt;And i can use the performance approach since i have got more than 1 field to evaluate&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 15:09:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301135#M90654</guid>
      <dc:creator>surekhasplunk</dc:creator>
      <dc:date>2017-11-22T15:09:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301136#M90655</link>
      <description>&lt;P&gt;You need to give stats an alias... add &lt;STRONG&gt;as myCount&lt;/STRONG&gt; as the alias just after stats&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 15:23:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301136#M90655</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-22T15:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301137#M90656</link>
      <description>&lt;P&gt;|inputlookup file1.csv|search  category="&lt;EM&gt;Time&lt;/EM&gt;" Region=UK "Location - City"="&lt;EM&gt;London&lt;/EM&gt;"| stats count(eval("Onsite/Offsite" like "%Onsite%")) as ON  , count(eval(match('Onsite/Offsite',"Offsite")))  as OFF by "CTO sub department" |eval Total=ON+OFF&lt;/P&gt;

&lt;P&gt;Now i have another query &lt;BR /&gt;
|inputlookup file1.csv|search  category="&lt;EM&gt;Outcome&lt;/EM&gt;" Region=UK "Location - City"="&lt;EM&gt;London&lt;/EM&gt;"| stats count(eval("Onsite/Offsite" like "%Onsite%")) as ON  , count(eval(match('Onsite/Offsite',"Offsite")))  as OFF by department |eval Total=ON+OFF&lt;/P&gt;

&lt;P&gt;It just differs on the category value and i want output like below:&lt;BR /&gt;
                       Time                  Outcome&lt;BR /&gt;
                      ON|OFF|total|ON|OFF|total&lt;BR /&gt;
department  10|10|20|22|33|55&lt;/P&gt;

&lt;P&gt;hope its clear now. what i am trying to achieve. &lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 15:33:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301137#M90656</guid>
      <dc:creator>surekhasplunk</dc:creator>
      <dc:date>2017-11-22T15:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301138#M90657</link>
      <description>&lt;P&gt;Please try the following&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup file1.csv where ( category="Time" OR category="Outcome" )
| chart count(eval( category="Time" AND match('Onsite/Offshore',"Onsite"))) as "Time:ON" count(eval( category="Time" AND match('Onsite/Offshore',"Offsite")))  as "Time:OFF" count(eval( category="London" AND match('Onsite/Offshore',"Onsite")))  as "London:ON" count(eval( category="London" AND match('Onsite/Offshore',"Onsite"))) as "London:OFF" by department
| eval "Time:Total"='Time:ON' + 'Time:OFF'
| eval "London:Total"='London:ON' + 'London:OFF'
| table department Time* London*
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Nov 2017 16:29:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301138#M90657</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-22T16:29:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301139#M90658</link>
      <description>&lt;P&gt;Give this a try&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|inputlookup file1.csv
|search (category="*Time*" OR category="*Outcome*") Region=UK "Location - City"="*London*"
("Onsite/Offsite"="*Onsite*" OR "Onsite/Offsite"="*Offsite*")
| eval colField=if(match(category,"Time"),"Time","Outcome").":".if(match('Onsite/Offsite',"Onsite"),"ON","OFF")
| eval department=if(match(category,"Time"),'CTO sub department',department)
| chart count over department by colField
| eval "Time:Total"='Time:ON'+'Time:OFF' 
| eval "Outcome:Total"='Outcome:ON'+'Outcome:OFF' 
| table department "Time:ON" "Time:OFF" "Time:Total" "Outcome:ON" "Outcome:OFF" "Outcome:Total"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Nov 2017 17:33:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301139#M90658</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-11-22T17:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301140#M90659</link>
      <description>&lt;P&gt;Thanks a lot it worked well for me and i got the required result. &lt;/P&gt;

&lt;P&gt;But if i want to do a pattern match there i am getting error saying you have to dynamically allocate the values. &lt;/P&gt;

&lt;P&gt;| inputlookup file1.csv where ( category="&lt;EM&gt;Time&lt;/EM&gt;" OR category="&lt;EM&gt;Outcome&lt;/EM&gt;" )&lt;BR /&gt;
 | chart count(eval( category="Time" AND match('Onsite/Offshore',"Onsite"))) as "Time:ON" count(eval( category="&lt;EM&gt;Time&lt;/EM&gt;" AND match('Onsite/Offshore',"Offsite")))  as "Time:OFF" count(eval( category="London" AND match('Onsite/Offshore',"Onsite")))  as "London:ON" count(eval( category="London" AND match('Onsite/Offshore',"Onsite"))) as "London:OFF" by department&lt;BR /&gt;
 | eval "Time:Total"='Time:ON' + 'Time:OFF'&lt;BR /&gt;
 | eval "London:Total"='London:ON' + 'London:OFF'&lt;BR /&gt;
 | table department Time* London*&lt;/P&gt;

&lt;P&gt;Can you please help me with that pattern match against the category values. &lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 11:26:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301140#M90659</guid>
      <dc:creator>surekhasplunk</dc:creator>
      <dc:date>2017-11-23T11:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301141#M90660</link>
      <description>&lt;P&gt;@surekhasplunk, can you please post above code with &lt;CODE&gt;code button (with 101010)&lt;/CODE&gt; so that special characters do not escape?&lt;/P&gt;

&lt;P&gt;Are you trying to do Pattern match in first &lt;CODE&gt;inputlookup&lt;/CODE&gt; command? If yes then you will have to remove from &lt;CODE&gt;where&lt;/CODE&gt; to next pipe with &lt;CODE&gt;search&lt;/CODE&gt;, the way you had in your original query.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| inputlookup file1.csv 
| search ( category="Time*" OR category="Outcome" )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If wildcard is somewhere else please re-post your search with code button and mention the error you are receiving.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 14:45:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301141#M90660</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-23T14:45:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to add more than one matching criteria while getting the count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301142#M90661</link>
      <description>&lt;P&gt;@surekhasplunk, have to tried the search provided by @somesoni2? It uses wildcard in filter from inputlookup.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 14:47:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-to-add-more-than-one-matching-criteria-while-getting-the/m-p/301142#M90661</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-11-23T14:47:17Z</dc:date>
    </item>
  </channel>
</rss>

