<?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: Simple math and string concatenation in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255532#M76525</link>
    <description>&lt;P&gt;i get this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval when=if(_time &amp;gt; relative_time( now(), "-7d@d  " )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the problem is the space after the d.&lt;/P&gt;

&lt;P&gt;so i changed form this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Last 7 days |-7d@d  |-14d@d;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Last 7 days |-7d@d|-14d@d;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and now seems to work&lt;/P&gt;

&lt;P&gt;Thank you a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Sep 2016 07:58:12 GMT</pubDate>
    <dc:creator>andreafebbo</dc:creator>
    <dc:date>2016-09-02T07:58:12Z</dc:date>
    <item>
      <title>Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255522#M76515</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;
I have this dashboard:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Prova_selettore_dinamico Clona v1&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false" autoRun="true"&amp;gt;
    &amp;lt;input type="radio" token="period" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Intervallo&amp;lt;/label&amp;gt;
      &amp;lt;choice value="1"&amp;gt;Last day&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="7"&amp;gt;Last 7 days&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="30"&amp;gt;Last 30 days&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="365"&amp;gt;Last 12 months&amp;lt;/choice&amp;gt;
      &amp;lt;default&amp;gt;30&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;-30d&amp;lt;/initialValue&amp;gt;
      &amp;lt;prefix&amp;gt;-&amp;lt;/prefix&amp;gt;
      &amp;lt;suffix&amp;gt;d&amp;lt;/suffix&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  CODE
          &amp;lt;earliest&amp;gt;$period$&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
   CODE
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The token $period$ is set, for instance, at -30d (and I use this token i the query so i need it like this).&lt;/P&gt;

&lt;P&gt;Now what I also need is the $period$ to double the period, for example: -60d&lt;/P&gt;

&lt;P&gt;This implies that i have to extract the 30 from the string "-30d", double it and put it back between the "-" and the "d".&lt;/P&gt;

&lt;P&gt;Another solution i thought is to set 2 values for every choice of the imput, like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;choice value="30" value2="60"&amp;gt;Last 30 days&amp;lt;/choice&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But this seems to be not possible.&lt;/P&gt;

&lt;P&gt;Please help me.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;I tried to integrate your code with my and this came our:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Prova_selettore_dinamico Clona v4&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false" autoRun="true"&amp;gt;
    &amp;lt;input type="dropdown" token="t" searchWhenChanged="true"&amp;gt;
      &amp;lt;label&amp;gt;Timerange&amp;lt;/label&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| makeresults
               | eval x="Last day    |-1d@d  |-2d@d;
                         Last 7 days |-7d@d  |-14d@d;
                         Last 30 days|-30d@d |-60d@d"
               | makemv x delim=";"
               | mvexpand x
               | rex field=x "(?&amp;lt;label&amp;gt;[^\|]+)\|(?&amp;lt;value&amp;gt;[^\|]+)\|(?&amp;lt;doublevalue&amp;gt;.*)"
               | table label value doublevalue&amp;lt;/query&amp;gt;
        &amp;lt;earliest&amp;gt;-15m&amp;lt;/earliest&amp;gt;
        &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;label&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;value&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;change&amp;gt;
        &amp;lt;set token="double"&amp;gt;$row.doublevalue$&amp;lt;/set&amp;gt;
        &amp;lt;set token="nor"&amp;gt;$row.value$&amp;lt;/set&amp;gt;
      &amp;lt;/change&amp;gt;
      &amp;lt;default&amp;gt;dfsdfhsdgh&amp;lt;/default&amp;gt;
      &amp;lt;initialValue&amp;gt;-1d@d&amp;lt;/initialValue&amp;gt;
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;BASE QUERY   
| eval when=if(_time &amp;amp;gt; relative_time(now(), "$nor$"), "Current_Week", "Prev_Week")  
| stats count as events by  source when  
| chart sum(events) by source, when  
| eval perc = (Current_Week-Prev_Week)/Prev_Week 
| eval trend = case(perc &amp;lt; -0.3, "basso", (perc &amp;gt;= -0.3 and perc &amp;lt;= 0.3 ), "medio", perc &amp;gt; 0.3, "alto") 
| table source, Current_Week, Prev_Week, perc, trend&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;$double$&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;true&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;cell&amp;lt;/option&amp;gt;
        &amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Everything seems to work except one thing.&lt;BR /&gt;
In the second row of the second query is written:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval when=if(_time &amp;amp;gt; relative_time(now(), "$nor$"), "Current_Week", "Prev_Week") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and for some reason it put everything in Prev_Week.&lt;BR /&gt;
instead if I write this line like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval when=if(_time &amp;gt; relative_time(now(), "-7d"), "Current_Week", "Prev_Week") 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;then everything works, but of course is not dynamic.&lt;/P&gt;

&lt;P&gt;Can you help me understand why?&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 14:57:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255522#M76515</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2016-08-31T14:57:43Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255523#M76516</link>
      <description>&lt;P&gt;What you will need to do is create a dynamic query that generates a table with 3 columns, label, value and value2. Bind the results to the dropdown, and set a token on change event to pick the "double" value. Here is a "run anywhere" sample that will give you an idea on how this can be done.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;form&amp;gt;
  &amp;lt;label&amp;gt;Test&amp;lt;/label&amp;gt;
  &amp;lt;fieldset submitButton="false"&amp;gt;
    &amp;lt;input type="dropdown" token="t"&amp;gt;
      &amp;lt;label&amp;gt;Timerange&amp;lt;/label&amp;gt;
      &amp;lt;search&amp;gt;
        &amp;lt;query&amp;gt;| makeresults | eval x="Last day|-1d@d|-2d@d;Last 7 days|-7d@d|-14d@d;Last 30 days|-30d@d|-60d@d" | makemv x delim=";" | mvexpand x | rex field=x "(?&amp;lt;label&amp;gt;[^\|]+)\|(?&amp;lt;value&amp;gt;[^\|]+)\|(?&amp;lt;doublevalue&amp;gt;.*)" | table label value doublevalue&amp;lt;/query&amp;gt;
      &amp;lt;/search&amp;gt;
      &amp;lt;fieldForLabel&amp;gt;label&amp;lt;/fieldForLabel&amp;gt;
      &amp;lt;fieldForValue&amp;gt;value&amp;lt;/fieldForValue&amp;gt;
      &amp;lt;change&amp;gt;
        &amp;lt;set token="double"&amp;gt;$row.doublevalue$&amp;lt;/set&amp;gt;
      &amp;lt;/change&amp;gt;  
    &amp;lt;/input&amp;gt;
  &amp;lt;/fieldset&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;event&amp;gt;
        &amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;index=_internal earliest=$double$ | stats earliest(_time) as first latest(_time) as last | eval first=strftime(first, "%x %X") | eval last=strftime(last, "%x %X") | eval double="$double$"&amp;lt;/query&amp;gt;
          &amp;lt;earliest&amp;gt;-15m&amp;lt;/earliest&amp;gt;
          &amp;lt;latest&amp;gt;now&amp;lt;/latest&amp;gt;
        &amp;lt;/search&amp;gt;
      &amp;lt;/event&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Aug 2016 15:13:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255523#M76516</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-08-31T15:13:39Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255524#M76517</link>
      <description>&lt;P&gt;Can you answer also to this question?&lt;/P&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/446961/calculate-time-and-doubling-it-from-the-user-selec.html"&gt;https://answers.splunk.com/answers/446961/calculate-time-and-doubling-it-from-the-user-selec.html&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Wed, 31 Aug 2016 15:55:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255524#M76517</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2016-08-31T15:55:49Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255525#M76518</link>
      <description>&lt;P&gt;Please do not update the original question. Add your feedback/comments in the comments section. Its become very difficult to track.&lt;/P&gt;

&lt;P&gt;Now, re: your issue. You dont need the "nor" token. You should use  &lt;CODE&gt;$t$&lt;/CODE&gt; for it. So, your query should look like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval when=if(_time &amp;gt; relative_time(now(), "$t$"), "Current_Week", "Prev_Week") 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:12:49 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255525#M76518</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-09-01T14:12:49Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255526#M76519</link>
      <description>&lt;P&gt;I did it and it works in the same way,  still putting everything in the prev_week. &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:23:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255526#M76519</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2016-09-01T14:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255527#M76520</link>
      <description>&lt;P&gt;Add this just below the &lt;CODE&gt;&amp;lt;panel&amp;gt;&lt;/CODE&gt; tag. &lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;&amp;lt;title&amp;gt;value=$t$; doublevalue=$double$&amp;lt;/title&amp;gt;&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;Do the values look right when you run it?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 15:05:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255527#M76520</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-09-01T15:05:26Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255528#M76521</link>
      <description>&lt;P&gt;yes, the numbers look right:&lt;BR /&gt;
&lt;CODE&gt;value=-7d@d ; doublevalue=-14d@d&lt;/CODE&gt;&lt;BR /&gt;
but all the data keep going into the prev_week.&lt;/P&gt;

&lt;P&gt;And still if i change from "$t$" to "-14d", which should be the exact same value, then it works.&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 15:17:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255528#M76521</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2016-09-01T15:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255529#M76522</link>
      <description>&lt;P&gt;remove the quotes around &lt;CODE&gt;$t$&lt;/CODE&gt;. &lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 16:25:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255529#M76522</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-09-01T16:25:24Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255530#M76523</link>
      <description>&lt;P&gt;if I remove the quotes around &lt;CODE&gt;$t$&lt;/CODE&gt; it gives me the following error:&lt;/P&gt;

&lt;BLOCKQUOTE&gt;
&lt;P&gt;Error in 'eval' command: The expression is malformed. Expected ).&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;

&lt;P&gt;I think it is because that &lt;CODE&gt;$t$&lt;/CODE&gt; is inside the query.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 18:07:17 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255530#M76523</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2016-09-01T18:07:17Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255531#M76524</link>
      <description>&lt;P&gt;In the bottom left corner of the panel, there is a magnifying glass. Click on that, see what you get in the search&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 19:24:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255531#M76524</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-09-01T19:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255532#M76525</link>
      <description>&lt;P&gt;i get this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval when=if(_time &amp;gt; relative_time( now(), "-7d@d  " )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;the problem is the space after the d.&lt;/P&gt;

&lt;P&gt;so i changed form this &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Last 7 days |-7d@d  |-14d@d;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Last 7 days |-7d@d|-14d@d;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and now seems to work&lt;/P&gt;

&lt;P&gt;Thank you a lot &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 07:58:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255532#M76525</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2016-09-02T07:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255533#M76526</link>
      <description>&lt;P&gt;@andreafebbo Can I close out the other question as a duplicate of this one?&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 11:47:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255533#M76526</guid>
      <dc:creator>sundareshr</dc:creator>
      <dc:date>2016-09-02T11:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Simple math and string concatenation</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255534#M76527</link>
      <description>&lt;P&gt;I needed for the same dashboard but the other does something broader so it would be nice to find a solution, but just for academical ends  &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Sep 2016 14:21:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Simple-math-and-string-concatenation/m-p/255534#M76527</guid>
      <dc:creator>andreafebbo</dc:creator>
      <dc:date>2016-09-02T14:21:56Z</dc:date>
    </item>
  </channel>
</rss>

