<?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: Removing null columns from a table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136455#M37326</link>
    <description>&lt;P&gt;This should be a comment to the mentioned answer rather than another 'answer'. Very misleading as the order of answers changes.&lt;/P&gt;</description>
    <pubDate>Mon, 27 Aug 2018 07:18:01 GMT</pubDate>
    <dc:creator>romanwaldecker</dc:creator>
    <dc:date>2018-08-27T07:18:01Z</dc:date>
    <item>
      <title>Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136444#M37315</link>
      <description>&lt;P&gt;I've found some previous posts with similar questions but the results dont seem to be correct so I'm hoping someone can help with this one...&lt;/P&gt;

&lt;P&gt;I have something like this: &lt;BR /&gt;
mysearch | table column1 column2 column3&lt;/P&gt;

&lt;P&gt;With results like this:&lt;BR /&gt;
column1 --- column2 --- column 3&lt;BR /&gt;
asdfasdf --- 123456&lt;BR /&gt;
bsdfasdf --- 234567&lt;BR /&gt;
csdfasdf --- 345678&lt;/P&gt;

&lt;P&gt;Sometimes column3 will have data, sometimes it wont. How (after piping to table) can I remove column3 if it has no data (and preferably keep the columns in order as well)? Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 14:44:30 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136444#M37315</guid>
      <dc:creator>hogan24</dc:creator>
      <dc:date>2015-06-04T14:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136445#M37316</link>
      <description>&lt;P&gt;So when you do the search column 3 sometimes contains data and other times it doesn't, and when it doesn't the column should be removed?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 14:48:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136445#M37316</guid>
      <dc:creator>MichaelPriest</dc:creator>
      <dc:date>2015-06-04T14:48:45Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136446#M37317</link>
      <description>&lt;P&gt;Correct. This is for a dashboard view that I will be turning over to users so I want to simplify the view if a column does not have data. &lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 15:21:10 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136446#M37317</guid>
      <dc:creator>hogan24</dc:creator>
      <dc:date>2015-06-04T15:21:10Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136447#M37318</link>
      <description>&lt;P&gt;If you don't want to show column 3, don't include it in your &lt;CODE&gt;table&lt;/CODE&gt; command.&lt;/P&gt;

&lt;P&gt;Other than that, how do you think it would work? You can either have a column or don't have it, but you can't have it in some results only - although in a way, that is exactly what happens with a row which is empty in column 3 - it doesn't have a value for column 3. If you could try to show me an example of how the table would look like the way you want it, that would be great.&lt;/P&gt;

&lt;P&gt;If you don't want to display empty fields, you could use&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your search | table column1 column2 column3 | fillnull column3 ("No entry for column 3")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;to have them display that text instead.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 15:21:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136447#M37318</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-06-04T15:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136448#M37319</link>
      <description>&lt;P&gt;@jeffland, this is a comment, not an answer. can you delete this as an answer?&lt;/P&gt;

&lt;P&gt;"...how do you think it would work?"  That's what i'm asking.&lt;/P&gt;

&lt;P&gt;I want to include it in the table b/c it may have data. I want to include all columns that may have data. Then remove the column if it does not have data.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 16:32:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136448#M37319</guid>
      <dc:creator>hogan24</dc:creator>
      <dc:date>2015-06-04T16:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136449#M37320</link>
      <description>&lt;P&gt;This works...&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; your search | fields column1 column2 column3 | table * | fields - _*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;However, do you really need to pipe to table?&lt;/P&gt;

&lt;P&gt;If you just show events and &lt;EM&gt;format&lt;/EM&gt; it as a table, then the extra column would disappear. In the search, you can select "Table" on the events tab.  Unfortunately, if you save this as a dashboard panel the settings are getting lost. In SimpleXML, here are the settings you need:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;panel&amp;gt;
  &amp;lt;event&amp;gt;
    &amp;lt;search&amp;gt;
      &amp;lt;query&amp;gt;your search&amp;lt;/query&amp;gt;
    &amp;lt;/search&amp;gt;
    &amp;lt;option name="count"&amp;gt;10&amp;lt;/option&amp;gt;
    &amp;lt;option name="rowNumbers"&amp;gt;0&amp;lt;/option&amp;gt;
    &amp;lt;option name="type"&amp;gt;table&amp;lt;/option&amp;gt;
    &amp;lt;fields&amp;gt;column1, column2, column3&amp;lt;/fields&amp;gt;
  &amp;lt;/event&amp;gt;
&amp;lt;/panel&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note, this method would also include _time.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jun 2015 20:15:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136449#M37320</guid>
      <dc:creator>mrobichaud_splu</dc:creator>
      <dc:date>2015-06-04T20:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136450#M37321</link>
      <description>&lt;P&gt;Let me rephrase that question: What do you want to see?&lt;/P&gt;

&lt;P&gt;I can't imagine how a table would look that has a third column sometimes and sometimes it doesn't. Should the first page of results contain such a column while the second page doesn't?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Jun 2015 05:15:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136450#M37321</guid>
      <dc:creator>jeffland</dc:creator>
      <dc:date>2015-06-05T05:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136451#M37322</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;mysearch | table column1 column2 column3
| streamstats count as temp_count
| stats values(*) as * by temp_count
| fields - temp_count
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The streamstats gives each row a unique number&lt;BR /&gt;
The stats values will remove null columns&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2015 16:39:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136451#M37322</guid>
      <dc:creator>pj</dc:creator>
      <dc:date>2015-12-22T16:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136452#M37323</link>
      <description>&lt;P&gt;Above answer is not working in splunk 6.5 version&lt;/P&gt;</description>
      <pubDate>Wed, 08 Feb 2017 07:40:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136452#M37323</guid>
      <dc:creator>arorarahul23</dc:creator>
      <dc:date>2017-02-08T07:40:00Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136453#M37324</link>
      <description>&lt;P&gt;Here's  a solution that eliminates empty columns AND keeps the order of the columns. As table is often used to define the order of fields, keeping it is essential.  Tested about a dozen possibilities and the only generic one I found  (where you don't have to know the column names) is using transpose, which eliminates empty columns when creating rows of it:&lt;BR /&gt;
`| makeresults count=3&lt;BR /&gt;
| rename comment as "generate some test data"&lt;BR /&gt;
| streamstats count&lt;BR /&gt;
| eval f2=if(count=2,"YYY",null), f3=if(count=3,"ZZZ",""),f5="XXX",f6=null&lt;BR /&gt;
| rename comment as "f1, f4 and f6 have no values in any row"&lt;BR /&gt;
| table f6 f5 f4 f3 f1 f2 count&lt;/P&gt;

&lt;P&gt;| rename comment as "now the transpose magic"&lt;BR /&gt;
| transpose &lt;BR /&gt;
| transpose header_field=column&lt;BR /&gt;
| fields - column` &lt;/P&gt;</description>
      <pubDate>Thu, 23 Nov 2017 19:39:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136453#M37324</guid>
      <dc:creator>jonasmeier</dc:creator>
      <dc:date>2017-11-23T19:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136454#M37325</link>
      <description>&lt;P&gt;Awesome answer - simple and works very well! Should be accepted as the right answer imho.&lt;BR /&gt;
The only downside to consider: The transpose commands demand a lot of computing power = time.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Feb 2018 08:04:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136454#M37325</guid>
      <dc:creator>romanwaldecker</dc:creator>
      <dc:date>2018-02-09T08:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136455#M37326</link>
      <description>&lt;P&gt;This should be a comment to the mentioned answer rather than another 'answer'. Very misleading as the order of answers changes.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Aug 2018 07:18:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136455#M37326</guid>
      <dc:creator>romanwaldecker</dc:creator>
      <dc:date>2018-08-27T07:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136456#M37327</link>
      <description>&lt;P&gt;There's a simple way to remove columns with all null values using foreach:&lt;/P&gt;

&lt;P&gt;if you have cols a, b and c and c has all NULL values:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults 
| eval a=10
| eval b=20
| eval c=30
| append 
    [
    | makeresults
    | eval a=100
    | eval b=200
    | eval c=300
    ]
| append 
    [
    | makeresults
    | eval a=1000
    | eval b=2000
    | eval c=3000
    ]
| table a b c
| eval c=NULL
| rename * AS X_*_NEW
| foreach X_*_NEW 
    [ eval &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; ]
| fields - X*
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;will leave cols a and b, as during the eval Splunk removes any col which is all NULL values.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2019 08:10:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136456#M37327</guid>
      <dc:creator>jadomaai</dc:creator>
      <dc:date>2019-10-16T08:10:57Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136457#M37328</link>
      <description>&lt;P&gt;This solution does not work for every possibility. e.g. I am tabling winevent data for multiple eventcodes. It seems that if a field has null data for just one data point, when the rest are populated, then that entire field is not displayed. Have tried this every way I can and it still excludes multiple fields of mine that contain data.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 00:48:27 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136457#M37328</guid>
      <dc:creator>nick405060</dc:creator>
      <dc:date>2020-01-08T00:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136458#M37329</link>
      <description>&lt;P&gt;This reorders your columns so in a dashboard it is not much of a solution &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 00:50:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136458#M37329</guid>
      <dc:creator>nick405060</dc:creator>
      <dc:date>2020-01-08T00:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136459#M37330</link>
      <description>&lt;P&gt;This also reorders your results&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 00:59:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136459#M37330</guid>
      <dc:creator>nick405060</dc:creator>
      <dc:date>2020-01-08T00:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136460#M37331</link>
      <description>&lt;P&gt;Bumping this.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 21:38:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136460#M37331</guid>
      <dc:creator>nick405060</dc:creator>
      <dc:date>2020-01-08T21:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136461#M37332</link>
      <description>&lt;P&gt;Fair point about the order.  Hadn't picked up on that constraint.  Can't find a way to preserve the order when running a search in the search editor, but have a solution for a dashboard context by virtue of using a token to preserve the desired order.  Arguably, this shouldn't work, as we're effectively 're-creating' the lost columns by running the tokenized fields command (try opening the second panel's search in the search editor to see what I mean)... but for some reason this works in the context of the dashboard.  For anyone who doesn't have access to _internal index, substitute your own search and modify the relevant commands in the base search to make the following work&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;dashboard&amp;gt;
  &amp;lt;label&amp;gt;remove_null_cols_and_keep_column_order&amp;lt;/label&amp;gt;
  &amp;lt;search id="baseSearch"&amp;gt;
    &amp;lt;query&amp;gt;
      index=_internal sourcetype=scheduler earliest=-1m
    | table _time host user concurrency_category status scheduled_time run_time result_count
    | eval user = NULL
    | eval scheduled_time = NULL
    | eval _flds = "| fields _time host user concurrency_category status scheduled_time run_time result_count"
    &amp;lt;/query&amp;gt;
    &amp;lt;done&amp;gt;
      &amp;lt;condition match="$job.resultCount$!=0"&amp;gt;
        &amp;lt;set token="displayFieldsInOrder_tok"&amp;gt;$result._flds$&amp;lt;/set&amp;gt;
      &amp;lt;/condition&amp;gt;
    &amp;lt;/done&amp;gt;
    &amp;lt;sampleRatio&amp;gt;1&amp;lt;/sampleRatio&amp;gt;
  &amp;lt;/search&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Original table of results showing all columns including 'user' and 'scheduled_time' which are set to all NULL values&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search base="baseSearch"&amp;gt;&amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;5&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;false&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
  &amp;lt;row&amp;gt;
    &amp;lt;panel&amp;gt;
      &amp;lt;title&amp;gt;Results after removing NULL cols&amp;lt;/title&amp;gt;
      &amp;lt;table&amp;gt;
        &amp;lt;search base="baseSearch"&amp;gt;
          &amp;lt;query&amp;gt;
            &amp;lt;![CDATA[
               | rename * AS X_*_NEW
               | foreach X_*_NEW 
               [ eval &amp;lt;&amp;lt;MATCHSTR&amp;gt;&amp;gt;=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt; ]
                 $displayFieldsInOrder_tok$
               ]]&amp;gt;
          &amp;lt;/query&amp;gt;
        &amp;lt;/search&amp;gt;
        &amp;lt;option name="count"&amp;gt;5&amp;lt;/option&amp;gt;
        &amp;lt;option name="dataOverlayMode"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="drilldown"&amp;gt;none&amp;lt;/option&amp;gt;
        &amp;lt;option name="percentagesRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="rowNumbers"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="totalsRow"&amp;gt;false&amp;lt;/option&amp;gt;
        &amp;lt;option name="wrap"&amp;gt;false&amp;lt;/option&amp;gt;
      &amp;lt;/table&amp;gt;
    &amp;lt;/panel&amp;gt;
  &amp;lt;/row&amp;gt;
&amp;lt;/dashboard&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Jan 2020 23:20:43 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136461#M37332</guid>
      <dc:creator>jadomaai</dc:creator>
      <dc:date>2020-01-08T23:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136462#M37333</link>
      <description>&lt;P&gt;To you perhaps, but the question only expressed a preference to keep the order, it wasn't mandated.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 02:10:04 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136462#M37333</guid>
      <dc:creator>pj</dc:creator>
      <dc:date>2020-01-09T02:10:04Z</dc:date>
    </item>
    <item>
      <title>Re: Removing null columns from a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136463#M37334</link>
      <description>&lt;P&gt;Use | transpose 0, which indicates that the number of rows to transpose is unlimited. (and be carefull with event counts &amp;gt; 10000, it trashed my browser)&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 07:53:05 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Removing-null-columns-from-a-table/m-p/136463#M37334</guid>
      <dc:creator>jonasmeier</dc:creator>
      <dc:date>2020-01-09T07:53:05Z</dc:date>
    </item>
  </channel>
</rss>

