<?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: Get total number of columns in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300338#M3860</link>
    <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/66281"&gt;@vinod94&lt;/a&gt;, what is your existing chart command that you have used? It is possible that you can have the total_date_columns value calculated in the chart command itself. Also once you get the &lt;CODE&gt;total_date_columns&lt;/CODE&gt;, what is the next thing you would want to do?&lt;/P&gt;

&lt;P&gt;I would also use foreach command. But, here is a run anywhere search with Splunk's _internal index and &lt;CODE&gt;transpose&lt;/CODE&gt;, &lt;CODE&gt;addtotals&lt;/CODE&gt; and filldown commands. This is just to document an alternative approach:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level!="INFO"
| eval Dates=strftime(_time,"%Y/%m/%d")
| chart count over Dates by component useother=f usenull=f
| eval total_date_columns=1
| transpose 0 header_field="Dates" column_name="Dates"
| addtotals row=t col=f fieldname="total_date_columns"
| eval total_date_columns=case(Dates=="total_date_columns",total_date_columns)
| reverse
| filldown total_date_columns
| search Dates!="total_date_columns"
| reverse
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 18:50:40 GMT</pubDate>
    <dc:creator>niketn</dc:creator>
    <dc:date>2020-09-29T18:50:40Z</dc:date>
    <item>
      <title>Get total number of columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300336#M3858</link>
      <description>&lt;PRE&gt;&lt;CODE&gt;  assigned 2018-02-06   2018-02-08  2018-02-13  2018-02-15  
     4            0          0              0          0
     9            0          0              0          0
    10            1          0              0          0
    11            1          0              0          0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;where the above date values are present in a field called DATES. I have used chart command to get the above table.&lt;BR /&gt;
I want to create a new column which should give me the total number of date columns.Here, I have 4 dates in my column so the output should look like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    assigned 2018-02-06   2018-02-08    2018-02-13  2018-02-15  total_date_columns
     4            0          0              0          0               4
     9            0          0              0          0               4
    10            1          0              0          0               4
    11            1          0              0          0               4
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Apr 2018 12:20:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300336#M3858</guid>
      <dc:creator>vinod94</dc:creator>
      <dc:date>2018-04-02T12:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: Get total number of columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300337#M3859</link>
      <description>&lt;P&gt;Assuming the date columns will always take that format, this should work:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search
| eval total_date_columns=0
| foreach 2018* 
 [ total_date_columns=total_date_columns+1 ]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 02 Apr 2018 14:23:51 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300337#M3859</guid>
      <dc:creator>elliotproebstel</dc:creator>
      <dc:date>2018-04-02T14:23:51Z</dc:date>
    </item>
    <item>
      <title>Re: Get total number of columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300338#M3860</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/66281"&gt;@vinod94&lt;/a&gt;, what is your existing chart command that you have used? It is possible that you can have the total_date_columns value calculated in the chart command itself. Also once you get the &lt;CODE&gt;total_date_columns&lt;/CODE&gt;, what is the next thing you would want to do?&lt;/P&gt;

&lt;P&gt;I would also use foreach command. But, here is a run anywhere search with Splunk's _internal index and &lt;CODE&gt;transpose&lt;/CODE&gt;, &lt;CODE&gt;addtotals&lt;/CODE&gt; and filldown commands. This is just to document an alternative approach:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_internal sourcetype=splunkd log_level!="INFO"
| eval Dates=strftime(_time,"%Y/%m/%d")
| chart count over Dates by component useother=f usenull=f
| eval total_date_columns=1
| transpose 0 header_field="Dates" column_name="Dates"
| addtotals row=t col=f fieldname="total_date_columns"
| eval total_date_columns=case(Dates=="total_date_columns",total_date_columns)
| reverse
| filldown total_date_columns
| search Dates!="total_date_columns"
| reverse
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 18:50:40 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300338#M3860</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2020-09-29T18:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: Get total number of columns</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300339#M3861</link>
      <description>&lt;P&gt;Thanks,  it worked!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 06:00:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Get-total-number-of-columns/m-p/300339#M3861</guid>
      <dc:creator>vinod94</dc:creator>
      <dc:date>2018-04-03T06:00:28Z</dc:date>
    </item>
  </channel>
</rss>

