Running Sums???
Say I've got a simple table:
Table
: Fields: Key, Section
given the statement:
select Section, Count(Key)
from Table
group by Section;
you will get the count of keys per section.
But what if I not Only want the Count of Keys per section, but also a sum of two sections at a time.
Like:
select Section, Count(Key), Sum(Section 1 & 2)
from table
group by section;
now i know that is not accurate, but i think my idea is clear enough. In ACCESS ( i hate to mention the evil-one) it was called a cross-tab query, when you could do multiple aggregates and running summations, but i don't know how to do that in oracle sql (or even if it can be done)
the output for this query (as i see it) should be
section 1 Count
Section 2 Count
Section 1+2 Count
Section 3 Count
Section 1+2+3 Count
section 4 count
section 1+2+3+4 Count
etcetera
(i'll understand if it can't be done, but I would think it could be)
Thanks
Jaeden "Sifo Dyas" al'Raec ruiner
Just for fun #2 :))
SQL> select new_d deptno, sc
2 from (select t.*,
3 lev,
4 decode(lev,1, to_char(d), ltrim(sys_connect_by_path(d, '+'), '+')) new_d,
5 decode(lev, 1, cnt, sumc) sc
6 from (select e.deptno d,
7 count(1) cnt,
8 sum(count(1)) over(order by e.deptno) sumc,
9 row_number() over(order by e.deptno) rn
10 from scott.dept d, scott.emp e
11 where e.deptno = d.deptno
12 group by e.deptno) t,
13 (select 1 lev from dual union all select 2 from dual)
14 connect by prior rn = rn - 1
15 and prior lev = lev
16 start with rn = 1
17 order by d, lev
18 ) t
19 where rn = lev
20 or rn > 1
21 /
DEPTNO SC
10 3
20 5
10+20 8
30 6
10+20+30 14
Similar Messages
-
Logical Columns - Running Sum & 3Month Rollover
Hi All,
Need to build a logical column.
I have a column with number of units (count distinct) in RPD.
I need to build a new logical column in the REPOSITORY , such that it has running sum values.... sothat when i pick this #units column and months column in the ANSWERS...I need to get roll over of all previous values for first month.
Say Jan ---> XXXX units ( summation of all previous available units - few years)
Feb----> YYYY units ( sum of till jan values & Feb units)
Mar----> ZZZZ ...etc ( sum of till Feb values & Mar units) so on.
Based on this newly built column I need to build another column of " 3 months roll over " column.
Replies appreciated.
Thanks in advance.Hi user11939829m
So help me understand your new measures a little better. For the sake of this post, let's say your data is like so
Month Year -- Units
Jan 2010 -- 1
Feb 2010 -- 2
Mar 2010 -- 3
Apr 2010 -- 4
May 2010 -- 5
Jun 2010 -- 6Then let's say you have a report with the above columns and the new running sum columns.
Month Year -- Units -- Running Sum Units
Jan 2010 -- 1 -- 1
Feb 2010 -- 2 -- 3
Mar 2010 -- 3 -- 6
Apr 2010 -- 4 -- 10
May 2010 -- 5 -- 15
Jun 2010 -- 6 -- 21Now what exactly would your three months rollover be? Would the 3 month rolling sum = running sum for current month + running sum for last month + running sum for last last month?
i.e.
Month Year -- Units -- Running Sum Units -- 3 Month Rolling Sum
Jan 2010 -- 1 -- 1 -- 1
Feb 2010 -- 2 -- 3 -- 4
Mar 2010 -- 3 -- 6 -- 10
Apr 2010 -- 4 -- 10 -- 19
May 2010 -- 5 -- 15 -- 31
Jun 2010 -- 6 -- 21 -- 46Not sure what value such a measure would add. Or do you mean 3 month rolling sum would be the running sum for just the last three months (like below)? This makes more sense but in your description, you indicated that you'd build the 3 month rolling sum off of the running sum which confused me a bit.
Month Year -- Units -- Running Sum Units -- 3 Month Rolling Sum
Jan 2010 -- 1 -- 1 -- 1
Feb 2010 -- 2 -- 3 -- 3
Mar 2010 -- 3 -- 6 -- 6
Apr 2010 -- 4 -- 10 -- 9
May 2010 -- 5 -- 15 -- 12
Jun 2010 -- 6 -- 21 -- 15 Is that what you are going for? Please elaborate.
Best regards,
-Joe -
Hi Experts,
I have the following pivot table:
----------SUM1--SUM2--SUM3
-------A--20------30-------45
-------P--10------15--------5
----DIFF-10------15-------40
where the last row is new calculated item. Is it possible to create another calculated row by using value from the 'Diff' row?. What I want to achieve is Running Sum for 'Diff' row.
So I need an output like:
----------SUM1--SUM2--SUM3
-------A--20------30-------45
-------P--10------15--------5
----DIFF-10------15-------40
RSUM-10----25-------65
My BI version is BI EE 10.1.3.4.1. I suppose that some kind of trick will be helped.
Thanks in advance for any suggestion
Regards,
EskHi, It is possible in pivot view.
You need to move the measure labels to the left..where it says rows.
Once that is done, we can click on any of the facts and choose display as running sum -
Running sum per column in pivot table
Hello,
I am facing a problem with a running sum in a pivot table. As you know, the running sum provided by OBIEE spans across rows and columns. My requirements force me to have a running sum per each column (I have four columns, one for each quarter of the year). My pivot is as follows:
------------------------------|| 1st Quarter / 2nd Quarter ...
type of product / status || (Measure / Running Sum) / (Measure / Running Sum) ...
I've tried using the evaluate function with a "sum over" but that doesn't seem to work either.
Do you have any ideas that could be useful to solve this?
Thank you in advance for your time,
João MarquesDo not use the "running measure" button in pivot table, but try this :
edit the formula of your measure and type :
RSUM(mesure by dimension)
where dimension is the attribute dimension that you put on the ROWS of your pivot table
Exemple : I've got the criteria REVENUE, YEAR, CUSTOMER TYPE
I put the YEAR in the Columns of the pivot table
I put the CUSTOMER TYPE on the rows of the pivot table
I put the REVENUE in the measures of the pivot table
Measure has the formula : RSUM("Facts Revenue".Revenue BY Customers."Customer Type") -
I have a measure in the pivot table with the following options enabled:
- Show data as - Percent of - Section
- Display as Running Sum
Also, I have several sections in the pivot table.
The measure result is correct, but when I add totals, I get a strange result. The total for the first section is 100%, for the second section is 200%, for the third section is 300%, and so on.
Does everybody get this problem? How can I solve it?
Thanks.I couldn't find a solution... I gave up using "Display as Running Sum" and I created in the criteria tab a formula to solve this (using RSUM BY).
-
"Display As Running Sum" Feature
Hi
Tried to use "Display As Running Sum" feature and it looks like it adds all the values across the pivot table and does not reset it on a new row...
So for instance we ahve a table as follows
A 1 2
A1 3 4
A2 5 6
After running sum applied:
A 1 3
A1 6 10
A2 15 21
Is there any way value could be reset after each row ? Any hidden configuration file to be changed ?Initial data is:
Product Date Value
A Day1 1
A Day2 2
A Day3 3
A1 Day1 4
A1 Day2 5
A1 Day3 6
A2 Day1 7
A2 Day2 8
A2 Day3 9
Pivot table looks like:
---- Day001 Day002 Day003
A 1 2 3
A1 4 5 6
A2 7 8 9
Required table (values disaplyed as running sums by product)
---- Day001 Day002 Day003
A 1 3 6
A1 4 9 15
A2 7 15 24
PROBLEM: its easy to create formula RSUM(value by product) and put it as pivot table measure BUT I have around 1000 reports with different dimensions which requires to create RSUM(value by dimension1), RSUM(value by dimension2) ... RSUM(value by dimension1000) and its sort of nightmare...
Instead of RSUM I thought that feature "Display As Running Sum" could be used, but its not working as expected in terms of it does not get reset for each row. How do I configure "Display As Running Sum" to reset value for each row ?
PS: this is what "Display As Running Sum" gives
---- Day001 Day002 Day003
A 1 3 6
A1 10 15 21
A2 28 36 45 -
Running Sum without analytic function
Hi
I have data like below
Create table Test (Name Varchar(30),M Int, Y Int, Val Int);
Insert into Test Values ('A',1,2011,2);
Insert into Test Values ('A',2,2011,2);
Insert into Test Values ('A',3,2011,2);
Insert into Test Values ('A',4,2011,2);
Insert into Test Values ('A',5,2011,2);
Insert into Test Values ('A',6,2011,2);
Insert into Test Values ('A',7,2011,2);
Insert into Test Values ('A',8,2011,2);
Insert into Test Values ('A',9,2011,2);
Insert into Test Values ('A',10,2011,2);
Insert into Test Values ('A',11,2011,2);
Insert into Test Values ('A',12,2011,2);
Insert into Test Values ('A',1,2012,2);
Insert into Test Values ('A',2,2012,2);
Insert into Test Values ('A',3,2012,2);
Insert into Test Values ('A',4,2012,2);
Insert into Test Values ('A',5,2012,2);
Insert into Test Values ('A',6,2012,2);
Insert into Test Values ('A',7,2012,2);
Now based on above data I need to calculate running sum for past 18 Months. Condition is I can not use analytic function or Oracle specific SQL functions (for portability).
I tries following SQL but it dint work
select Name,rnk, SUM(val) from (
SELECT a.Name,a.m,a.Y,b.val, count(*) rnk
from Test a, Test b
where (a.Name=b.Name and (a.M <= b.M and a.Y<= b.Y))
group by a.Name,a.Y,a.m
order by a.Name,a.Y,a.m
) abc
group By Name,rnk
Order by Name,rnk
Can some one give suggastion.Hi,
I don't see what your query or your desired results have to do with the last 18 months. Is the task here to show for a given month (July, 2012, for example) the total of the 18 months ending in that month (February, 2011 through July, 2012 in this case) for the same name? If so:
SELECT c.name, c.y, c.m
, SUM (p.val) AS running_total
FROM test c
JOIN test p ON ( ((12 * c.y) + c.m)
- ((12 * p.y) + p.m)
) BETWEEN 0 AND 17
GROUP BY c.name, c.y, c.m
ORDER BY c.name, c.y, c.m
;Output:
NAME Y M RUNNING_TOTAL
A 2011 1 2
A 2011 2 4
A 2011 3 6
A 2011 4 8
A 2011 5 10
A 2011 6 12
A 2011 7 14
A 2011 8 16
A 2011 9 18
A 2011 10 20
A 2011 11 22
A 2011 12 24
A 2012 1 26
A 2012 2 28
A 2012 3 30
A 2012 4 32
A 2012 5 34
A 2012 6 36
A 2012 7 36 -
Running Sum on column total minus current month
Hi all,
Is it possible to get the running sum total value of all the months minus the current month value in the column function,as I need to display the same in the narrative view.
Like RSUM(YTD(M-1)Value)...
Presently this RSUM is not giving me the right value.
I can also do the total for all the months minus the current month value.Can it be done at the column funtion?
Regards
AshishHi
Can you elaborate a little..Did you mean I need to create one variable in the repository?
YTD (M-1 Value) / (YTD Last Year M 0 Value)
where M0 is current month and M-1 is previous month and value is a measure.
Regards
Ashish
Edited by: Ashish21473 on Jan 7, 2011 3:38 AM -
Running Sum does not reste at the start of new period
Hi Gurus,
I am using function Running SUm for a variable. The problem is our Fiscal period starts in September. SO the running sum should reset at teh start of every period. but its not happening.
Any Idea why?
RegardsHi,
As I see it
num RunningSum(measure[;Row|Col][;reset_dims])
You are using to many variables for reset_dims, if you wanna do it this way, create a variable and add this v_FY_Sort_1;Output;Site to that variable then use
RunningSum(COGM RM Cost Total Amt Actual; variable) -
Running Sum on Sorted data & freeze panes?
Hi all,
Brand new to Web Intelligence XI, so learning whilst putting together first report, however need some guidance and help on the following.
I have a basic report which is sorted by highest ytd sales within the report and has breaks at each change in brand category.
I need to be able to provide a running % cumulative total for each article within each brand category based on the highest ytd sales.
I have tried using the running sum formula but this does not give correct results due to the sort, as when this is taken off
the formula is correct. Have different varients of this after reviewing the forum but unfortunately still cannot get this basic calculation to work.
My second question is that when viewing a lot of data, is it yet possible to freeze the headers in each column?
Thanks in advance for any help given.
NickFreeze panes will be supported in BO 4.1 which is planned to be released in Q3 2013.
Check the details below:
http://scn.sap.com/community/businessobjects-web-intelligence/blog/2013/03/10/what-is-new-with-web-intelligence-bi-41-part-2-core-capabilities
http://scn.sap.com/community/business-intelligence/blog/2013/01/31/sap-businessobjects-bi-41-update-and-bi4x-roadmap-asug-webcast-part-1
http://scn.sap.com/community/business-intelligence/blog/2013/02/01/sap-businessobjects-bi-41-update-and-bi4x-roadmap-asug-webcast-part-2 -
Running Sum on Two Dimension object
Dear All,
I have below scenario:
In Crosstab:
Row: Region,State
Column : Month
Measure - Sales & Sales % (= Sales for State/Total Sales for that Region)
Expected Output:
Region - Month --- Jan Sales -Jan % - Feb - Feb % - Mar - Mar %
West - State -1 -- 10 - 66%(10/30) - 40 - 66% (40/60) - 50 - 50%(50/100)
West -State -2 -- 20 - 34% (20/20) - 20 - 34% (20/60) - 50- 50% (50/100)
West Running Total 30 - 100% - 60 -100% - 100 -100%
East - State -1 -- 0 - 0%(0/0) - 60 - 100% (60/60) - 50 - 50%(50/100)
East -State -2 -- 20 - 100% (20/20) - 0 - 0% (0/60) - 50- 50% (50/100)
West Running Total 20 - 100% - 60 -100% - 100 -100%
Actual Output:
Month --- Jan Sales -Jan % - Feb - Feb % - Mar - Mar %
West - State -1 10 - 66%(10/30) - 40 - 57% (40/70) - 50 - 35%(50/140)
West - State -2 20 - 34% (20/20) - 20 - 22% (20/90) - 50- 26% (50/190)
Running Total 30 - 100% - 90 (304030) -79% - 100 -61%
East - State -1 -- 0 - 0%(0/0) - 60 - 75% (60/80) - 50 - 35%(50/140)
East -State -2 -- 20 - 100% (20/20) - 0 - 0% (0/80) - 50- 27% (50/180)
West Running Total 20 - 100% - 80 -75% - 180 -57%
My Running Total Formula is : = Runningsum( Sales; (Region))
Sales % = Sales / Running Total Formula
In short, I want to reset running total while my state and Month gets change. Here what's going on is while my state will get change, sum will reset and if I use Month in Running Sum formula I will get reverse effect in State.
Can anyone have idea how to solve this issue ?
Any answer would be appreciate.
Regards,
Rishithi Rishit,
You need not create any formulas to achieve the expected output.
Create a cross tab with
row -> region, state
column -> month
measure -> sales
Apply a break on Region
Now select sales column
1) insert sum using Summary(Sigma) button.
2) insert Percentage using Summary button
3) Remove unrequired row i.e. horizontal rows for Percentage. But keep the Percentage Column
4) Manually you can type 100% on right hand side of sum.
Regards,
Vamsee -
Integrating a waveform to obtain a running sum of the amplitude
I am trying to decide the easiest way to integrate a waveform. I have obtained a signal and done a series of waveform operations on it, not I need to sum up the amplitudes of the waveform. I am assuming that the best way to do this is going to be using some sort of integration. I can't seem to get a simple integrator to do this.
Thanks for your helpHere is a little more information about the application. I have used data aquisitions to aquire two AC voltage waveforms. I have rectified the waveforms, and summed the two waveforms together. Now I need to take a summation (running sum) of the resulting waveform. Accuracy is somewhat of a concern, as this running sum will be used to calculate a series of costs and usage characteristics.
Hope this helps by giving an idea of what I am looking to do.
I have tried to do the numeric integration, but I am having a problem getting the waveform to sample as needed. My other idea was to convert the waveform to (x,y) coordinates and work with that data. I'm not sure what the best way will be. -
Hello,
I need to calculate running sum for each row. I' ve created pivot table report where both dimensions are dates. When I use function RSUM, it sums all values from first record till current record (totals for all rows), but I need a running sum for each row.
Is there any way to get running sum for specific group (dimension value change) record similar as it could be in Oracle SQL using OVER(PARTION BY) construct?
For example, if there is a table with 3 rows and 2 columns:
_*1* *2*
*1* 2 4
*2* 1 3
*3* 1 2
Then corresponding table with running sums will be:
_*1* *2*
*1* 2 6
*2* 1 4
*3* 1 3
Thanksuse the aggregate by statement:
http://obiee101.blogspot.com/search?q=aggregate
regards
John
http://obiee101.blogspot.com -
A slightly different running sum in a hierarchy query
Hi,
I've got stuck with this problem since quite some time, so pls help:
I am basically trying to rollup/aggregate values from the lower level nodes to the upper level nodes in a hierarchy. But this aggregate is a bit different than a plain rollup of values.
create table ent_rel (parent number, child number, child_amount number);
insert into ent_rel
select null, 100, null from dual
union all select 100, 101, null from dual
union all select 101, 102, 20 from dual
union all select 102, 103, null from dual
union all select 103, 104, null from dual
union all select 104, 105, null from dual
union all select 105, 106, 40 from dual
union all select 106, 107, null from dual
union all select 107, 108, 20 from dual
union all select 107, 109, 10 from dual
union all select 101, 203, null from dual
union all select 203, 205, 50 from dual
union all select 205, 207, null from dual
union all select 207, 209, null from dual
union all select 209, 210, 10 from dual
commit;
select RPAD(' ', (LEVEL - 1) * 2, '-') || child child
,level
,child_amount
from ent_rel
start with parent is null
connect by prior child = parent
CHILD LEVEL CHILD_AMOUNT
100 1
--101 2
----102 3 20
------103 4
--------104 5
----------105 6
------------106 7 40
--------------107 8
----------------108 9 20
----------------109 9 10
----203 3
------205 4 50
--------207 5
----------209 6
------------210 7 10
Now, I need a SQL query or even a simple PL/SQL code to get the DESIRED_AMOUNT field as shown below:
Pls note that there might be many more parallel branches to a node, but I've kept it simple just to get the concept.
CHILD LEVEL CHILD_AMOUNT DESIRED_AMOUNT
100 1 70
--101 2 70
----102 3 20 20
------103 4 40
--------104 5 40
----------105 6 40
------------106 7 40 40
--------------107 8 30
----------------108 9 20 20
----------------109 9 10 10
----203 3 50
------205 4 50 50
--------207 5 10
----------209 6 10
------------210 7 10 10
Thanks a lot in advance.
thanks and regards,
KnlHi,
Welcome to the forum!
Thanks for posting the CREATE TABLE and INSERT statements! That's very helpful.
It's also helpful if you format your code and output. When posting formatted text on this site, type these 6 characters:
\(all small letters, inside curly brackets) to keep the site from compressing the spaces.
You can do two CONNECT BY queries: one to get the desired amount, and the other like you're already doing, to get the indented child column. The first will differ in that it has no START WITH clause, which means every node in your table will be the root of a tree, and that there's an additional CONNECT BY condition to quit looking for descendants as soon as an amount is found. This corresponds to your apparant requirement that the desired_amount is the amount, if it is not NULL, and only otherwise is the sum of the desired_amounts of one's descendants.WITH desired_amount_tree AS
SELECT CONNECT_BY_ROOT child AS root
, child
, child_amount
FROM ent_rel
CONNECT BY PRIOR child = parent
AND PRIOR child_amount IS NULL
, got_desired_amount AS
SELECT root
, SUM (child_amount) AS desired_amount
FROM desired_amount_tree
GROUP BY root
select RPAD ( ' '
, (LEVEL - 1) * 2
) || e.child AS child
, level
, e.child_amount
, desired_amount
from ent_rel e
JOIN got_desired_amount d ON e.child = d.root
start with parent is null
connect by prior child = parent
It's usually more efficient to do join after doing the CONNECT BY. For better performance, try doing your original query by itself, and then joining its result set to got_desired_amount.
Of course, it would be a lot more efficient if we could eliminate the extra CONNECT BY query. That might be possible using MODEL or (starting in Oracle 11.2) a recursive sub-query. -
Sql query for running sum(using aggregate)
<pre>
Table name table1 (no, amount)
insert into table1 values(1, 10) ;
insert into table1 values(2 ,-10) ;
insert into table1 values(3, -20) ;
insert into table1 values(4, -30) ;
insert into table1 values(5,40) ;
and i am expecting the result in this manner
no
sum (amount)
1
10
2
0
3
-20
4
-50
5
-10
select no,sum(amount) over(order by no) from table1;
but with this query i am getting the result in below manner
no
sum (amount)
1
10
2
20
3
40
4
70
5
110
which is not excepted result, could some one help me in getting excepted results ,could any one provide the proper query for this
</pre>h
Hi Friends,
sorry to trouble you,i did not have oracle instance installed on my machine to check the query ,
this is some test query which is some resemblance with actual query in my project
actually the requirement is like this ,this is the master table
NO amount
1 10
2 100
3 120
4 50
5 41
using some decoding function in the query the result came like this
NO decode(amount,......) quantity
1 10
2 -10
3 -20
4 -30
5 41
on this decode function i am trying to using aggregate function SUM,but in that case in stood of giving
ABS value , it is giving in proper value like below result
NO decode(amount,......) quantity aggregate sum
1 10 10
2 -10 20
3 -20 40
4 -30 70
5 41 111
but i excepted the result ABS value like below
NO decode(amount,......) quantity aggregate sum
1 10 10
2 -10 0
3 -20 -20
4 -30 -50
5 41 -9
my question is aggregate function on this decoded values have any impact on the result?
for this question your are unable to help me ,tomorrow i will get exact table structure and exact query which i am using
in my project
Maybe you are looking for
-
Monitor Calibration under Snow Leopard 10.6.6
Hello, I´m using a EIZO CE 240 W hardware-calibrated monitor for Photoshop and a second one connected with it for the tools, which worked perfectly under Tiger, but doesn´t work properly under Snow Leopard. Does anybody know this problem? When I disc
-
667 qualify for FHA loan?
Hi, any and all input is greatly appreciated. My girlfriend and I have been wanting to purchase a home for quite some time now. My mortgage score is 667 & hers is 647. She actually has better credit than I do. I have six big collections, she has none
-
Customer Master not updated when creating BP- BAPIBUSISM007_CREATEFROMDATA
Hi All When I creating BP with TCODE BP-with BP role ISM020 , BP is created and all the tables are updated. But when I create BP programmatically with the BAPI -BAPIBUSISM007_CREATEFROMDATA Though the BP is created ,But The customer master tables are
-
ITunes Store language settings or using an overseas store?
Is there any way to change the Japan iTunes Store interface to display English instead of Japanese? Or failing that, is there any way to use the US or UK stores if I only have a Japan credit card?
-
When I'm seeing an article about cross join I got a doubt. In that physical diagram they connected the the column-1 from table A and column 2 from table B.Table-A is xls and table-2 is Oracle. Now IN BMM layer they connected the col-1 and col-2 as fo