<?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: Using field names as variable in column name in Dashboards &amp; Visualizations</title>
    <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682663#M55878</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236540"&gt;@deepdive100&lt;/a&gt;.,&lt;/P&gt;&lt;P&gt;You can create the column name based on what the field "&lt;EM&gt;name"&lt;/EM&gt; is set to using &lt;EM&gt;by&lt;/EM&gt;:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults
|eval sample="100"
|eval name=if(sample=100,"C",N/A)
|timechart max(sample) by name&lt;/LI-CODE&gt;&lt;P&gt;This creates a table with columns: _time, C. If the values are less or more than 100, there'll be an additional column "&lt;EM&gt;N/A&lt;/EM&gt;"&lt;/P&gt;&lt;P&gt;If you have a dashboard and you want to pick which column is displayed, you could do something like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults
|eval sample="100"
|eval name=if(sample=100,"$DROPDOWN_TOKEN$",N/A)
|timechart max(sample) by name&lt;/LI-CODE&gt;&lt;P&gt;And set up an input that sets the token $DROPDOWN_TOKEN$.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Apr 2024 22:02:57 GMT</pubDate>
    <dc:creator>danspav</dc:creator>
    <dc:date>2024-04-01T22:02:57Z</dc:date>
    <item>
      <title>Using field names as variable in column name</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682660#M55877</link>
      <description>&lt;P&gt;I have a timechart that I want a column name to reflect a field name like how a variable or token would be used.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;```Example```
|makeresults
|eval sample="100"
|eval name=if(sample=100,"C",N/A)
|timechart max(sample) as $name$

```Expected Outcome would by a timechart with column named "C"```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible?&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 21:45:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682660#M55877</guid>
      <dc:creator>deepdive100</dc:creator>
      <dc:date>2024-04-01T21:45:21Z</dc:date>
    </item>
    <item>
      <title>Re: Using field names as variable in column name</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682663#M55878</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/236540"&gt;@deepdive100&lt;/a&gt;.,&lt;/P&gt;&lt;P&gt;You can create the column name based on what the field "&lt;EM&gt;name"&lt;/EM&gt; is set to using &lt;EM&gt;by&lt;/EM&gt;:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults
|eval sample="100"
|eval name=if(sample=100,"C",N/A)
|timechart max(sample) by name&lt;/LI-CODE&gt;&lt;P&gt;This creates a table with columns: _time, C. If the values are less or more than 100, there'll be an additional column "&lt;EM&gt;N/A&lt;/EM&gt;"&lt;/P&gt;&lt;P&gt;If you have a dashboard and you want to pick which column is displayed, you could do something like:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;|makeresults
|eval sample="100"
|eval name=if(sample=100,"$DROPDOWN_TOKEN$",N/A)
|timechart max(sample) by name&lt;/LI-CODE&gt;&lt;P&gt;And set up an input that sets the token $DROPDOWN_TOKEN$.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2024 22:02:57 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682663#M55878</guid>
      <dc:creator>danspav</dc:creator>
      <dc:date>2024-04-01T22:02:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using field names as variable in column name</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682768#M55884</link>
      <description>&lt;P&gt;Hi Thanks.&amp;nbsp;This is almost what I need. I think I need to expand on my requirements a bit more.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;```Example```
|makeresults
|eval sample="100"
|eval perc="45"
|eval name=if(sample=100,"C",N/A)
|timechart max(sample) as "The Sample yields $name$", avg(perc) as "percentage"

```Expected Outcome would by a timechart with column named "The Sample yields C" and another column titled "percentage"```&lt;/LI-CODE&gt;&lt;P&gt;Using the BY clause appends that eval'd field in the column name, but not all columns need that field name.&lt;BR /&gt;I'd think that the easiest way about doing it would be some type of variable replacement but it seems that the AS clause does not allow that.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2024 15:23:39 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682768#M55884</guid>
      <dc:creator>deepdive100</dc:creator>
      <dc:date>2024-04-02T15:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Using field names as variable in column name</title>
      <link>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682945#M55890</link>
      <description>&lt;P&gt;I think I understand -&amp;nbsp; try this search to create a table with fields: _time, percentage and one or more columns based on the value calculated each hour:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| gentimes start=-7
| eval sample=random()%100
| eval perc=random()%50
| rename starttime as _time
| append[|makeresults | eval sample=100, perc=45| table _time, sample, perc]
| timechart span=1d max(sample) as name, avg(perc) as "percentage"

``` Calculate how we name the fields based on the value of: name ```
| eval rename_field_to=if(name=100,"C","N/A")
| eval "The Sample Yields {rename_field_to}" = name
| fields - rename_field_to, name&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This will create three or four columns:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;_time = time&lt;/LI&gt;&lt;LI&gt;percentage = hourly average of the perc field&lt;/LI&gt;&lt;LI&gt;The Sample Yields C&amp;nbsp; =&amp;nbsp; If the max for that hour was 100&lt;/LI&gt;&lt;LI&gt;The Sample Yields N/A = If the max for that hour was not 100&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;If you only want "The Sample Yields C" or nothing, then you can filter out with a &lt;EM&gt;| search name="C"&lt;/EM&gt; after the timechart command.&lt;BR /&gt;&lt;BR /&gt;The main SPL is :&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| eval "The Sample Yields {rename_field_to}" = name&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;That will allow you to name a field using the value of another field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want NA to simply be N/A then you can do a rename:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| rename "The Sample Yields N/A" as "N/A"&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Is that closer to what you were after?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Apr 2024 03:56:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Dashboards-Visualizations/Using-field-names-as-variable-in-column-name/m-p/682945#M55890</guid>
      <dc:creator>danspav</dc:creator>
      <dc:date>2024-04-03T03:56:31Z</dc:date>
    </item>
  </channel>
</rss>

