<?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: Change table columns based on field value in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672464#M230338</link>
    <description>&lt;P&gt;Oh okay I just assumed it was a Splunk lookup. So if you are indexing the data from a CSV then you can probably do something like this (assuming field extractions are in place)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=&amp;lt;index&amp;gt; sourcetype=&amp;lt;sourcetype&amp;gt;
    | table
        [ 
            | makeresults
                | fields - _time
                | eval
                    ID=[ | search index=&amp;lt;index&amp;gt; sourcetype=&amp;lt;sourcetype&amp;gt; | stats latest(ID) as ID | return $ID ],
                    field_list_id_zero="NAME,STATUS,DATE,ACTION",
                    field_list_id_positive="DATE-Changed,ID,NAME,DATE_DOWN,ACTION",
                    final_field_list=if(
                        'ID'==0,
                            'field_list_id_zero',
                            'field_list_id_positive'
                            )
                    | fields + final_field_list
                    | return $final_field_list
                ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;where &amp;lt;index&amp;gt; and &amp;lt;sourcetype&amp;gt; is where your CSV is being indexed.&lt;/P&gt;</description>
    <pubDate>Thu, 21 Dec 2023 00:24:57 GMT</pubDate>
    <dc:creator>dtburrows3</dc:creator>
    <dc:date>2023-12-21T00:24:57Z</dc:date>
    <item>
      <title>Change table columns based on field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672458#M230335</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;I have a search question. I have a csv file that returnds data.&lt;/P&gt;&lt;P&gt;the ID field if there is no data - I want to have a table which shows 4 columns: NAME,STATUS,DATE,ACTION. These come from the csv file header line.&lt;/P&gt;&lt;P&gt;If the ID &amp;gt;0 I want to show these columns: DATE-Changed,ID,NAME,DATE_DOWN,ACTION. I have not yet seen how I might do this. What I need, in a sense, it two searches, one when ID=0, and one when ID&amp;gt;0. Any suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;EWHOLZ&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 23:21:26 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672458#M230335</guid>
      <dc:creator>eholz1</dc:creator>
      <dc:date>2023-12-20T23:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: Change table columns based on field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672462#M230336</link>
      <description>&lt;P&gt;Not sure exactly how your ID value is being derived in this situation but you may be able to utilize a subsearch holding you list of fields for each scenario and then set up an eval if() function to determine which to use based on the value in the ID field. Then with a return command you can return that conditional field list back into the parent search after a fields command.&lt;BR /&gt;&lt;BR /&gt;Something like this.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| inputlookup &amp;lt;lookup&amp;gt;
    | fields  
        [ 
            | makeresults
                | fields - _time
                | eval
                    ``` Not sure how the ID is being derived but there should be a variety of ways to get it here ```
                    ``` From lookup method ```
                    ```
                    ID=[ | inputlookup &amp;lt;lookup&amp;gt; | stats max(ID) as ID | return $ID ]
                    ```
                    ``` From token method ```
                    ```
                    ID=$ID_token$
                    ```
                    ``` This is hardcoded for a POC ```
                    ID=1,
                    field_list_id_zero="NAME,STATUS,DATE,ACTION",
                    field_list_id_positive="DATE-Changed,ID,NAME,DATE_DOWN,ACTION",
                    final_field_list=if(
                        'ID'==0,
                            'field_list_id_zero',
                            'field_list_id_positive'
                            )
                    | fields + final_field_list
                    | return $final_field_list
                ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Sample output when ID=0&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_0-1703115959337.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28615iD038F8C08F54EAA1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_0-1703115959337.png" alt="dtburrows3_0-1703115959337.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Sample output when ID&amp;gt;0&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dtburrows3_1-1703116011254.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/28616i04963DACBEDF93D9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dtburrows3_1-1703116011254.png" alt="dtburrows3_1-1703116011254.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2023 23:52:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672462#M230336</guid>
      <dc:creator>dtburrows3</dc:creator>
      <dc:date>2023-12-20T23:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change table columns based on field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672463#M230337</link>
      <description>&lt;P&gt;dtbur;rows3&lt;/P&gt;&lt;P&gt;Wow, fast reply. Thanks. The ID gets set when the csv file is written. I have a python program that queries a MySQL database, and writes a "0" as ID if no results are returned from the query. If there is data returned, the ID is taken from query results (i.e ID=34, etc). The csv file is on a remote server. I use the Splunk Universal Forwarder to send the file to splunk. Is there a way to get this file set as an "input lookup" or does the "input lookupo" required the file to be local to the Splunk server?&lt;/P&gt;&lt;P&gt;Thanks for quick help.&lt;/P&gt;&lt;P&gt;EWHolz&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 00:07:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672463#M230337</guid>
      <dc:creator>eholz1</dc:creator>
      <dc:date>2023-12-21T00:07:51Z</dc:date>
    </item>
    <item>
      <title>Re: Change table columns based on field value</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672464#M230338</link>
      <description>&lt;P&gt;Oh okay I just assumed it was a Splunk lookup. So if you are indexing the data from a CSV then you can probably do something like this (assuming field extractions are in place)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;index=&amp;lt;index&amp;gt; sourcetype=&amp;lt;sourcetype&amp;gt;
    | table
        [ 
            | makeresults
                | fields - _time
                | eval
                    ID=[ | search index=&amp;lt;index&amp;gt; sourcetype=&amp;lt;sourcetype&amp;gt; | stats latest(ID) as ID | return $ID ],
                    field_list_id_zero="NAME,STATUS,DATE,ACTION",
                    field_list_id_positive="DATE-Changed,ID,NAME,DATE_DOWN,ACTION",
                    final_field_list=if(
                        'ID'==0,
                            'field_list_id_zero',
                            'field_list_id_positive'
                            )
                    | fields + final_field_list
                    | return $final_field_list
                ]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;where &amp;lt;index&amp;gt; and &amp;lt;sourcetype&amp;gt; is where your CSV is being indexed.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2023 00:24:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Change-table-columns-based-on-field-value/m-p/672464#M230338</guid>
      <dc:creator>dtburrows3</dc:creator>
      <dc:date>2023-12-21T00:24:57Z</dc:date>
    </item>
  </channel>
</rss>

