Calculate running total
I want to calculate the running total on a bank account with each transaction.
Below is sample data script.
CREATE TABLE ACCT (trans_type varchar2(100), trans_date date, trans_loc varchar2(250), trans_amt number);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('11/19/2010', 'MM/DD/YYYY'), 'WAL-MART', 2.62);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('RETURN', TO_DATE('12/27/2010', 'MM/DD/YYYY'), 'JCPENNEY STORE', -32.27);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('11/28/2010', 'MM/DD/YYYY'), 'WAL-MART', 23.91);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('01/02/2011', 'MM/DD/YYYY'), 'TOMMY HILFIGER', 16.1);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('02/27/2011', 'MM/DD/YYYY'), 'DILLARD''S', 64.31);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('01/07/2011', 'MM/DD/YYYY'), 'MIKE KEHOE', 23.26);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('01/02/2011', 'MM/DD/YYYY'), 'OLIVE CAFE', 25.04);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('12/10/2010', 'MM/DD/YYYY'), 'WAL-MART', 46.13);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('12/07/2010', 'MM/DD/YYYY'), 'WAL-MART', 3.82);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('12/01/2010', 'MM/DD/YYYY'), 'TARGET', 12.09);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('02/22/2011', 'MM/DD/YYYY'), 'TARGET', 43.1);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('01/26/2011', 'MM/DD/YYYY'), 'ST MARYS BIL', 6.96);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('02/14/2011', 'MM/DD/YYYY'), 'WALLMART', 56.9);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('02/27/2011', 'MM/DD/YYYY'), 'WALLMART', 43.64);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('01/16/2011', 'MM/DD/YYYY'), 'OLIVE CAFE', 18.14);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('SALE', TO_DATE('12/23/2010', 'MM/DD/YYYY'), 'MIDEAST BALLWIN', 103.18);
Insert into ACCT (TRANS_TYPE, TRANS_DATE, TRANS_LOC, TRANS_AMT)
Values ('RETURN', TO_DATE('12/27/2010', 'MM/DD/YYYY'), 'JCPENNEY STORE', -34.75);I need running total to show with each transaction and also the balance amount out of a static limit of 7500.
Any help is appreciated!
Thanks for providing sample data!
Are you looking for something like this?
SQL > SELECT trans_type
2 , trans_date
3 , trans_loc
4 , trans_amt
5 , 7500 - SUM(trans_amt) OVER (ORDER BY rn) AS running_balance
6 , SUM(trans_amt) OVER (ORDER BY rn) AS running_total
7 FROM (
8 SELECT trans_type
9 , trans_date
10 , trans_loc
11 , trans_amt
12 , ROW_NUMBER() OVER (ORDER BY trans_date) AS rn
13 FROM acct
14 )
15 ORDER BY 2
16 ;
TRANS_TYPE TRANS_DATE TRANS_LOC TRANS_AMT RUNNING_BALANCE RUNNING_TOTAL
SALE 11/19/2010 00:00:00 WAL-MART 2.62 7497.38 2.62
SALE 11/28/2010 00:00:00 WAL-MART 23.91 7473.47 26.53
SALE 12/01/2010 00:00:00 TARGET 12.09 7461.38 38.62
SALE 12/07/2010 00:00:00 WAL-MART 3.82 7457.56 42.44
SALE 12/10/2010 00:00:00 WAL-MART 46.13 7411.43 88.57
SALE 12/23/2010 00:00:00 MIDEAST BALLWIN 103.18 7308.25 191.75
RETURN 12/27/2010 00:00:00 JCPENNEY STORE -34.75 7343 157
RETURN 12/27/2010 00:00:00 JCPENNEY STORE -32.27 7375.27 124.73
SALE 01/02/2011 00:00:00 OLIVE CAFE 25.04 7350.23 149.77
SALE 01/02/2011 00:00:00 TOMMY HILFIGER 16.1 7334.13 165.87
SALE 01/07/2011 00:00:00 MIKE KEHOE 23.26 7310.87 189.13
SALE 01/16/2011 00:00:00 OLIVE CAFE 18.14 7292.73 207.27
SALE 01/26/2011 00:00:00 ST MARYS BIL 6.96 7285.77 214.23
SALE 02/14/2011 00:00:00 WALLMART 56.9 7228.87 271.13
SALE 02/22/2011 00:00:00 TARGET 43.1 7185.77 314.23
SALE 02/27/2011 00:00:00 WALLMART 43.64 7142.13 357.87
SALE 02/27/2011 00:00:00 DILLARD'S 64.31 7077.82 422.18
17 rows selected.
Similar Messages
-
Filling gaps when calculate running total
Hello Friends,
i have a script that calculate running total,but i have gaps between dates.i had some solutions to resolve this issue but it did not perform well.because my source table has over milllion rows.please see my query,output and desired output.
Thanks in advance.
IF OBJECT_ID('tempdb..#SalesSummary') IS NOT NULL
DROP TABLE #SalesSummary
IF OBJECT_ID('tempdb..#StockDetail') IS NOT NULL
DROP TABLE #StockDetail
IF OBJECT_ID('dbo.SalesTransaction') IS NOT NULL
DROP TABLE SalesTransaction
IF OBJECT_ID('dbo.DesiredOutput') IS NOT NULL
DROP TABLE DesiredOutput
CREATE TABLE [dbo].[SalesTransaction] (
[StoreKey] [int] NULL
,[StockKey] [int] NULL
,[OptionKey] [int] NULL
,[DateKey] [int] NULL
,[Quantity] [int] NULL
CREATE TABLE [dbo].[DesiredOutput] (
[Datekey] [int] NULL
,[StoreKey] [int] NULL
,[StockKey] [int] NULL
,[OptionKey] [int] NULL
,[SalesFlag] [int] NOT NULL
,[Quantity] [int] NULL
,[StockQty] [int] NULL
INSERT [dbo].[SalesTransaction] (
[StoreKey]
,[StockKey]
,[OptionKey]
,[DateKey]
,[Quantity]
VALUES (
1
,1
,1
,20140601
,20
INSERT [dbo].[SalesTransaction] (
[StoreKey]
,[StockKey]
,[OptionKey]
,[DateKey]
,[Quantity]
VALUES (
1
,1
,1
,20140603
,- 10
INSERT [dbo].[SalesTransaction] (
[StoreKey]
,[StockKey]
,[OptionKey]
,[DateKey]
,[Quantity]
VALUES (
1
,1
,1
,20140607
,30
INSERT [dbo].[SalesTransaction] (
[StoreKey]
,[StockKey]
,[OptionKey]
,[DateKey]
,[Quantity]
VALUES (
2
,2
,2
,20140602
,15
INSERT [dbo].[SalesTransaction] (
[StoreKey]
,[StockKey]
,[OptionKey]
,[DateKey]
,[Quantity]
VALUES (
2
,2
,2
,20140603
,- 5
INSERT [dbo].[SalesTransaction] (
[StoreKey]
,[StockKey]
,[OptionKey]
,[DateKey]
,[Quantity]
VALUES (
2
,2
,2
,20140605
,20
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140601
,1
,1
,1
,1
,20
,20
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140602
,1
,1
,1
,0
,0
,20
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140603
,1
,1
,1
,1
,- 10
,10
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140604
,1
,1
,1
,0
,0
,10
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140605
,1
,1
,1
,0
,0
,10
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140606
,1
,1
,1
,0
,0
,10
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140607
,1
,1
,1
,1
,30
,40
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140602
,2
,2
,2
,1
,15
,15
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140603
,2
,2
,2
,1
,- 5
,10
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140604
,2
,2
,2
,0
,0
,10
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140605
,2
,2
,2
,1
,20
,30
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140606
,2
,2
,2
,0
,0
,30
INSERT [dbo].[DesiredOutput] (
[Datekey]
,[StoreKey]
,[StockKey]
,[OptionKey]
,[SalesFlag]
,[Quantity]
,[StockQty]
VALUES (
20140607
,2
,2
,2
,0
,0
,30
SELECT Datekey
,StoreKey
,StockKey
,OptionKey
,SUM(Quantity) Quantity
INTO #SalesSummary
FROM dbo.SalesTransaction
GROUP BY Datekey
,StoreKey
,StockKey
,OptionKey
SELECT Datekey
,StoreKey
,StockKey
,OptionKey
,1 AS SalesFlag
,Quantity
,SUM(Quantity) OVER (
PARTITION BY StoreKey
,StockKey
,OptionKey ORDER BY Datekey ROWS UNBOUNDED PRECEDING
) AS StockQty
INTO #StockDetail
FROM #SalesSummary
ORDER BY Datekey
SELECT *
FROM #StockDetail
SELECT *
FROM DesiredOutputI am glad that you attempted to post DDL, but you have no idea what you are doing and this is garbage. You have no idea what the ISO-11179 rules are. The meta-data attribute “_key” is never part of a data element name. Never! This is
how the element is used, and not what it is by its nature. A silly world of only INTEGERs? No keys, no DRI, nothing that can be part of a data model.
Why not use an industry standard like GTIN for the items? But I am sure you did not research anything.
Why did you have one and only sales transaction? That your table name told us. Most transaction models have an identifier; look at the receipt you got from MacDonald's for the last hamburger you are.
Why not use an industry standard like GTIN for the items? But I am sure you did not research anything.
Why did you have one and only sales transaction? That your table name told us. Most transaction models have an identifier; look at the receipt you got from MacDonald's for the last hamburger you are.
This is a deck of punch cards written in bad SQL.
CREATE TABLE Sales_Transactions
(sale_ticket INTEGER NOT NULL PRIMARY KEY,
store_nbr CHAR(10) NOT NULL,
gtin INTEGER NOT NULL, --- really CHAR(15)!
sale_date DATE NOT NULL,
sale_qty INTEGER NOT NULL
CHECK (sale_qty <> 0));
I have no idea how you get the unique ticket number for the key, but you can consider CREATE SEQUENCE Sales_Tickets; If you do not know this, Google it. You can build it into the DDL.
Did you know that RDBMS does not use Assembly language flags? We also do not use the Sybase “INTO #temp_table” to fake a scratch tape. In fact, you even mount another scratch tape so you can do step-by-step processing! This is not RDBMS.
You got the syntax for insertions wrong; you are using the old Sybase stuff.
INSERT INTO Sales_Transactions
(1, '00001', 1, '2014-06-01', 20),
(2, '00001', 1, '2014-06-03', -10),
(3, '00001', 1, '2014-06-07', 30),
(4, '00002', 2, '2014-06-02', 15),
(5, '00002', 2, '2014-06-03', -5),
(6, '00002', 2, '2014-06-05', 20);
It looks like you want inventory levels as running total
This is a deck of punch cards written in bad SQL.
CREATE TABLE Sales_Transactions
(sale_ticket INTEGER NOT NULL PRIMARY KEY,
store_nbr CHAR(10) NOT NULL,
gtin INTEGER NOT NULL, --- really CHAR(15)!
sale_date DATE NOT NULL,
sale_qty INTEGER NOT NULL
CHECK (sale_qty <> 0));
I have no idea how you get the unique ticket number for the key, but you can consider CREATE SEQUENCE Sales_Tickets; If you do not know this, Google it. You can build it into the DDL.
Did you know that RDBMS does not use Assembly language flags? We also do not use the Sybase “INTO #temp_table” to fake a scratch tape. In fact, you even mount another scratch tape so you can do step-by-step processing! This is not RDBMS.
You got the syntax for insertions wrong; you are using the old Sybase stuff.
INSERT INTO Sales_Transactions
(1, '00001', 1, '2014-06-01', 20),
(2, '00001', 1, '2014-06-03', -10),
(3, '00001', 1, '2014-06-07', 30),
(4, '00002', 2, '2014-06-02', 15),
(5, '00002', 2, '2014-06-03', -5),
(6, '00002', 2, '2014-06-05', 20);
My guess is that yoyu can use:
CREATE VIEW Inventory_Levels
AS
SELECT sale_date, gtin, sale_qty,
SUM(sale_qty)
OVER (PARTITION BY gtin
ORDER BY sale_date
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)
AS current_stock_qty
FROM Sales_Transactions
GROUP BY sale_date, gtin, sale_qty;
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
CALCULATE RUNNING TOTALS FOR SUBSETS OF THE DATA IN A SECTION
How can I calculate a running total in BO XI Release 2, (WebI), where my totals only include the value of the current row and the previous 5 rows?
For Example:
In the data, behind my BO table, I have transaction dates that roll up to a dimension called Period. The "Period" represents the Year and Month of the transaction date, which is a month's worth of data at a time. Each month contains an aggregated value that is the Population of items for that month. The RunningSum function in BO works well, except that I need the running total to only include the current month along with the last 5 months, for a total of 6 months worth of data per row.
See my example below. The Period of JAN 2009 includes the Population for JAN 2009 plus the sum of the Populations from AUG 2008 through DEC 2008 for a total of 6 months worth of data. FEB 2009 includes SEP 2008 through FEB 2009. MAR 2009 includes OCT 2008 through MAR 2009...
__________Period_______Population_______6 MOS
__________200801__________54___________54
__________200802__________60__________114
__________200803__________50__________164
__________200804__________61__________225
__________200805__________65__________290
__________200806__________58__________348
__________200807__________70__________364
__________200808__________64__________368
__________200809__________59__________377
__________200810__________62__________378
__________200811__________66__________379
__________200812__________75__________396
__________200901__________62__________388
__________200902__________53__________377
__________200903__________63__________381
__________200904__________67__________386
Six months is obviously no magic number. I'd like the solution to be flexible enough to use for 3, 12, 18, or 24 month periods as well.Hi Frank,
can you consider building the rolling sums directly in your database using subselects in the select statement:
eg. select attr1, attr2,key2, (select sum(key1) from B where B.month<=A.month and B.month>=A.month-6) from A
Just create a key figure in your universe and add the subselect statement select sum(key1) from B where B.month<=A.month and B.month>=A.month-6 as select-clause.
ATTENTION: This is SQL pseudo code.
Regards,
Stratos -
I'm trying to create a calculated measure as a running total.
I'm using the following
SUM({Null:[TIME].[YMD].currentmember},[Measures].[Qty])
This is working fine except that I would like the measure only to show the running total up to todays date - right now if I am using the above and use my time hierachy together with this it shows me all dates in my time hierachy(which Means all future dates
which results in the same qty for the future dates)
How to avoid this ?
Also is there a way where I could use all of my Time hierachies and Time attributes together with this measure (and not only the one that I have specified like [TIME].[YMD]) so to speak are more dynamic solution ?
Thanks in advance,Hi Hcmj,
According to your description, you want to calculate running total for all the time attributes, right?
In Analysis Services, we can use YTD, QTD and MTD to to calculate running total for all the time attributes. We can calculate this measure in query directly or add the calculation to your cube. Please refer to the link below to see the detail information
about it.
http://aniruddhathengadi.blogspot.com/2011/03/how-to-calculate-ytd-qtd-mtd-and-wtd.html
http://www.powerpivotblog.nl/add-time-functions-like-ytd-to-ssas-using-the-add-business-intelligence-wizard/
Hope this helps.
Regards,
Charlie Liao
TechNet Community Support -
Calculating Running Totals in Columns
I am trying to calculate running totals in Dynamic columns
I have data that is monthly and want to create a running total in the columns.
Data Format in:
Material|Type|Month|Qty
Query Report Ex:
Material|Type| Nov-05| Dec-05| Jan-06| Feb-06
PART1| DEMAND| -42 EA| -46 EA| -33 EA| -3 EA
PART1| SUPPLY| 58 EA| 0 EA| 0 EA| 49 EA
Result| | 16 EA| -46 EA| -33 EA| 46 EA
I would like running total taken from totals from previous columns + current column total are dynamic:
Result| | 16 EA| -30 EA| -63 EA| -17 EA
.continues for more parts
PART2
Thanks,
Mike Walker
FMC Technologies Inc.I am still having problems with this.
I have not figured out a way to control the Results row that is genereated to be a running total. Without having the data also becoming a running total.
I am wanting an new running total line. And not the standard Results row unless I can make it a running total and it leaves the data alone.
Material|Type| Nov-05| Dec-05| Jan-06| Feb-06|....<Dynamic>
PART1| DEMAND| -42 EA| -46 EA| -33 EA| -3 EA|....<Dynamic>
PART1| SUPPLY| 58 EA| 0 EA| 0 EA| 49 EA|....<Dynamic>
Standard Results Row:
Result| | 16 EA| -46 EA| -33 EA| 46 EA
I want this. Running total of the standard results.
Result| | 16 EA| -30 EA| -63 EA| -17 EA
I will look more on this next week.
Thanks. -
Running Total Issue: How to calculate counts excluding suppressed records
Post Author: benny
CA Forum: Formula
Hello All:
I have a current report that gives the total counts of work requests. However, in my section expert, there are some records in the detail that are suppressed (if there isn't any backlog). The current running totals are counting all the records including the suppressed records. I think I need three formulas:1. Calculate the counts2. Calculate the counts excluding suppressed records3. Reseting the counts by group
May I ask if someone can give me an example of what I should do?
Thanks so much!
BennyPost Author: benny
CA Forum: Formula
Bettername,
Actually, I should have been more specific. This report is actually a PM backlog report. It displays all the work requests (PM) issued including the backlogged. There are 9 columns (including one called Backlog) for the different counts of the pm's based from the status codes (Issued, Material on Order, Completed, Cancelled, etc) of the work requests. The detail records of worke requests are grouped by shop and PM end date. The running totals are calculated at the pm date group level (group footer#2). Then based from those at the shop group level (group footer#1) there is a grand total of counts of the running totals. The detail records and pm end date group header (group header #2) are suppressed.
Now the foremen would like the report to just display all the backlogged PMs. Using the section expert, I suppressed all the PM issued that have no back log ({@ backlog = 0}) and just display the back logged pm's. This is where I run into the running total issue.
This is very involved report and I will use the column PM Issued as an example. I can still use the same logic as you suggested?
1. declaration formula:
whileprintingrecords;numbervar pmissued := 0;
2. Suppression formula that uses the variable:
whileprintingrecords;
numbervar pmissued;
if ({@ backlog = 0}) then pmissued:= pmissed else pmissued:=pmissuedr+1
3. Display formula:whileprintingrecords;
numbervar pmissued;
If this is the right track, then I can use the same example for the other columns.
Thanks so much.
Benny -
Calculate % on manual running total??
I have a three part manual running total that prints the final value in the report footer. That total is based on groups of cities and time spent by each city on a project. I'm trying to calculate the percentage of time they spent on the total project in each cities group footer. So, of course (citytime % totalprojecttime). However, since it's a manual running total it's calculating based on the time up until that point, so the first city is always at 100% because the manual running total and time spent by that city is always equal. Then the next percentage is only based on the first two cities total divided by that current city, etc. so that the only city that actually has a correct percentage is the last one because it's finally calculated the totals at that point.
I've tried various printing states (evaluate after, etc) but those aren't going to work because the total isn't done until the end. Without doing a subreport, is there anyway to calculate that properly?If you can't do a simple summary to derive total time for City, then you will need to develop a hidden subreport which you place in city group header, and use that total calculate total city time. You can then use a shared variable to holding the total city time to calculate your %ages.
Hidden subreport is a subreport will all sections suppressed and minmised so that it does not appear, it must be held in an unsuppressed section, you can section to underlay to ensure minimum space taken up.
Ian -
How to calculate a percentage of a Running Total?
Post Author: pvang
CA Forum: Formula
Hi folks, Quite new here to the forum and to Crystal Report. As you can tell, I've already stumbled upon a roadblock. Here is what I'm trying to do:I am grabbing employee names and the number of cases that they are working via a sql query. So the sql query will result in something like 'Bob', '403'; Bob being the employee and 403 being the number of cases he's working on. In the report, I have a running total that sums up the total number of cases. I want to determine the ratio of Bob's(and every other employee's) cases over the running total amount of cases. So, for demo purposes, Bob has 403 cases and the total amount of cases is 1612, Bob's ratio would be 25%(403/1612). The equation that I am using right now is: /{#RTotal})*100 and it is not working. The ratio starts at 100%(effectively because the running total after the first record is equal to his/her cases) and then drops off dramatically. I know why it is doing that, just don't want those results. I tried using the EvaluateAfter function to no avail. Is this possible? If so, how? Many thanks in advance.Post Author: rroberson
CA Forum: Formula
Sounds to me like you don't need to use a running total. Just group on name (bob) and do a normal total (not running total) for the group (group summary). You can just divide that group summary total by the grand total (another crystal summary) and mult by 100. -
Showing running totals on AR statatement Report
Hi All I need assistance in populating the Running totals on AR statement Report , I am trying to calculate the running total on the RDF using the (sum Over Partition ) and Not on the RTF template please assist .
here is my query below :
select customers.customer_name,
detail.customer_id,
detail.customer_site_use_id,
:CP_ACC_NAME,
:CP_ACC_NUM,
:CP_BRNCH_NAME,
:CP_COL_EMAIL,
:CP_COL_PHONE,
:CP_BRANCH_NR,
decode( (select meaning
from ar_lookups
where lookup_type = 'INV/CM/ADJ' and lookup_code = detail.class), 'Payment', apply_date, trx.trx_date) TRX_DATE,
trx.INVOICE_CURRENCY_CODE,
trx.INVOICE_CURRENCY_CODE INVOICE_CURRENCY_CODE_BAL,
NVL(trx.term_due_date,trx.TRX_DATE) term_due_date,
detail.customer_id cst_id,
detail.customer_site_use_id cst_site_id,
detail.customer_trx_id,
detail.trx_number,
(select meaning
from ar_lookups
where lookup_type = 'INV/CM/ADJ' and lookup_code = detail.class) class,
detail.amount_full_original,
detail.end_bal * -1 , (detail.end_bal + detail.amount_full_original)* -1 closing_balance ,
detail.amount_full_original - detail.the_order * -1 closing_bal,
(detail.amount_full_original - detail.running_total) running_total ,
detail.running_tot ,
customers.customer_name address1,
customers.address1 address2,
customers.address2 address3,
customers.address3 address4,
customers.city||' '||customers.state address5,
customers.country||' '||customers.postal_code address6,
addr.address1 rm_address1,
addr.address2 rm_address2,
addr.address3 rm_address3,
addr.address4 rm_address4,
addr.address5 rm_address4,
:p_as_of_date_from date_from,
to_char(to_date(:p_as_of_date_to,'DD-MON-YYYY'),'DD-Mon-YYYY') date_to,
addr.org_id rm_org_id,
rtrim(to_char(sysdate,'DD')||' '||to_char(sysdate,'Month'))||' '||to_char(sysdate, 'YYYY') curr_date
from (select customer_id, CUSTOMER_SITE_USE_ID, trx.CUSTOMER_TRX_ID,trx.TRX_NUMBER, null apply_date,ps.class,ps.AMOUNT_DUE_ORIGINAL amount_full_original, the_trx.end_bal,the_trx.running_total , the_trx.running_tot , 1 the_order
select customer_trx_id, sum(acctd_end_bal) end_bal , running_total , running_tot
SELECT ps.customer_trx_id ,
sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
NULL,to_date(:p_as_of_date_from))
* ps.amount_due_remaining) start_bal,
sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
NULL,to_date(:p_as_of_date_to))
* ps.amount_due_remaining) end_bal,
sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
NULL,to_date(:p_as_of_date_from))
* ps.acctd_amount_due_remaining) acctd_start_bal,
sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
NULL,to_date(:p_as_of_date_to))
* ps.acctd_amount_due_remaining) acctd_end_bal ,
(sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
NULL,to_date(:p_as_of_date_from))
* ps.amount_due_remaining) + sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
NULL,to_date(:p_as_of_date_to))
* ps.acctd_amount_due_remaining) ) running_total ,
sum((sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
NULL,to_date(:p_as_of_date_from))
* ps.amount_due_remaining) + sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
NULL,to_date(:p_as_of_date_to))
* ps.acctd_amount_due_remaining) )) over (partition by ps.customer_trx_id order by ps.customer_trx_id)running_tot
FROM ar_payment_schedules_all ps
WHERE ps.payment_schedule_id+0 > 0
--JF2 AND ps.gl_date_closed >= to_date(:p_as_of_date_from)
AND ps.class IN ( 'CB', 'CM','DEP','DM','GUAR','INV')
AND ps.gl_date <= to_date(:p_as_of_date_to)
and org_id = nvl(:P_ORG_ID,org_id)--1246
--and customer_id = :p_customer_id --1075
--and CUSTOMER_SITE_USE_ID = :p_customer_site_id --1066
--and customer_trx_id = 66291
--'|| l_ps_org_where ||'
GROUP BY ps.customer_trx_id ,ps.acctd_amount_due_remaining , ps.gl_date,ps.gl_date_closed ,ps.class , rownum
ps.customer_trx_id ,
sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
ra.gl_date,to_date(:p_as_of_date_from))
* ( ra.amount_applied + NVL(ra.earned_discount_taken,0)
+ NVL(ra.unearned_discount_taken,0))) start_bal,
sum(ar_calc_aging.begin_or_end_bal(ps.gl_date,ps.gl_date_closed,
ra.gl_date,to_date(:p_as_of_date_to))
* ( ra.amount_applied + NVL(ra.earned_discount_taken,0)
+ NVL(ra.unearned_discount_takenHi
Yes i would like more help as i have never used group by roll up before
SELECT p.employee_number,
p.full_name employee_name,
DECODE (p.sex, 'M', 'Male', 'F', 'Female') gender,
(DECODE (p.per_information4,
'01', 'Indian',
'02', 'African',
'03', 'Coloured',
'04', 'White')) race,
p.original_date_of_hire,
a.effective_start_date startdate_current_position,
RTRIM (SUBSTR (ps.NAME, 1, INSTR (ps.NAME, ';')), ';') current_position,
ho.NAME current_organization,
xx_return_company_name(a.person_id, a.effective_start_date) current_company,
RTRIM (SUBSTR (ps1.NAME, 1, INSTR (ps1.NAME, ';')),';') previous_position,
ho1.NAME previous_organization,
xx_return_company_name(a1.person_id, a1.effective_start_date) previous_company,
a1.effective_start_date startdate_prev_position
FROM per_assignments_v2 a,
per_assignments_v2 a1,
per_all_people_f p,
per_all_positions ps,
per_all_positions ps1,
hr_all_organization_units_tl ho,
hr_all_organization_units_tl ho1
WHERE a1.person_id = a.person_id
AND NVL (a1.position_id, 9) <> a.position_id
AND a1.effective_end_date = a.effective_start_date - 1
AND p.person_id = a.person_id
and ho.ORGANIZATION_ID=ps.ORGANIZATION_ID
and ho1.ORGANIZATION_ID=a1.ORGANIZATION_ID
AND a.effective_start_date BETWEEN p.effective_start_date AND p.effective_end_date
AND a.position_id = ps.position_id
and p.EMPLOYEE_NUMBER not in ('1','2','3')
AND a1.position_id = ps1.position_id(+)
order by p.full_name -
Running Total - How to summarize a formula field?
I'm sorry if this comes over as stupid but I have got myself quite messed up and am not 100% au fait with Crystal Reporting.
The aim of my report is to calculate the costs of selected tests and to calculate a grand total of all tests at the end.
I have created a group of jobtests.TestTypeName
Details
1. testTypeName - to show Test Name that is being calcutaed - Database field
2. Count ({jobTests.testTypeName}, {jobTests.testTypeName}) - to show number of tests of that type - this is a formula field
3. Analysis1 - to show the cost of that test type - Database field
4. {@CountTests/TestType} * {jobTests.AnalysisN1} - to show the number of tests per test type mulitplied by the cost of that test type - this is a formula field
Report footer
Count ({jobTests.testTypeName}) - to count the total number of tests
MY PROBLEM - I need to see the sum of 4, this would be my grand total
Trying to run the Running Total I can't get it to Summarize the field 4 because it is a formula field.
What can I do?
Thanks.You can't do a SUM on a formula that uses another aggregate function. However, for both 4 and your grand total, you just need to SUM() (with ",{jobTests.testTypeName}" for the #4 calc), as the database field will be the cost for each test in each record.
HTH,
Carl -
Oracle report running total Resseting balance
Dear All,
I am developing report on Oracle R12 fixed Assets, I have to calculate the running total for each asset.
In brief
Asset 1
cost Deprciation Adjusted Cost
50 - 2 48
48 -5 45
45 - 4 41
I achieved that by using
if :p_val is null then
:result := nvl(:cost,0)-nvl(:depriciation,0);
:P_val :='5';
return :result;
else
:result := nvl(:result,0)-nvl(:depriciation,0) ;
return :result;
end if;
working fine
But problem is when the next asset start on same report
Asset 2
cost Deprciation Adjusted Cost
100 5 36
it substracts the last total (running total of previous asset with depriciation which was 41 in this example).
Oracle Champs pl advice me how to solve this.
I really dont got any idea how to solve this.
thanksDear,
Thanks for your reply , in your reply what you said I tried this but in pl/sql I am not actually achieving the result. The balance is not resetting at next group if you give one accurate line it would be really helpfull.
thanks -
Require a formula to calc the diff between 2 running total fields in a crosstab
Post Author: PJM
CA Forum: General
Hi,
I have built a crosstab in Crystal XI with the following columns:
PROFILED BUDGET (a) EXPENDITURE TO DATE (b) VARIANCE (a-b)
The profiled budget and expenditure to date columns are both running total fields. I want the variance column to show the difference between the budget and expenditure.
To set the variance field up as a running total, I assume that I would have to specify that I want this formula evaluated after the budget and expenditure fields , however, I can't work out how to do this on a crosstab.
Moving the crosstab to the report footer has had no impact.
If I try to create a basic formula using the running totals, I get the error message "A summary has been specified on a non-recurring field" - I can't find an explanation of this error message on the help menu.
Can anyone help with this please?overtime hours are calculated after 40. If I work 12 on monday, thats 12 regulars hours. not sure about others states laws but here in wisconsin we consider overtime after 40 only, not after 8 daily. at least thats how my company calculates overtime. lets say I work 10 hours a day, monday thru thursday, thats 40 hours regular time. anything after that is overtime. our weekly work schedule starts on sunday and ends on saturday. so on my bi-weekly time log, if i work 10 hrs a day monday thru thursday, i want 10hrs each day in regular hours cell, then when i work friday and or saturday, i want those hours in overtime hours. the main problem im having is: if i reach 40 hours in the middle of a day, i want the regular of that day to end and the overtime to pick up on the same day.
here is a basic example of how i want regular and overtime to look. of course the values will be duration not just numbers. hope this helps explain what i need a bit better. -
Running Total Issue or Possibly Formula Issue in Crystal Reports 9
Post Author: Jeffs23
CA Forum: Formula
My issue involves two formula's - @TotalTime and @Converted Time and a Running Total (RTotal0).
@TotalTime{Data.ApptTime}/60@Converted Timenumbervar x := {#RTotal0};totext(truncate(x),0,"")" Hrs "totext(remainder(x,truncate(x))*60,0,"") + " Mins"Running Total (RTotal0)
Field to Summarize - @TotalTime
Type of Summary - sum
Under Evaluate Section:
"Use a Formula":
onfirstrecord or
{Data.ResourceStart} <> previous({Data.ResourceStart}) or
{Data.Resource} <> previous({Data.Resource})
) and
minimum({Data.ApptKind},{Data.ResourceStart}) = 1 AND
maximum({Data.Column},{Data.ResourceStart}) >= '1'
Reset on change of field {Data.Resource}
A little background:My report deals with a Doctors schedule. In the doctors schedule, a appointment is booked and is by default placed into Column 1. It always defaults to Column 1. If the provider elects to double book their time and schedule another patient at the exact same time, the second appointment hits column 2. It expands in essence. It is possible to have up to 4 appointments in one time slot. This is why we wait forever at the Doctors office - appointments get overbooked because patients cancel or no show frequently and the provider would rather have the patients wait then risk no appointment at all. My Client wants the "TOTAL TIME" a provider was "scheduled" to see patients, not the time they actually saw the patients. So if the Provider was scheduled to see patients from 8 am to noon and had patients doublebooked for every time slot, I only want to report the overall time he saw patients regardless of the doublebooking, triplebooking or quadruplebooking. So the total time for my example should be 4 hours not 8 hours. The good news is this is painfully close to being correct! What is currently happening, is if the schedule contains more than 1 facility the time calculates wrong. I think my issue may be in the running Total but not 100% sure. I need it to calculate time on each facility - {Data.Facility}.Post Author: Jeffs23
CA Forum: Formula
I had some minor issues with my formulas and Running Total so I modified them alittle:
@TotalTime
If {Data.ApptTime} = 0 then 0else {Data.ApptTime}
@Converted Time
If {#RTotal0} = 0 then "--"else ToText(Truncate({#RTotal0}/60),0,"") + " Hour(s), " + ToText(Remainder({#RTotal0},60),0,"") + " Min(s)"
My running total stayed the same.......
Field to Summarize - @TotalTime Type of Summary - sum Under Evaluate Section: "Use a Formula":(onfirstrecord or{Data.ResourceStart} <> previous({Data.ResourceStart}) or{Data.Resource} <> previous({Data.Resource}) ) andminimum({Data.ApptKind},{Data.ResourceStart}) = 1 AND maximum({Data.Column},{Data.ResourceStart}) >= '1' Reset on change of field {Data.Resource}
Some fake sample data:
Resource = Francis, William MD
Facility 1: River Oaks Main Clinic
Facility 2: Western Medical Hospital
Date of Service = 10/25/2007
From 7:15 am to 11:45 am, Patients were treated at Facility 1: River Oaks Main Clinic *** (total time = 4 hours 30 min)
From 12:15 pm to 1:00 pm, Patients were treated at Facility 2: Western Medical Hospital *** (total time = 45 min)
From 1:00 pm to 3:15 pm, Patients were treated at Facility 1: River Oaks Main Clinic *** (total time = 2 Hours 15 min)
The report should tell me Total time at River Oaks Main Clinic = 6 Hours 45 min and 45 min for Western Medical Hospital. What it currently is doing, is reporting the 6 Hours 45 min on the River Oaks Main Clinic and 7 Hours 30 min on the Western Medical Hospital. The time for this facility should be 45 minutes, yet its taking the full provider time and throwing it into this second facility. I am assuming its because the Running total tells it "Reset on change of field {Data.Resource}". Somehow, I need it to evaluate on both the Resource and the Facility. Any suggestions? -
Running Total of a Calculated Member
Hi Friends ,
Need help in calculating the Running Total of a calculated member . I am using the below Query to calculate but it is not showing correct Values.
Query :
WITH
set
[FUNCTIONAL BENEFITS]
as
ORDER(
[FUNCTIONAL BENEFITS].[FUNCTIONAL BENEFITS].children,[Measures].[ANNUAL UNIT CASES WEIGHTED VALUE]
,DESC)
member AUCWEIGHT as
[Measures].[ANNUAL UNIT CASES WEIGHTED VALUE],
FORMAT_STRING='##0.0'
member
[Running Total]
AS
SUM({null:[FUNCTIONAL BENEFITS].[FUNCTIONAL BENEFITS].CurrentMember},[Measures].[ANNUAL UNIT CASES WEIGHTED VALUE]),
FORMAT_STRING='##0.0'
MEMBER [Measures].[AUCWV_PRCT] AS
([Running Total]/[Measures].[TotalSuM])*100,
FORMAT_STRING='##0.0'
member [CummalativePercent] as
(SUM({null:[FUNCTIONAL BENEFITS].[FUNCTIONAL BENEFITS].currentmember},[Measures].[AUCWV_PRCT]))
SELECT {
AUCWEIGHT,[Running Total],
[Measures].[TotalSuM],[Measures].[AUCWV_PRCT],[CummalativePercent]}on columns,
NON EMPTY ([FUNCTIONAL BENEFITS])
DIMENSION PROPERTIES PARENT_UNIQUE_NAME ON rows
FROM [RRMiningDS1_CUBE]
Output :
DiMENSION
AUCWEIGHT
RunningTotal
TotalSum
AUCWV_PRCT
CUMMULATIVEPERCENT
CORRECTCUMMULATIVEPERCENT
A
62605.4
661634.6
1345632.2
49.2
1271.2
49.2
B
38587.9
425278.7
1345632.2
31.6
545.5
80.8
C
35894.5
370057.9
1345632.2
27.5
485.2
108.3
D
30246.4
48345.3
1345632.2
3.6
4.9
111.9
The CUMMALITIVEPERCENT is coming wrong .
I have mentioned the Correct CummulativePercent. as it should be the Running sum of AUCWV_PRCT i.e
49.2+31.6+27.5+3.6=111.9
Please help . where i am making the mistake
Thanks
Rakesh k DharHi R,
It might be as simple as adding solve_order = 99 to the cumulative calc. This tells the formula engine to do the cumulative calculation after the %.
Richard -
Oracle report running total Resetting balance on next group
Dear All,
I am developing report on Oracle R12 fixed Assets, I have to calculate the running total for each asset.
In brief
Asset 1
cost Deprciation Adjusted Cost
50 - 2 48
48 -5 45
45 - 4 41
I achieved that by using
if :p_val is null then
:result := nvl(:cost,0)-nvl(:depriciation,0);
:P_val :='5';
return :result;
else
:result := nvl(:result,0)-nvl(:depriciation,0) ;
return :result;
end if;
working fine
But problem is when the next asset start on same report
Asset 2
cost Deprciation Adjusted Cost
100 5 36
it substracts the last total (running total of previous asset with depriciation which was 41 in this example).
Oracle Champs pl advice me how to solve this.
I really dont got any idea how to solve this.
thanksDear,
Thanks for your reply , in your reply what you said I tried this but in pl/sql I am not actually achieving the result. The balance is not resetting at next group if you give one accurate line it would be really helpfull.
thanks
Maybe you are looking for
-
Problem with an incoming message. For example, during my conversation the second line receives a call, I hear the sound in dynamics such as "piiiip piiiip," but when in this situation I recieve SMS and i hear established melody and I do't hear the pe
-
IBY_PAYMENTA_ALL.PAYMENT_REFERENCE_NUMBER
Hello, Not sure if anyone has the answer for this. In 11i when the batch is submitted and failed for validation the ap_selected_invoice_checks_all.check_number has a value, in R12 what I understood is this table is obsolete. Instead I am using iby_p
-
Display PDF in different window by reading Binary file in MIME folder.
Hi all, I've kept binary file in MIME folder and I'm trying to read the contents of it. and I'm trying to display contents in pdf format in separate window. For this I was able to read the file by using FileInputStream byte[] bytes = new byte[1000];
-
How to CREATE an IDOC of name WMTC1D01 for Transfer Orders-STOs??
Hi Experts, I need to CREATE a IDOC-WMTC1D01 for Stock Transfer Orders-STOs and must execute it. So, in this regard, request u that, let me know that, 1 - How I can CREATE the IDOC-WMTC1D01 for STOs? 2 - Then, after creating it, How to execute it?
-
I put new ram in my G5 last month. Things were fine until a couple days ago. I started getting kernel panics and was unable to run superduper because of bad permissions. Diskutility was unable to fix persmissions. So I bought DiskWarrior and removed