<?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 How to get a calculated column in a table in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371294#M165856</link>
    <description>&lt;P&gt;Hi Splunk Experts,&lt;BR /&gt;
  I need to create a report to display the table record count difference between two databases during a period of time.&lt;/P&gt;

&lt;P&gt;Events (list) are captured as follow:&lt;BR /&gt;
db_name  table_name row_count&lt;BR /&gt;
x                 a                    4&lt;BR /&gt;
x                 b                    3&lt;BR /&gt;
y                 a                    4&lt;BR /&gt;
y                 b                    1&lt;/P&gt;

&lt;P&gt;Report should look like this:&lt;/P&gt;

&lt;P&gt;table_name     x               y          rec_diff &lt;BR /&gt;
a                        4              4           0&lt;BR /&gt;
b                        3              1           2&lt;/P&gt;

&lt;P&gt;Any help will be very appreciated.&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 16:03:45 GMT</pubDate>
    <dc:creator>romoc</dc:creator>
    <dc:date>2020-09-29T16:03:45Z</dc:date>
    <item>
      <title>How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371294#M165856</link>
      <description>&lt;P&gt;Hi Splunk Experts,&lt;BR /&gt;
  I need to create a report to display the table record count difference between two databases during a period of time.&lt;/P&gt;

&lt;P&gt;Events (list) are captured as follow:&lt;BR /&gt;
db_name  table_name row_count&lt;BR /&gt;
x                 a                    4&lt;BR /&gt;
x                 b                    3&lt;BR /&gt;
y                 a                    4&lt;BR /&gt;
y                 b                    1&lt;/P&gt;

&lt;P&gt;Report should look like this:&lt;/P&gt;

&lt;P&gt;table_name     x               y          rec_diff &lt;BR /&gt;
a                        4              4           0&lt;BR /&gt;
b                        3              1           2&lt;/P&gt;

&lt;P&gt;Any help will be very appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:03:45 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371294#M165856</guid>
      <dc:creator>romoc</dc:creator>
      <dc:date>2020-09-29T16:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371295#M165857</link>
      <description>&lt;P&gt;|chart values(row_count) over table_name by  db_name |eval rec_diff=x-y|table table_name * rec_diff&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:00:06 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371295#M165857</guid>
      <dc:creator>xisura</dc:creator>
      <dc:date>2020-09-29T16:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371296#M165858</link>
      <description>&lt;P&gt;@romoc, does your table always have 4 rows? Will it have only two rows for specific table_name one for each x and y? If not please add more sample data and correlation. If so following answer by @xisura should work.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 03:12:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371296#M165858</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-02T03:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371297#M165859</link>
      <description>&lt;P&gt;Hi Niketnilay,&lt;BR /&gt;
   That was just a sample of records - there would be more tables to compare and the list could grow over the time. What is a fact, there would be always two databases to compare  - x and y in this case.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 16:57:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371297#M165859</guid>
      <dc:creator>romoc</dc:creator>
      <dc:date>2017-10-02T16:57:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371298#M165860</link>
      <description>&lt;P&gt;Thanks Xisure - I tried your suggestion but it get no results found. By the way, x and y are the possible values for field db_name so, I'm not sure if the eval function is expressed correctly. For example, this is in fact how some events (from all the list of possible events) look like:&lt;/P&gt;

&lt;P&gt;DB_NAME="x", TABLE_NAME="a", SNAP_DATE="2017-09-30 21:17:16.267", ROW_COUNT="183"&lt;BR /&gt;
DB_NAME="y", TABLE_NAME="a", SNAP_DATE="2017-10-01 01:12:35.0", ROW_COUNT="180"&lt;BR /&gt;
DB_NAME="y", TABLE_NAME="b", SNAP_DATE="2017-09-30 21:17:16.267", ROW_COUNT="1731"&lt;BR /&gt;
DB_NAME="x", TABLE_NAME="b", SNAP_DATE="2017-10-01 01:12:35.0", ROW_COUNT="1738"&lt;/P&gt;

&lt;P&gt;I will appreciate any help.&lt;/P&gt;

&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:00:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371298#M165860</guid>
      <dc:creator>romoc</dc:creator>
      <dc:date>2020-09-29T16:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371299#M165861</link>
      <description>&lt;P&gt;If that is the case, the answer by @xisura should work. Please try out and confirm.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 17:25:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371299#M165861</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-02T17:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371300#M165862</link>
      <description>&lt;P&gt;Thanks xisura - I tried your suggestion but unfortunately I get "no results found". I want to clarify also that x and y are the two possible values for db_name and I'm not sure if function eval rec_diff=x-y would work. This is a sample of 4 events captured: &lt;/P&gt;

&lt;P&gt;2017-10-01 01:47:16.541, DB_NAME="x", TABLE_NAME="a", SNAP_DATE="2017-09-30 21:47:16.2", ROW_COUNT="183"&lt;BR /&gt;
2017-10-01 01:42:36.069, DB_NAME="y", TABLE_NAME="a", SNAP_DATE="2017-10-01 01:42:35.0", ROW_COUNT="183"&lt;BR /&gt;
2017-10-01 01:47:16.541, DB_NAME="x", TABLE_NAME="b", SNAP_DATE="2017-09-30 21:47:16.2", ROW_COUNT="1731"&lt;BR /&gt;
2017-10-01 01:42:36.069, DB_NAME="y", TABLE_NAME="b", SNAP_DATE="2017-10-01 01:42:35.0", ROW_COUNT="1738"&lt;/P&gt;

&lt;P&gt;I'll appreciate any help on this.&lt;BR /&gt;
Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:00:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371300#M165862</guid>
      <dc:creator>romoc</dc:creator>
      <dc:date>2020-09-29T16:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371301#M165863</link>
      <description>&lt;P&gt;Hi Niketnilay - I just replied @xisura. I'm not getting the expected results yet and provided further details. Hope you could have any other suggestion.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 17:33:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371301#M165863</guid>
      <dc:creator>romoc</dc:creator>
      <dc:date>2017-10-02T17:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371302#M165864</link>
      <description>&lt;P&gt;@romoc, &lt;CODE&gt;field names are case sensitive in Splunk&lt;/CODE&gt;. In your question you had tabular data with lower case field names. However, in the raw events you seem to have upper case field names. So try the following:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| chart first(ROW_COUNT) as ROW_COUNT over TABLE_NAME by DB_NAME
| eval REC_DIFF=y-x
| table TABLE_NAME x y REC_DIFF
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Following is a run anywhere search which mocks up data similar to your example above and then performs the chart function as &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval data="x,a,183;x,b,1781;y,a,183;y,b,1783;x,c,150;x,d,1780;y,c,151;y,d,1785;"
| makemv delim=";" data 
| mvexpand data
| eval data=split(data,",")
| eval DB_NAME=mvindex(data,0)
| eval TABLE_NAME=mvindex(data,1)
| eval ROW_COUNT=mvindex(data,2)
| table DB_NAME TABLE_NAME ROW_COUNT
| sort TABLE_NAME DB_NAME
| chart first(ROW_COUNT) as ROW_COUNT over TABLE_NAME by DB_NAME
| eval REC_DIFF=y-x
| table TABLE_NAME x y REC_DIFF
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;PS: Commands till &lt;CODE&gt;| sort TABLE_NAME DB_NAME&lt;/CODE&gt; generates the mock data for testing.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 17:57:24 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371302#M165864</guid>
      <dc:creator>niketn</dc:creator>
      <dc:date>2017-10-02T17:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371303#M165865</link>
      <description>&lt;P&gt;It worked like a charm! thanks @niketnilay!&lt;/P&gt;</description>
      <pubDate>Mon, 02 Oct 2017 18:05:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371303#M165865</guid>
      <dc:creator>romoc</dc:creator>
      <dc:date>2017-10-02T18:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a calculated column in a table</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371304#M165866</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/47492"&gt;@romoc&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;I tried to simulate your case, I  index the sample data you gave since there are key pair value which splunk will auto extract for you in search time   , i dont need to manually extract it. So I run my search &lt;/P&gt;

&lt;P&gt;index="test" sourcetype="test2"  source="/home/Documents/test2.txt" |chart values(ROW_COUNT) over TABLE_NAME by DB_NAME |eval REC_DIFF=x-y|table TABLE_NAME x y REC_DIFF&lt;/P&gt;

&lt;P&gt;and it works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;note: I use the "*" on my first answer inside the table  so i twill show all the  values under DB_NAME in order also values are not static.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 16:00:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-get-a-calculated-column-in-a-table/m-p/371304#M165866</guid>
      <dc:creator>xisura</dc:creator>
      <dc:date>2020-09-29T16:00:34Z</dc:date>
    </item>
  </channel>
</rss>

