<?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 add a  field to an extra column, depending on a condition? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429896#M174147</link>
    <description>&lt;P&gt;Thanks for this, but the columns for Target stayed empty .&lt;BR /&gt;
I changed the search to this and its working now:&lt;/P&gt;

&lt;P&gt;basesearch&lt;BR /&gt;
 | stats first(eval(if(&lt;STRONG&gt;like(Job_Type, "A%")&lt;/STRONG&gt;,Target,NULL))) as Startpoint first(eval(if(like(&lt;STRONG&gt;Job_Type, "B%")&lt;/STRONG&gt;,Target,NULL))) as Endpoint by ID&lt;/P&gt;</description>
    <pubDate>Wed, 12 Dec 2018 18:46:23 GMT</pubDate>
    <dc:creator>j_r</dc:creator>
    <dc:date>2018-12-12T18:46:23Z</dc:date>
    <item>
      <title>How can I add a  field to an extra column, depending on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429892#M174143</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;My log files look like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;       ID Job_Type Target
Event1    1  A     X
Event2    1  B     Y
Event3    2  A     X1
Event4    2  B     Y1
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;X/X1= Startpoint&lt;BR /&gt;
Y/Y1 = Endpoint&lt;/P&gt;

&lt;P&gt;Startpoint is defined by Job_Type. So if Job_Type = A, then Targe = Startpoint&lt;/P&gt;

&lt;P&gt;my search...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|basesearch
|stats values(Target) by ID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;...gives me the following results:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    ID  values(Target)
    ID1 Startpoint
         Endpoint
    ID2 Startpoint
         Endpoint
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;How can I add the "Target" field to an extra column, depending on whether it is Job_Type=A or Job_Type=B?&lt;/P&gt;

&lt;P&gt;Like this: &lt;CODE&gt;ID, Startpoint, Endpoint&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;I tried if-condition, but it didn't work.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:21:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429892#M174143</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2020-09-29T22:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a  field to an extra column, depending on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429893#M174144</link>
      <description>&lt;P&gt;@j_r Can you post a table of what your desired results should look like?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 18:02:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429893#M174144</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-12T18:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a  field to an extra column, depending on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429894#M174145</link>
      <description>&lt;P&gt;The result should looks like this (from example above):&lt;/P&gt;

&lt;P&gt;ID  Startpoint  Endpoint&lt;BR /&gt;
1      X                  Y&lt;BR /&gt;
2     X1                  Y1&lt;/P&gt;

&lt;P&gt;At the moment the results for Startpoint and endpoint are in the same column. I would like to have them in separate columns&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 18:13:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429894#M174145</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-12T18:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a  field to an extra column, depending on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429895#M174146</link>
      <description>&lt;P&gt;Hello @j_r,&lt;/P&gt;

&lt;P&gt;It should be possible by &lt;A href="https://docs.splunk.com/Documentation/Splunk/7.2.1/Search/Usestatswithevalexpressionsandfunctions"&gt;using stats with eval expressions&lt;/A&gt;.&lt;/P&gt;

&lt;P&gt;Using stats in combination with eval looks like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_* | stats count(eval(sourcetype=="splunkd")) as count_splunkd
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So in your case, try:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;basesearch
| stats first(eval(if(Job_Type=="A",Target,NULL))) as Startpoint first(eval(if(Job_Type=="B",Target,NULL))) as Endpoint by ID
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;You could use values() instead of first(), but there should only be one value.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 18:30:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429895#M174146</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-12T18:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a  field to an extra column, depending on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429896#M174147</link>
      <description>&lt;P&gt;Thanks for this, but the columns for Target stayed empty .&lt;BR /&gt;
I changed the search to this and its working now:&lt;/P&gt;

&lt;P&gt;basesearch&lt;BR /&gt;
 | stats first(eval(if(&lt;STRONG&gt;like(Job_Type, "A%")&lt;/STRONG&gt;,Target,NULL))) as Startpoint first(eval(if(like(&lt;STRONG&gt;Job_Type, "B%")&lt;/STRONG&gt;,Target,NULL))) as Endpoint by ID&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 18:46:23 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429896#M174147</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-12T18:46:23Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a  field to an extra column, depending on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429897#M174148</link>
      <description>&lt;P&gt;If i want to add another field to be displayed in the statistics, how do i do this?&lt;BR /&gt;
with: &lt;/P&gt;

&lt;P&gt;| table Startpoint, Endpoint, ID, Another_Field&lt;/P&gt;

&lt;P&gt;does not work.  Field stays empty&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 19:02:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429897#M174148</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-12T19:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a  field to an extra column, depending on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429898#M174149</link>
      <description>&lt;P&gt;It depends on what you want to do.&lt;BR /&gt;
However, the table command does not create any new fields.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 19:17:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429898#M174149</guid>
      <dc:creator>whrg</dc:creator>
      <dc:date>2018-12-12T19:17:55Z</dc:date>
    </item>
    <item>
      <title>Re: How can I add a  field to an extra column, depending on a condition?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429899#M174150</link>
      <description>&lt;P&gt;It worked by adding &lt;CODE&gt;values(another_field)&lt;/CODE&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Dec 2018 19:27:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-can-I-add-a-field-to-an-extra-column-depending-on-a/m-p/429899#M174150</guid>
      <dc:creator>j_r</dc:creator>
      <dc:date>2018-12-12T19:27:53Z</dc:date>
    </item>
  </channel>
</rss>

