<?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 can I pass field value as macro name in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133045#M36331</link>
    <description>&lt;P&gt;Macro substitution happens once before the search is started, so it cannot depend on field values.&lt;/P&gt;

&lt;P&gt;What's in those macros? Maybe there's a different way to achieve whatever it is you're trying to do.&lt;/P&gt;

&lt;P&gt;Edit: Here's what you can do. Define an eval-based macro &lt;CODE&gt;fieldA_or_fieldB(1)&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if("$selection$"=="*", "fieldA", "fieldB")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then change your search to this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats sum(total_amount) by `fieldA_or_fieldB($your_token$)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That'll select fieldA if your token has been set to &lt;CODE&gt;*&lt;/CODE&gt;, fieldB otherwise.&lt;/P&gt;</description>
    <pubDate>Tue, 08 Jul 2014 00:14:14 GMT</pubDate>
    <dc:creator>martin_mueller</dc:creator>
    <dc:date>2014-07-08T00:14:14Z</dc:date>
    <item>
      <title>How can I pass field value as macro name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133044#M36330</link>
      <description>&lt;P&gt;I have two macros with names &lt;STRONG&gt;yes&lt;/STRONG&gt; and &lt;STRONG&gt;no&lt;/STRONG&gt;&lt;/P&gt;

&lt;P&gt;Now, I want to refer to these macros in my search query, but not by directly calling them with the name&lt;/P&gt;

&lt;P&gt;My query looks something like below&lt;BR /&gt;
&lt;PRE&gt;&lt;BR /&gt;
...| eval FLAG=if(fieldA!=fieldb,yes,no) | `FLAG`&lt;BR /&gt;
&lt;/PRE&gt;&lt;/P&gt;

&lt;P&gt;I want the FLAG field to be substituted with yes or no so that my corresponding macro is called.&lt;/P&gt;

&lt;P&gt;With the above approach, I suppose it looks for a macro with the name FLAG.&lt;/P&gt;

&lt;P&gt;How can I achieve this?&lt;/P&gt;</description>
      <pubDate>Mon, 07 Jul 2014 21:09:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133044#M36330</guid>
      <dc:creator>pradeepkumarg</dc:creator>
      <dc:date>2014-07-07T21:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pass field value as macro name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133045#M36331</link>
      <description>&lt;P&gt;Macro substitution happens once before the search is started, so it cannot depend on field values.&lt;/P&gt;

&lt;P&gt;What's in those macros? Maybe there's a different way to achieve whatever it is you're trying to do.&lt;/P&gt;

&lt;P&gt;Edit: Here's what you can do. Define an eval-based macro &lt;CODE&gt;fieldA_or_fieldB(1)&lt;/CODE&gt; like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;if("$selection$"=="*", "fieldA", "fieldB")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then change your search to this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | stats sum(total_amount) by `fieldA_or_fieldB($your_token$)`
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;That'll select fieldA if your token has been set to &lt;CODE&gt;*&lt;/CODE&gt;, fieldB otherwise.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 00:14:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133045#M36331</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-08T00:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pass field value as macro name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133046#M36332</link>
      <description>&lt;P&gt;Hi Martin, here is my actual requirement.&lt;/P&gt;

&lt;P&gt;I have a drop down in my dashboard. I want to change the search query of the panel based on the option selected from drop down.&lt;/P&gt;

&lt;P&gt;If * (All) is selected from the drop down my search query should be  ...| stats sum(total_amount) by fieldA&lt;/P&gt;

&lt;P&gt;If any other value is selected from the drop down, my search query should be ..| stats sum(total_amount) by fieldB&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 00:41:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133046#M36332</guid>
      <dc:creator>pradeepkumarg</dc:creator>
      <dc:date>2014-07-08T00:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pass field value as macro name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133047#M36333</link>
      <description>&lt;P&gt;Is that the only purpose of the dropdown?&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 01:26:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133047#M36333</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-08T01:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pass field value as macro name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133048#M36334</link>
      <description>&lt;P&gt;Other panels in the dashboard as well use the same drop down to filter the data.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 01:46:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133048#M36334</guid>
      <dc:creator>pradeepkumarg</dc:creator>
      <dc:date>2014-07-08T01:46:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pass field value as macro name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133049#M36335</link>
      <description>&lt;P&gt;Okay, you can use an eval-based macro to decide the field name - this works because you're not actually deciding based on a field value but rather on a token. That's known and unique before running the search, so the macro substitution works. I've added an example to the answer above.&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 01:55:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133049#M36335</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2014-07-08T01:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: How can I pass field value as macro name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133050#M36336</link>
      <description>&lt;P&gt;Perfect. Thanks Martin!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jul 2014 15:14:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-pass-field-value-as-macro-name/m-p/133050#M36336</guid>
      <dc:creator>pradeepkumarg</dc:creator>
      <dc:date>2014-07-08T15:14:25Z</dc:date>
    </item>
  </channel>
</rss>

