<?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 Reference a calculated field within another calculated field in Knowledge Management</title>
    <link>https://community.splunk.com/t5/Knowledge-Management/Reference-a-calculated-field-within-another-calculated-field/m-p/438136#M3897</link>
    <description>&lt;P&gt;Is it possible to reference a calculated field within another calculated field?&lt;/P&gt;

&lt;P&gt;My original search query was:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval SourceServer=substr(source, 11, 6)
| eval SourceInstance=case(
     SourceServer=="AAA001", "PROD", 
     SourceServer=="AAA002", "PROD", 
     SourceServer=="BBB001", "UAT", 
     SourceServer=="BBB002", "UAT",
    1=1, "UNKNOWN")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My intention was to create two calculated fields. However, it doesn't look like SourceServer is processed before SourceInstance is, so all of the Events resolve to "UNKNOWN".&lt;/P&gt;

&lt;P&gt;My alternative is to repeat the same logic for each option in the case statement which seems pretty inefficient. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;SourceInstance&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;case(
     substr(source, 11, 6)=="AAA001", "PROD", 
     substr(source, 11, 6)=="AAA002", "PROD", 
     substr(source, 11, 6)=="BBB001", "UAT", 
     substr(source, 11, 6)=="BBB002", "UAT",
    1=1, "UNKNOWN")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I try to chain them together in a single field, like the simplified example below I get the error "Encountered the following error while trying to update: Unexpected token"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval foo=4 | eval bar=foo+4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there anyway to accomplish the logic of my original query without having to repeat the first query for every option of the case statement in the second query?&lt;/P&gt;</description>
    <pubDate>Thu, 02 May 2019 20:22:54 GMT</pubDate>
    <dc:creator>RWL01</dc:creator>
    <dc:date>2019-05-02T20:22:54Z</dc:date>
    <item>
      <title>Reference a calculated field within another calculated field</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Reference-a-calculated-field-within-another-calculated-field/m-p/438136#M3897</link>
      <description>&lt;P&gt;Is it possible to reference a calculated field within another calculated field?&lt;/P&gt;

&lt;P&gt;My original search query was:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval SourceServer=substr(source, 11, 6)
| eval SourceInstance=case(
     SourceServer=="AAA001", "PROD", 
     SourceServer=="AAA002", "PROD", 
     SourceServer=="BBB001", "UAT", 
     SourceServer=="BBB002", "UAT",
    1=1, "UNKNOWN")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;My intention was to create two calculated fields. However, it doesn't look like SourceServer is processed before SourceInstance is, so all of the Events resolve to "UNKNOWN".&lt;/P&gt;

&lt;P&gt;My alternative is to repeat the same logic for each option in the case statement which seems pretty inefficient. &lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;SourceInstance&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;case(
     substr(source, 11, 6)=="AAA001", "PROD", 
     substr(source, 11, 6)=="AAA002", "PROD", 
     substr(source, 11, 6)=="BBB001", "UAT", 
     substr(source, 11, 6)=="BBB002", "UAT",
    1=1, "UNKNOWN")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;When I try to chain them together in a single field, like the simplified example below I get the error "Encountered the following error while trying to update: Unexpected token"&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| eval foo=4 | eval bar=foo+4
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Is there anyway to accomplish the logic of my original query without having to repeat the first query for every option of the case statement in the second query?&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 20:22:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Reference-a-calculated-field-within-another-calculated-field/m-p/438136#M3897</guid>
      <dc:creator>RWL01</dc:creator>
      <dc:date>2019-05-02T20:22:54Z</dc:date>
    </item>
    <item>
      <title>Re: Reference a calculated field within another calculated field</title>
      <link>https://community.splunk.com/t5/Knowledge-Management/Reference-a-calculated-field-within-another-calculated-field/m-p/438137#M3898</link>
      <description>&lt;P&gt;Hi RWL01,&lt;/P&gt;

&lt;P&gt;there must be something wrong somewhere else, because both examples work fine here:&lt;/P&gt;

&lt;P&gt;First one:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval SourceServer=substr("ZZZZZZZZZZAAA001", 11, 6) 
| eval SourceInstance=case(
    SourceServer=="AAA001", "PROD", 
    SourceServer=="AAA002", "PROD", 
    SourceServer=="BBB001", "UAT", 
    SourceServer=="BBB002", "UAT",
    1=1, "UNKNOWN")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6975i31C9ABF89EC9C4C5/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;As well as the second one:&lt;/P&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/6976iDC7D90695E1D3093/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Thu, 02 May 2019 20:32:37 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Knowledge-Management/Reference-a-calculated-field-within-another-calculated-field/m-p/438137#M3898</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2019-05-02T20:32:37Z</dc:date>
    </item>
  </channel>
</rss>

