<?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: If-statement does not work in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155900#M43856</link>
    <description>&lt;P&gt;Non-standard field names have to be enclosed in single quotes for &lt;CODE&gt;where&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats dc(eval(if('2013_11'="1" AND '2013_12'="1", user_id, null()))) AS output
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 24 Jul 2014 11:25:54 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-07-24T11:25:54Z</dc:date>
    <item>
      <title>If-statement does not work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155895#M43851</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;my search looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| eval month=strftime(_time, "%Y_%m")
| chart dc(user_id) as count by user_id, month
| stats dc(eval(if(2013_11="1" AND 2013_12="1", user_id, null()))) AS output
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The stats command does not work and I don't know why&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;"Error in 'stats' command: The eval expression for dynamic field 'eval(if(2013_11="1", account_id, null()))' is invalid. Error='The expression is malformed. Expected ).' "
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've used such a command many times before and Splunk never complained about it.&lt;/P&gt;

&lt;P&gt;BR&lt;/P&gt;

&lt;P&gt;Heinz&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2014 09:04:35 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155895#M43851</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2014-07-24T09:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: If-statement does not work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155896#M43852</link>
      <description>&lt;P&gt;Why are you using 2013_11 and 2013_12 in if condition. Could you please tell us what are you trying there?&lt;BR /&gt;
You need to use month in if, not its value. If you give us more details we can help you to write the search&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:09:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155896#M43852</guid>
      <dc:creator>strive</dc:creator>
      <dc:date>2020-09-28T17:09:50Z</dc:date>
    </item>
    <item>
      <title>Re: If-statement does not work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155897#M43853</link>
      <description>&lt;P&gt;These are the column names after the chart command. The Stats command should count number the users if the value in both columns is "1"&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2014 09:24:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155897#M43853</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2014-07-24T09:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: If-statement does not work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155898#M43854</link>
      <description>&lt;P&gt;In the end, I want to have a chart that shows the number of active users in 2013_12, who have been active in 2013_11 as well.&lt;/P&gt;

&lt;P&gt;I'm wondering, why it is not possible to use it in the if command? Using it as " | search 2013_01="1" is working, so Splunk seems to know that it is the fieldname here&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 17:09:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155898#M43854</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2020-09-28T17:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: If-statement does not work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155899#M43855</link>
      <description>&lt;P&gt;I just tried out another apporach and it seems to work fine:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;...
| eval month=strftime(_time, "%Y_%m")
| stats values(month) AS months by user_id
| stats dc(eval(if(months="2013_11" AND months="2013_12", user_id, null()))) AS users
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Jul 2014 09:57:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155899#M43855</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2014-07-24T09:57:52Z</dc:date>
    </item>
    <item>
      <title>Re: If-statement does not work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155900#M43856</link>
      <description>&lt;P&gt;Non-standard field names have to be enclosed in single quotes for &lt;CODE&gt;where&lt;/CODE&gt; and &lt;CODE&gt;eval&lt;/CODE&gt;:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats dc(eval(if('2013_11'="1" AND '2013_12'="1", user_id, null()))) AS output
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Jul 2014 11:25:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155900#M43856</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-24T11:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: If-statement does not work</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155901#M43857</link>
      <description>&lt;P&gt;thank you very much!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Jul 2014 12:05:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-does-not-work/m-p/155901#M43857</guid>
      <dc:creator>HeinzWaescher</dc:creator>
      <dc:date>2014-07-24T12:05:53Z</dc:date>
    </item>
  </channel>
</rss>

