<?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: Cannot get count by case statement in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-count-by-case-statement/m-p/703870#M238538</link>
    <description>&lt;P&gt;You can use LIKE or MATCH&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval region=CASE(LIKE(url, "%region1%"), "Region 1", LIKE(url, "%region2%"), "Region 2")

| eval region=CASE(MATCH(url, "region1"), "Region 1", MATCH(url, "region2"), "Region 2")&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 08 Nov 2024 03:13:39 GMT</pubDate>
    <dc:creator>johnhuang</dc:creator>
    <dc:date>2024-11-08T03:13:39Z</dc:date>
    <item>
      <title>Cannot get count by case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-count-by-case-statement/m-p/703865#M238536</link>
      <description>&lt;P&gt;I am trying to simply break down a url to extract the region and chart the use of specific urls over time. but i just get a NULL count of everything. How do i display the counts as separate values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[query] | eval region=case(url like "%region1%","Region 1",url like "%region2%","Region 2") | timechart span=1h count by region&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 08 Nov 2024 15:11:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-count-by-case-statement/m-p/703865#M238536</guid>
      <dc:creator>tjsnow</dc:creator>
      <dc:date>2024-11-08T15:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get count by case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-count-by-case-statement/m-p/703870#M238538</link>
      <description>&lt;P&gt;You can use LIKE or MATCH&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval region=CASE(LIKE(url, "%region1%"), "Region 1", LIKE(url, "%region2%"), "Region 2")

| eval region=CASE(MATCH(url, "region1"), "Region 1", MATCH(url, "region2"), "Region 2")&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 08 Nov 2024 03:13:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-count-by-case-statement/m-p/703870#M238538</guid>
      <dc:creator>johnhuang</dc:creator>
      <dc:date>2024-11-08T03:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot get count by case statement</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Cannot-get-count-by-case-statement/m-p/703883#M238547</link>
      <description>&lt;P&gt;Going back to my four commandments of asking answerable questions:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Illustrate data input (in raw text, anonymize as needed), whether they are raw events or output from a search (SPL that volunteers here do not have to look at).&lt;/LI&gt;&lt;LI&gt;Illustrate the desired output from illustrated data.&lt;/LI&gt;&lt;LI&gt;Explain the logic between illustrated data and desired output&amp;nbsp;&lt;EM&gt;without&lt;/EM&gt;&amp;nbsp;SPL.&lt;/LI&gt;&lt;LI&gt;If you also illustrate attempted SPL, illustrate actual output and compare with desired output, explain why they look different&amp;nbsp;&lt;U&gt;to you&lt;/U&gt;&amp;nbsp;if that is not painfully obvious.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Until you can illustrate your data, no one can help you. &amp;nbsp;On the surface, your case function should work given this set of data:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;url&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="229.140625px" height="25px"&gt;abc.fromregion1.com&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="229.140625px" height="25px"&gt;def.toregion2wego.com&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="229.140625px" height="25px"&gt;ghi.fromregion1toregion2.com&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;You can run a stats and get&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;region&lt;/TD&gt;&lt;TD&gt;count&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Region 1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Region 2&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Here is the emulation to prove the above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults format=csv data="url
abc.fromregion1.com
def.toregion2wego.com
ghi.fromregion1toregion2.com"
``` data emulation above ```
| eval region=case(url like "%region1%","Region 1",url like "%region2%","Region 2")
| stats count by region&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 06:22:46 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Cannot-get-count-by-case-statement/m-p/703883#M238547</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2024-11-08T06:22:46Z</dc:date>
    </item>
  </channel>
</rss>

