<?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 do I create a variable(or new field name) with its value another field name in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397469#M115371</link>
    <description>&lt;P&gt;helps thanks, But what if I did not know what the fieldname was e.g. successfullAttempts? I would not be able to hardcode it like that. &lt;/P&gt;

&lt;P&gt;let me try explain it better &lt;BR /&gt;
&lt;CODE&gt;index=core.... LABEL=successfullAttempts | timechart sum(kpi) as X by LABEL&lt;/CODE&gt;&lt;BR /&gt;
would give something like: &lt;/P&gt;

&lt;P&gt;_time successfullAttempts &lt;BR /&gt;
time1 val1&lt;BR /&gt;
..&lt;BR /&gt;
timeN valN&lt;/P&gt;

&lt;P&gt;Now I want to do something like: &lt;CODE&gt;eval Q = value(LABEL)&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;index=core.... LABEL=successfullAttempts | timechart sum(kpi) as X by LABEL | eval Q = value(LABEL)&lt;/CODE&gt;&lt;BR /&gt;
but that won't work, because I can't use &lt;CODE&gt;value()&lt;/CODE&gt; this wa way with eval.&lt;/P&gt;

&lt;P&gt;But what I would hope to endup with something like: &lt;/P&gt;

&lt;P&gt;_time successfullAttempts Q&lt;BR /&gt;
time1 val1 successfullAttempts &lt;BR /&gt;
..&lt;BR /&gt;
timeN valN successfullAttempts&lt;/P&gt;</description>
    <pubDate>Mon, 14 May 2018 23:34:10 GMT</pubDate>
    <dc:creator>HattrickNZ</dc:creator>
    <dc:date>2018-05-14T23:34:10Z</dc:date>
    <item>
      <title>how do I create a variable(or new field name) with its value another field name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397467#M115369</link>
      <description>&lt;P&gt;This is my sample search/data: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;  | makeresults 
     | eval data = "
     1    2017-12-01 00:00:00    A    0    131033    84.1;
    2    2017-12-01 00:30:00    B    0    23627    95;
    3    2017-12-01 00:45:00    C    0    117185    99.6;
    " 
     | makemv delim=";" data 
     | mvexpand data
     | rex field=data "(?&amp;lt;serial&amp;gt;\d)\s+(?&amp;lt;date&amp;gt;\d+-\d+-\d+ \d+:\d+:\d+)\s+(?&amp;lt;type&amp;gt;\w)\s+(?&amp;lt;attempts&amp;gt;\d+)\s+(?&amp;lt;successfullAttempts&amp;gt;\d+)\s+(?&amp;lt;sr&amp;gt;\d+)"
     | fields + date serial type attempts successfullAttempts sr 
     | rename date as _time 
     | search serial=*
 | eval x = "successfullAttempts"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;And this is what I want, just for illustration. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    _time   serial  type    attempts    successfullAttempts sr  x
1   2017-12-01 00:00:00 1   A   0   131033  84  successfullAttempts
2   2017-12-01 00:30:00 2   B   0   23627   95  successfullAttempts
3   2017-12-01 00:45:00 3   C   0   117185  99  successfullAttempts
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;But what I am trying to do is be able to get the field name e.g. successfullAttempts    as the value of another field name e.g. x.&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;So, given some data, how do I create a variable(or new field name) with its value another field name?&lt;/STRONG&gt;&lt;BR /&gt;
Hope that explains it. &lt;BR /&gt;
One option, that may or not help explain it, is to &lt;CODE&gt;appendcols [search .... | stats values(fieldnameThatHasTheValueOfInterest) as x]&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 03:22:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397467#M115369</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2018-05-14T03:22:10Z</dc:date>
    </item>
    <item>
      <title>Re: how do I create a variable(or new field name) with its value another field name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397468#M115370</link>
      <description>&lt;P&gt;I guess you want something like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval data = "
      1    2017-12-01 00:00:00    A    0    131033    84.1;
     2    2017-12-01 00:30:00    B    0    23627    95;
     3    2017-12-01 00:45:00    C    0    117185    99.6;
     " 
| makemv delim=";" data 
| mvexpand data 
| rex field=data "(?&amp;lt;serial&amp;gt;\d)\s+(?&amp;lt;date&amp;gt;\d+-\d+-\d+ \d+:\d+:\d+)\s+(?&amp;lt;type&amp;gt;\w)\s+(?&amp;lt;attempts&amp;gt;\d+)\s+(?&amp;lt;successfullAttempts&amp;gt;\d+)\s+(?&amp;lt;sr&amp;gt;\d+)" 
| fields + date serial type attempts successfullAttempts sr 
| rename date as _time 
| search serial=* 
| append 
    [| makeresults 
    | eval failed="1"] 
| eval x =case(successfullAttempts&amp;gt;0,"successfullAttempts",failed&amp;gt;0,"failedAttempts")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;let me know if this helps!&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 05:11:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397468#M115370</guid>
      <dc:creator>mayurr98</dc:creator>
      <dc:date>2018-05-14T05:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: how do I create a variable(or new field name) with its value another field name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397469#M115371</link>
      <description>&lt;P&gt;helps thanks, But what if I did not know what the fieldname was e.g. successfullAttempts? I would not be able to hardcode it like that. &lt;/P&gt;

&lt;P&gt;let me try explain it better &lt;BR /&gt;
&lt;CODE&gt;index=core.... LABEL=successfullAttempts | timechart sum(kpi) as X by LABEL&lt;/CODE&gt;&lt;BR /&gt;
would give something like: &lt;/P&gt;

&lt;P&gt;_time successfullAttempts &lt;BR /&gt;
time1 val1&lt;BR /&gt;
..&lt;BR /&gt;
timeN valN&lt;/P&gt;

&lt;P&gt;Now I want to do something like: &lt;CODE&gt;eval Q = value(LABEL)&lt;/CODE&gt;&lt;BR /&gt;
&lt;CODE&gt;index=core.... LABEL=successfullAttempts | timechart sum(kpi) as X by LABEL | eval Q = value(LABEL)&lt;/CODE&gt;&lt;BR /&gt;
but that won't work, because I can't use &lt;CODE&gt;value()&lt;/CODE&gt; this wa way with eval.&lt;/P&gt;

&lt;P&gt;But what I would hope to endup with something like: &lt;/P&gt;

&lt;P&gt;_time successfullAttempts Q&lt;BR /&gt;
time1 val1 successfullAttempts &lt;BR /&gt;
..&lt;BR /&gt;
timeN valN successfullAttempts&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 23:34:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397469#M115371</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2018-05-14T23:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: how do I create a variable(or new field name) with its value another field name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397470#M115372</link>
      <description>&lt;P&gt;basically &lt;BR /&gt;
&lt;CODE&gt;index=core.... LABEL=successfullAttempts | timechart sum(kpi) as X value(LABEL) as LABEL by LABEL |&lt;/CODE&gt;&lt;BR /&gt;
will get me what I want. But then I want to do a &lt;CODE&gt;timewrap&lt;/CODE&gt; after this but I just want to do it on the 1 column e.g. X. which is related to a question I have asked on this &lt;A href="https://answers.splunk.com/answers/659220/can-i-just-do-a-timewrap-on-just-1-fieldcolumn.html"&gt;here&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;OR &lt;BR /&gt;
after the timewrap, which I don't think can work on just 1 column I could do the following:&lt;BR /&gt;
just append the column I want with the 1 value I want in the column. &lt;BR /&gt;
&lt;CODE&gt;...  appendcols [ search &lt;BR /&gt;
  index=core ... | stats values(LABEL) as LABEL  ] | eventstats max(LABEL) as LABEL&lt;/CODE&gt;&lt;BR /&gt;
Was just hoping there was a better way than this.&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 00:35:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397470#M115372</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2018-05-21T00:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: how do I create a variable(or new field name) with its value another field name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397471#M115373</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Use the value of one field as the name for a new field&lt;/STRONG&gt;&lt;BR /&gt;
In this example, use each value of the field counter to make a new field name. Assign to the new field the value of the Value field. See Field names under the Usage section.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=perfmon sourcetype=Perfmon* counter=* Value=* | eval {counter} = Value
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;A href="https://answers.splunk.com/answers/658830/how-do-i-create-a-variableor-new-field-name-with-i.html"&gt;Link to the documentation on this topic.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 01:23:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397471#M115373</guid>
      <dc:creator>kmorris_splunk</dc:creator>
      <dc:date>2018-05-21T01:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: how do I create a variable(or new field name) with its value another field name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397472#M115374</link>
      <description>&lt;P&gt;tks, I don't see any new fields in my &lt;CODE&gt;Interesting fields&lt;/CODE&gt; list.&lt;BR /&gt;
also that link is to this page.&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 02:02:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/397472#M115374</guid>
      <dc:creator>HattrickNZ</dc:creator>
      <dc:date>2018-05-21T02:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: how do I create a variable(or new field name) with its value another field name</title>
      <link>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/690332#M235135</link>
      <description>&lt;P&gt;thanks, saved me loads of redundant coding!&lt;BR /&gt;&lt;BR /&gt;i.e. elegant new solution setting dashboard tokens:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;| sort 0 area -error_rate | dedup area
| eval x=area+"_service_id" | eval {x} = service_id | fields - x service_id
| eval x=area+"_service" | eval {x} = service | fields - x service
| eval x=area+"_value" | eval {x} = error_rate | fields - x error_rate
| eval x=area+"_color" | eval {x} = color | fields - x color
| fields - area _time
| stats values(*) as *&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 11 Jun 2024 14:02:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/how-do-I-create-a-variable-or-new-field-name-with-its-value/m-p/690332#M235135</guid>
      <dc:creator>carbdb</dc:creator>
      <dc:date>2024-06-11T14:02:50Z</dc:date>
    </item>
  </channel>
</rss>

