<?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 Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/260997#M189671</link>
    <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;I have a DB query as below which displays the results as shown in the attached picture:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbquery "PB CSL" limit=1000 "select trunc(creation_time), SOURCE_SYSTEM_NAME, count(1) Count 
from PB_CSL.activity a, PB_CSL.Activitymap b 
where trunc(creation_time) &amp;gt;= trunc(sysdate) -5 and a.service_id = b.ACTIVITY_ID 
group by trunc(creation_time), SOURCE_SYSTEM_NAME 
order by trunc(creation_time), SOURCE_SYSTEM_NAME" | rename TRUNC(CREATION_TIME) as Date | eval Date=strftime('Date', "%m-%d-%Y") | chart values(COUNT) over SOURCE_SYSTEM_NAME by Date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/715iC34933C145FD0267/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I want to show the Total, Average, and % Change as additional columns. I already used the chart command for the table, so how would I be able to show the 3 remaining columns?  Any help is greatly appreciated!&lt;/P&gt;</description>
    <pubDate>Wed, 07 Oct 2015 21:09:48 GMT</pubDate>
    <dc:creator>pmcfadden91</dc:creator>
    <dc:date>2015-10-07T21:09:48Z</dc:date>
    <item>
      <title>Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/260997#M189671</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;

&lt;P&gt;I have a DB query as below which displays the results as shown in the attached picture:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| dbquery "PB CSL" limit=1000 "select trunc(creation_time), SOURCE_SYSTEM_NAME, count(1) Count 
from PB_CSL.activity a, PB_CSL.Activitymap b 
where trunc(creation_time) &amp;gt;= trunc(sysdate) -5 and a.service_id = b.ACTIVITY_ID 
group by trunc(creation_time), SOURCE_SYSTEM_NAME 
order by trunc(creation_time), SOURCE_SYSTEM_NAME" | rename TRUNC(CREATION_TIME) as Date | eval Date=strftime('Date', "%m-%d-%Y") | chart values(COUNT) over SOURCE_SYSTEM_NAME by Date
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="alt text"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/715iC34933C145FD0267/image-size/large?v=v2&amp;amp;px=999" role="button" title="alt text" alt="alt text" /&gt;&lt;/span&gt;&lt;/P&gt;

&lt;P&gt;I want to show the Total, Average, and % Change as additional columns. I already used the chart command for the table, so how would I be able to show the 3 remaining columns?  Any help is greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 21:09:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/260997#M189671</guid>
      <dc:creator>pmcfadden91</dc:creator>
      <dc:date>2015-10-07T21:09:48Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/260998#M189672</link>
      <description>&lt;P&gt;You seem to be doing a lot of work in the dbquery that may be easier done in Splunk, and even if not, that "heavy" query makes it difficult for folks not conversant with "regular" DBs to try to answer.  &lt;/P&gt;

&lt;P&gt;Could you provide a few rows of the dbquery output before you do anything in Splunk to it and, if possible, post a few rows of output for a query like&lt;BR /&gt;
    | dbquery "PB CSL" limit=1000 "select trunc(creation_time) AS Date, SOURCE_SYSTEM_NAME &lt;BR /&gt;
    from PB_CSL.activity a, PB_CSL.Activitymap b where a.service_id = b.ACTIVITY_ID"&lt;BR /&gt;
Those may help us to see what it is we're working with.  &lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:29:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/260998#M189672</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2020-09-29T07:29:31Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/260999#M189673</link>
      <description>&lt;P&gt;So the dbquery output is 3 columns  : &lt;/P&gt;

&lt;P&gt;Creation_Time    Source_System   Count&lt;BR /&gt;
10/2/2015         ADP                    2483&lt;BR /&gt;
10/2/2015        CSL                   10039&lt;BR /&gt;
10/2/2015        DIVP                   2032&lt;BR /&gt;
10/2/2015        RECON             7&lt;BR /&gt;
10/2/2015        SHRS                      621&lt;BR /&gt;
10/2/2015         T24                     587&lt;BR /&gt;
10/2/2015         TPE                    64702&lt;BR /&gt;
10/3/2015         ADP                    2519&lt;BR /&gt;
10/3/2015         CSL                   138&lt;BR /&gt;
10/3/2015        DIVP                     420&lt;BR /&gt;
10/3/2015        TPE                        3&lt;/P&gt;

&lt;P&gt;It shows like this in the database and when I run the query into Splunk before adding or making any additonal changes to it.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:32:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/260999#M189673</guid>
      <dc:creator>pmcfadden91</dc:creator>
      <dc:date>2020-09-29T07:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261000#M189674</link>
      <description>&lt;P&gt;Thanks for that!  This was the output of your whole db_query, right - just without any of the splunk pieces?&lt;/P&gt;

&lt;P&gt;So without all that grouping and summing inside SQL, you'd just have rows like&lt;/P&gt;

&lt;P&gt;10/2/2015 08:43:17.455 ADP&lt;BR /&gt;
10/2/2015 08:43:19.221 ADP&lt;BR /&gt;
10/2/2015 08:43:19.664 CSL&lt;BR /&gt;
...&lt;/P&gt;

&lt;P&gt;Right?  Exact date/time format doesn't matter, just that it's date and time, not just date, right?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Oct 2015 12:04:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261000#M189674</guid>
      <dc:creator>Richfez</dc:creator>
      <dc:date>2015-10-10T12:04:33Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261001#M189675</link>
      <description>&lt;P&gt;Add this to your current search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| fillnull value=0 | addtotals row=true| addtotals col=true | eval prev=0 | foreach *2015 [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;_changePct=100*((&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;-prev)/prev) | eval prev=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;]
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Oct 2015 22:52:22 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261001#M189675</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-10T22:52:22Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261002#M189676</link>
      <description>&lt;P&gt;Hi woodcock,  thanks for your answer. I was able to modify my query but am still having touble with the % Difference. The query is below but I need a need the "Difference" column to work as such: 100*((5_Day_Avg-Current_Day/5_Day_Avg)).  The Current Day being today's date, and then calculating when tomorrow is the new current date.  I tried an if statement for eval, but can't seem to quite figure out why it wont work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; index=csl_dblogs | rename TRUNC_CREATION_TIME as Date | rename SOURCE_SYSTEM_NAME as Source_System| eval Date=strftime('Date', "%m-%d-%Y") | chart values(COUNT) over Source_System by Date | addtotals fieldname=Total | eval 5_Day_Avg=round(Total/5)
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 07:41:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261002#M189676</guid>
      <dc:creator>pmcfadden91</dc:creator>
      <dc:date>2020-09-29T07:41:20Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261003#M189677</link>
      <description>&lt;P&gt;What is the output of your query?  Did you even try my solution?  As long as the output has not changed (you are no longer using &lt;CODE&gt;dbquery&lt;/CODE&gt;), it should work but it will give you the percent change of adjacent fields.  Perhaps you would like the % difference between the left-most column and the rightmost column?  Define the approach and I am sure I will be able to help you.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2015 16:28:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261003#M189677</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-10-29T16:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261004#M189678</link>
      <description>&lt;P&gt;@woodcock, I tried your solution, combined with what I have: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=csl_dblogs | rename TRUNC_CREATION_TIME as Date | rename SOURCE_SYSTEM_NAME as Source_System| eval Date=strftime('Date', "%m-%d-%Y") | chart values(COUNT) over Source_System by Date | addtotals fieldname=Total | eval 5_Day_Avg=round(Total/5)   | fillnull value=0 | addtotals row=true| addtotals col=true | eval prev=0 | foreach *2015 [ eval &amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;_changePct=100*((&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;-prev)/prev) | eval prev=&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So it sort of works, but I only need 1 specific column that displays %Difference based on "Today's Date -1"(Excluding Weekends).  So for today, the difference (1 column) would show for all systems where the date is Nov 6.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Nov 2015 20:57:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261004#M189678</guid>
      <dc:creator>pmcfadden91</dc:creator>
      <dc:date>2015-11-09T20:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Splunk DB Connect 1: How to edit my dbquery to add Total, Average, and Percentage columns to my results?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261005#M189679</link>
      <description>&lt;P&gt;You have completely destroyed the function of what I gave you which I guess is because you are desiring something totally different than what I understood you to mean.  If you will come back with a mockup table showing your desired output, then maybe I can help.  As it stands right now, I believe that I have given you &lt;EM&gt;exactly&lt;/EM&gt; what you described so I cannot help any more because I just don't understand what you really need.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2015 23:30:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Splunk-DB-Connect-1-How-to-edit-my-dbquery-to-add-Total-Average/m-p/261005#M189679</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2015-11-15T23:30:53Z</dc:date>
    </item>
  </channel>
</rss>

