<?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 coalesce count in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/coalesce-count/m-p/536518#M151699</link>
    <description>&lt;P&gt;The goal is to get a count when a specific value exists 'by id'.&amp;nbsp; This is not working on a&amp;nbsp;coalesced search.&lt;BR /&gt;&lt;BR /&gt;The search below works, it looks at two source types with different field names that have the same type of values.&amp;nbsp; I used this because appendcols is very computation costly and I try to avoid it as much as possible.&amp;nbsp;&lt;/P&gt;&lt;P&gt;One alternative I tried was:&lt;/P&gt;&lt;PRE&gt;count(eval(if(isnotnull(calcValue),1,null())))&lt;/PRE&gt;&lt;P&gt;Lastly I tried, however that one gives an error:&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Error in 'stats' command: The eval expression for dynamic field 'if("total-calcValue"&amp;gt;0,1,null())' is invalid. Error='Type checking failed. The '&amp;gt;' operator received different types.'.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;count(eval(if("total-calcValue"&amp;gt;0,1,null())))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the full search&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=someindex (sourcetype1)  OR (sourcetype2) 
| rex field="Some Amt" "-(?&amp;lt;Amount&amp;gt;[\d\.]+)"
| convert num(Amount)
| rename Amount as total-calcValue, total as total-charges, "Some ID" as miq, "Other Source Company Name" as "other_source_company_name"
| eval mid=coalesce(mid,miq)
| eval Company=coalesce(other_source_company_name,company_name)
| stats count first(Company) AS "Company" sum(total-*) AS * count(eval(if(isnotnull("total-calcValue"),1,null()))) as "calcValue Count" by mid&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Jan 2021 15:03:58 GMT</pubDate>
    <dc:creator>dpolochefm</dc:creator>
    <dc:date>2021-01-20T15:03:58Z</dc:date>
    <item>
      <title>coalesce count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/coalesce-count/m-p/536518#M151699</link>
      <description>&lt;P&gt;The goal is to get a count when a specific value exists 'by id'.&amp;nbsp; This is not working on a&amp;nbsp;coalesced search.&lt;BR /&gt;&lt;BR /&gt;The search below works, it looks at two source types with different field names that have the same type of values.&amp;nbsp; I used this because appendcols is very computation costly and I try to avoid it as much as possible.&amp;nbsp;&lt;/P&gt;&lt;P&gt;One alternative I tried was:&lt;/P&gt;&lt;PRE&gt;count(eval(if(isnotnull(calcValue),1,null())))&lt;/PRE&gt;&lt;P&gt;Lastly I tried, however that one gives an error:&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Error in 'stats' command: The eval expression for dynamic field 'if("total-calcValue"&amp;gt;0,1,null())' is invalid. Error='Type checking failed. The '&amp;gt;' operator received different types.'.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;count(eval(if("total-calcValue"&amp;gt;0,1,null())))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the full search&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=someindex (sourcetype1)  OR (sourcetype2) 
| rex field="Some Amt" "-(?&amp;lt;Amount&amp;gt;[\d\.]+)"
| convert num(Amount)
| rename Amount as total-calcValue, total as total-charges, "Some ID" as miq, "Other Source Company Name" as "other_source_company_name"
| eval mid=coalesce(mid,miq)
| eval Company=coalesce(other_source_company_name,company_name)
| stats count first(Company) AS "Company" sum(total-*) AS * count(eval(if(isnotnull("total-calcValue"),1,null()))) as "calcValue Count" by mid&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 15:03:58 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/coalesce-count/m-p/536518#M151699</guid>
      <dc:creator>dpolochefm</dc:creator>
      <dc:date>2021-01-20T15:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/coalesce-count/m-p/536523#M151703</link>
      <description>&lt;P&gt;Using hyphens in field names is not a great idea.&amp;nbsp; Stick with underscores or use camelCase.&amp;nbsp; Introducing other characters may be valid, but can lead to errors (as you've seen) or confusion (is&amp;nbsp;"total-calcValue" a string, an expression, or something else?).&amp;nbsp; Often, putting single quotes around the field will help, but not always.&lt;/P&gt;&lt;P&gt;Try this modification of your query.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=someindex (sourcetype1)  OR (sourcetype2) 
| rex field="Some Amt" "-(?&amp;lt;Amount&amp;gt;[\d\.]+)"
| convert num(Amount)
| rename Amount as total_calcValue, total as total_charges, "Some ID" as miq, "Other Source Company Name" as "other_source_company_name"
| eval mid=coalesce(mid,miq)
| eval Company=coalesce(other_source_company_name,company_name)
| stats count first(Company) AS "Company" sum(total_*) AS * sum(eval(isnotnull(total_calcValue))) as "calcValue Count" by mid&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Jan 2021 15:17:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/coalesce-count/m-p/536523#M151703</guid>
      <dc:creator>richgalloway</dc:creator>
      <dc:date>2021-01-20T15:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: coalesce count</title>
      <link>https://community.splunk.com/t5/Splunk-Search/coalesce-count/m-p/536874#M151773</link>
      <description>&lt;P&gt;The issue was that&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;"total-calcValue"&lt;/LI-CODE&gt;&lt;P&gt;needed to be changed to&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;'total-calcValue'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;It was taking the double quote version as a literal text value instead of the field..&lt;/P&gt;</description>
      <pubDate>Fri, 22 Jan 2021 18:00:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/coalesce-count/m-p/536874#M151773</guid>
      <dc:creator>dpolochefm</dc:creator>
      <dc:date>2021-01-22T18:00:31Z</dc:date>
    </item>
  </channel>
</rss>

