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 DesiredOutput

I 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

Similar Messages

  • How to bridge (fill) gaps when converting a 2006 geometry  into a 2002 geometry

    Is it at all possible to bridge (fill) gaps when converting a 2006 geometry into a single 2002 geometry. I have a solution for the conversion from 2006 to 2002 provided by BHall but upon further investigation investigation of my dataset some of the multi line polygons have gaps which I need to fill and I am not sure how to go about this.
    Here is a simple example of what I am trying to achieve
    Before
    SELECT (sdo_geometry(2006, 81989, NULL,
                    mdsys.sdo_elem_info_array(1,2,1,5,2,1,9,2,1,13,2,1),
                    mdsys.sdo_ordinate_array(16,0.999,16.998,-0.001,17.253,-0.001,18.003,0.999,18.003,0.999,19.001,0.999,19.001,0.999,19.999,-0.001)))
      FROM dual
    After
    SELECT (sdo_geometry(2006, 81989,NULL,
                   mdsys.sdo_elem_info_array(1,2,1),
                   mdsys.sdo_ordinate_array(16,0.999,17.253,-0.001,18.003,0.999,19.001,0.999,19.999,-0.001))) FROM dual    
    Thanks in advance

    Okay Roché,
    You might need to break this problem down into smaller parts for the forum.  All your examples show the gap being replaced by a single vertice - e.g. you want to "snap" the gap together.  I'd suggest this is just complicating your question.  Once the gap is filled (with a line) then you can run SDO_UTIL.REMOVE_DUPLICATE_VERTICES afterwards to remove the new line if its below your tolerance.  I think that Bryan's code wrapped in remove duplicate vertices will solve your second scenario.  But overall I think it would be helpful to focus just on the filling and leave the snapping for a follow-up question.
    So back to scenario #1, below is some code I wrote a while back that might do what you want or at least get you started.     Note that the input must be a multistring and the multistring cannot be "spaghetti".  In other words each line in the multistring must be disjoint or at most touch other lines only at endpoints. The goal is to sift through the lines and create a single linestring using the smallest gaps.  It's not subtle and will indeed produce bad geometries if the inputs are setup in an impossible manner.  There are also some rare geodetic bugs with SDO_GEOM.RELATE that crop up.  So you'll note I test both distance and relate in some places.  That's intentional though kind of dumb.
    Hopefully this helps.  If you improve the code please shoot a copy back to me.
    Cheers,
    Paul   
    CREATE OR REPLACE PACKAGE dz_gap_fill
    AUTHID CURRENT_USER
    AS
       FUNCTION linear_gap_filler(
           p_input            IN  MDSYS.SDO_GEOMETRY
          ,p_tolerance        IN  NUMBER DEFAULT 0.05
       ) RETURN MDSYS.SDO_GEOMETRY;
    END dz_gap_fill;
    CREATE OR REPLACE PACKAGE BODY dz_gap_fill
    AS
       FUNCTION fast_point(
           p_x             IN  NUMBER
          ,p_y             IN  NUMBER
          ,p_z             IN  NUMBER DEFAULT NULL
          ,p_m             IN  NUMBER DEFAULT NULL
          ,p_srid          IN  NUMBER DEFAULT 8265
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF p_x IS NULL
          OR p_y IS NULL
          THEN
             RAISE_APPLICATION_ERROR(-20001,'x and y cannot be NULL');
          END IF;
          -- Step 20
          -- Do the simplest solution first
          IF  p_z IS NULL
          AND p_m IS NULL
          THEN
             RETURN SDO_GEOMETRY(
                 2001
                ,p_srid
                ,SDO_POINT_TYPE(
                     p_x
                    ,p_y
                    ,NULL
                ,NULL
                ,NULL
          END IF;
          -- Step 30
          -- Do the other wilder choices
          IF p_z IS NULL
          AND p_m IS NOT NULL
          THEN
             RETURN SDO_GEOMETRY(
                 3301
                ,p_srid
                ,SDO_POINT_TYPE(
                     p_x
                    ,p_y
                    ,p_m
                ,NULL
                ,NULL
          ELSIF p_z IS NOT NULL
          AND   p_m IS NULL
          THEN
             RETURN SDO_GEOMETRY(
                 3001
                ,p_srid
                ,SDO_POINT_TYPE(
                     p_x
                    ,p_y
                    ,p_z
                ,NULL
                ,NULL
          ELSIF p_z IS NOT NULL
          AND   p_m IS NOT NULL
          THEN
             RETURN SDO_GEOMETRY(
                 4401
                ,p_srid
                ,NULL
                ,SDO_ELEM_INFO_ARRAY(1,1,1)
                ,SDO_ORDINATE_ARRAY(p_x,p_y,p_z,p_m)
          ELSE
             RAISE_APPLICATION_ERROR(-20001,'ERR!');
          END IF;
       END fast_point;
       FUNCTION get_start_point(
          p_input        IN  MDSYS.SDO_GEOMETRY
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
          int_dims PLS_INTEGER;
          int_gtyp PLS_INTEGER;
          int_lrs  PLS_INTEGER;
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF p_input IS NULL
          THEN
             RETURN NULL;
          END IF;
          -- Step 20
          -- Gather information about the geometry
          int_dims := p_input.get_dims();
          int_gtyp := p_input.get_gtype();
          int_lrs  := p_input.get_lrs_dim();
          -- Step 30
          -- Handle point and multipoint inputs
          IF int_gtyp = 1
          THEN
             RETURN p_input;
          ELSIF int_gtyp = 5
          THEN
             RETURN SDO_UTIL.EXTRACT(p_input,1);
          END IF;
          -- Step 40
          -- Return results
          IF int_dims = 2
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,NULL
                ,NULL
                ,p_input.SDO_SRID
          ELSIF  int_dims = 3
          AND int_lrs = 3
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,NULL
                ,p_input.SDO_ORDINATES(3)
                ,p_input.SDO_SRID
          ELSIF  int_dims = 3
          AND int_lrs = 0
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,p_input.SDO_ORDINATES(3)
                ,NULL
                ,p_input.SDO_SRID
          ELSIF  int_dims = 4
          AND int_lrs IN (4,0)
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,p_input.SDO_ORDINATES(3)
                ,p_input.SDO_ORDINATES(4)
                ,p_input.SDO_SRID
          ELSIF  int_dims = 4
          AND int_lrs = 3
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(1)
                ,p_input.SDO_ORDINATES(2)
                ,p_input.SDO_ORDINATES(4)
                ,p_input.SDO_ORDINATES(3)
                ,p_input.SDO_SRID
          ELSE
             RAISE_APPLICATION_ERROR(-20001,'ERR!');
          END IF;
       END get_start_point;
       FUNCTION get_end_point(
          p_input        IN  MDSYS.SDO_GEOMETRY
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
          int_dims PLS_INTEGER;
          int_gtyp PLS_INTEGER;
          int_lrs  PLS_INTEGER;
          int_len  PLS_INTEGER;
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF p_input IS NULL
          THEN
             RETURN NULL;
          END IF;
          -- Step 20
          -- Gather information about the geometry
          int_dims := p_input.get_dims();
          int_gtyp := p_input.get_gtype();
          int_lrs  := p_input.get_lrs_dim();
          int_len  := p_input.SDO_ORDINATES.COUNT();
          -- Step 30
          -- Handle point and multipoint inputs
          IF int_gtyp = 1
          THEN
             RETURN p_input;
          ELSIF int_gtyp = 5
          THEN
             RETURN SDO_UTIL.EXTRACT(
                 p_input
                ,SDO_UTIL.GETNUMELEM(p_input)
          END IF;
          -- Step 40
          -- Return results
          IF int_dims = 2
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 1)
                ,p_input.SDO_ORDINATES(int_len)
                ,NULL
                ,NULL
                ,p_input.SDO_SRID
          ELSIF  int_dims = 3
          AND int_lrs = 3
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 2)
                ,p_input.SDO_ORDINATES(int_len - 1)
                ,NULL
                ,p_input.SDO_ORDINATES(int_len)
                ,p_input.SDO_SRID
          ELSIF  int_dims = 3
          AND int_lrs = 0
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 2)
                ,p_input.SDO_ORDINATES(int_len - 1)
                ,p_input.SDO_ORDINATES(int_len)
                ,NULL
                ,p_input.SDO_SRID
          ELSIF  int_dims = 4
          AND int_lrs IN (4,0)
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 3)
                ,p_input.SDO_ORDINATES(int_len - 2)
                ,p_input.SDO_ORDINATES(int_len - 1)
                ,p_input.SDO_ORDINATES(int_len)
                ,p_input.SDO_SRID
          ELSIF  int_dims = 4
          AND int_lrs = 3
          THEN
             RETURN fast_point(
                 p_input.SDO_ORDINATES(int_len - 3)
                ,p_input.SDO_ORDINATES(int_len - 2)
                ,p_input.SDO_ORDINATES(int_len)
                ,p_input.SDO_ORDINATES(int_len - 1)
                ,p_input.SDO_SRID
          ELSE
             RAISE_APPLICATION_ERROR(-20001,'ERR!');
          END IF;
       END get_end_point;
       FUNCTION is_spaghetti(
           p_input             IN  MDSYS.SDO_GEOMETRY
          ,p_tolerance         IN  NUMBER DEFAULT 0.05
       ) RETURN VARCHAR2
       AS
          num_tolerance    NUMBER := p_tolerance;
          ary_strings      MDSYS.SDO_GEOMETRY_ARRAY := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_starts       MDSYS.SDO_GEOMETRY_ARRAY := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_ends         MDSYS.SDO_GEOMETRY_ARRAY := MDSYS.SDO_GEOMETRY_ARRAY();
          int_count        PLS_INTEGER;
          ary_start_count  MDSYS.SDO_NUMBER_ARRAY := MDSYS.SDO_NUMBER_ARRAY();
          ary_end_count    MDSYS.SDO_NUMBER_ARRAY := MDSYS.SDO_NUMBER_ARRAY();
          ary_inside_count MDSYS.SDO_NUMBER_ARRAY := MDSYS.SDO_NUMBER_ARRAY();
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF p_input IS NULL
          THEN
             RETURN NULL;
          ELSIF p_input.get_gtype = 2
          THEN
             RETURN 'FALSE';
          ELSIF p_input.get_gtype <> 6
          THEN
             RAISE_APPLICATION_ERROR(-20001,'input gtype must be 2 or 6');
          END IF;
          IF num_tolerance IS NULL
          THEN
             num_tolerance := 0.05;
          END IF;
          -- Step 20
          -- Break multistring into single linestrings with nodes
          int_count := SDO_UTIL.GETNUMELEM(p_input);
          ary_strings.EXTEND(int_count);
          ary_starts.EXTEND(int_count);
          ary_ends.EXTEND(int_count);
          ary_start_count.EXTEND(int_count);
          ary_end_count.EXTEND(int_count);
          ary_inside_count.EXTEND(int_count);
          FOR i IN 1 .. int_count
          LOOP
             ary_strings(i) := SDO_UTIL.EXTRACT(p_input,i);
             ary_starts(i)  := get_start_point(ary_strings(i));
             ary_ends(i)    := get_end_point(ary_strings(i));
          END LOOP;
          -- Step 30
          -- Loop through and count the nodes connections
          FOR i IN 1 .. int_count
          LOOP
             ary_start_count(i)  := 0;
             ary_end_count(i)    := 0;
             ary_inside_count(i) := 0;
             FOR j IN 1 .. int_count
             LOOP
                IF i != j
                THEN
                   IF SDO_GEOM.RELATE(
                      ary_starts(i),
                      'DETERMINE',
                      ary_strings(j),
                      num_tolerance
                   ) IN ('TOUCH','CONTAINS','COVERS','ON')
                   THEN
                      ary_start_count(i) := ary_start_count(i) + 1;
                   ELSIF SDO_GEOM.RELATE(
                      ary_ends(i),
                      'DETERMINE',
                      ary_strings(j),
                      num_tolerance
                   ) IN ('TOUCH','CONTAINS','COVERS','ON')
                   THEN
                      ary_end_count(i) := ary_end_count(i) + 1;
                   ELSIF SDO_GEOM.RELATE(
                      ary_strings(i),
                      'DETERMINE',
                      ary_strings(j),
                      num_tolerance
                   ) IN ('TOUCH','CONTAINS','COVERS','OVERLAPBYINTERSECT')
                   THEN
                      ary_inside_count(i) := ary_inside_count(i) + 1;
                   END IF;
                END IF;
             END LOOP;
             IF ary_start_count(i) > 1
             OR ary_end_count(i) > 1
             OR ary_inside_count(i) > 0
             THEN
                RETURN 'TRUE';
             END IF;
          END LOOP;
          RETURN 'FALSE';
       END is_spaghetti;
       FUNCTION points2segment(
           p_point_one              IN  MDSYS.SDO_POINT_TYPE
          ,p_point_two              IN  MDSYS.SDO_POINT_TYPE
          ,p_srid                   IN  NUMBER
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
       BEGIN
          IF ( p_point_one.Z IS NULL AND p_point_two.Z IS NOT NULL )
          OR ( p_point_one.Z IS NOT NULL AND p_point_two.Z IS NULL )
          THEN
             RAISE_APPLICATION_ERROR(
                -20001,
                'both points must have the same number of dimensions, point_one Z is ' ||
                NVL(TO_CHAR(p_point_one.Z),'') ||
                ' and point_two Z is ' ||
                NVL(TO_CHAR(p_point_two.Z),'')
          END IF;
          IF p_point_one.Z IS NULL
          THEN
             RETURN SDO_GEOMETRY(
                 2002
                ,p_srid
                ,NULL
                ,SDO_ELEM_INFO_ARRAY(1,2,1)
                ,SDO_ORDINATE_ARRAY(p_point_one.X,p_point_one.Y,p_point_two.X,p_point_two.Y)
          ELSE
             RETURN SDO_GEOMETRY(
                 3002
                ,p_srid
                ,NULL
                ,SDO_ELEM_INFO_ARRAY(1,2,1)
                ,SDO_ORDINATE_ARRAY(p_point_one.X,p_point_one.Y,p_point_one.Z,p_point_two.X,p_point_two.Y,p_point_two.Z)
          END IF;
       END points2segment;
       FUNCTION points2segment(
           p_point_one              IN  MDSYS.SDO_GEOMETRY
          ,p_point_two              IN  MDSYS.SDO_GEOMETRY
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
          int_gtype1 PLS_INTEGER;
          int_dims1  PLS_INTEGER;
          int_gtype2 PLS_INTEGER;
          int_dims2  PLS_INTEGER;
          point_one  MDSYS.SDO_POINT_TYPE;
          point_two  MDSYS.SDO_POINT_TYPE;
       BEGIN
          int_gtype1 := p_point_one.get_gtype();
          int_dims1  := p_point_one.get_dims();
          int_gtype2 := p_point_two.get_gtype();
          int_dims2  := p_point_two.get_dims();
          IF  int_gtype1 = 1
          AND int_gtype2 = 1
          AND int_dims1  = int_dims2
          AND p_point_one.SDO_SRID = p_point_two.SDO_SRID
          THEN
             NULL;  -- Good
          ELSE
             RAISE_APPLICATION_ERROR(
                 -20001
                ,'both point objects must be points and have the same number of dimensions and SRIDs'
          END IF;
          IF int_dims1 = 4
          THEN
             RETURN SDO_GEOMETRY(
                 4402
                ,p_point_one.SDO_SRID
                ,NULL
                ,SDO_ELEM_INFO_ARRAY(1,2,1)
                ,SDO_ORDINATE_ARRAY(
                     p_point_one.SDO_ORDINATES(1)
                    ,p_point_one.SDO_ORDINATES(2)
                    ,p_point_one.SDO_ORDINATES(3)
                    ,p_point_one.SDO_ORDINATES(4)
                    ,p_point_two.SDO_ORDINATES(1)
                    ,p_point_two.SDO_ORDINATES(2)
                    ,p_point_two.SDO_ORDINATES(3)
                    ,p_point_two.SDO_ORDINATES(4)
          ELSE
             -- Use the sdo_point_type method for the rest
             IF p_point_one.SDO_POINT IS NOT NULL
             THEN
                point_one := p_point_one.SDO_POINT;
             ELSE
                IF int_dims1 = 3
                THEN
                   point_one := SDO_POINT_TYPE(
                       p_point_one.SDO_ORDINATES(1)
                      ,p_point_one.SDO_ORDINATES(2)
                      ,p_point_one.SDO_ORDINATES(3)
                ELSE
                   point_one := SDO_POINT_TYPE(
                       p_point_one.SDO_ORDINATES(1)
                      ,p_point_one.SDO_ORDINATES(2)
                      ,NULL
                END IF;
             END IF;
             IF p_point_two.SDO_POINT IS NOT NULL
             THEN
                point_two := p_point_two.SDO_POINT;
             ELSE
                IF int_dims1 = 3
                THEN
                   point_two := SDO_POINT_TYPE(
                        p_point_two.SDO_ORDINATES(1)
                       ,p_point_two.SDO_ORDINATES(2)
                       ,p_point_two.SDO_ORDINATES(3)
                ELSE
                   point_two := SDO_POINT_TYPE(
                       p_point_two.SDO_ORDINATES(1)
                      ,p_point_two.SDO_ORDINATES(2)
                      ,NULL
                END IF;
             END IF;
             RETURN points2segment(
                 p_point_one   => point_one
                ,p_point_two   => point_two
                ,p_srid        => p_point_one.SDO_SRID
          END IF;
       END points2segment;
       FUNCTION linear_gap_filler(
           p_input            IN  MDSYS.SDO_GEOMETRY
          ,p_tolerance        IN  NUMBER DEFAULT 0.05
       ) RETURN MDSYS.SDO_GEOMETRY
       AS
          sdo_input     MDSYS.SDO_GEOMETRY := p_input;
          num_tolerance NUMBER;
          int_counter   PLS_INTEGER;
          ary_edges     MDSYS.SDO_GEOMETRY_ARRAY;
          ary_starts    MDSYS.SDO_GEOMETRY_ARRAY;
          ary_ends      MDSYS.SDO_GEOMETRY_ARRAY;
          ary_nearest   MDSYS.SDO_NUMBER_ARRAY;
          ary_distance  MDSYS.SDO_NUMBER_ARRAY;
          num_temp      NUMBER;
          num_nearest   NUMBER;
          int_winner    PLS_INTEGER;
          int_winner2   PLS_INTEGER;
          sdo_point1    MDSYS.SDO_GEOMETRY;
          sdo_point2    MDSYS.SDO_GEOMETRY;
          boo_done      BOOLEAN;
          num_one       NUMBER;
          num_two       NUMBER;
          int_looper    PLS_INTEGER := 1;
       BEGIN
          -- Step 10
          -- Check over incoming parameters
          IF num_tolerance IS NULL
          THEN
             num_tolerance := 0.05;
          END IF;
          IF sdo_input IS NULL
          OR sdo_input.get_gtype() <> 6
          THEN
             RETURN sdo_input;
          END IF;
          IF is_spaghetti(sdo_input,p_tolerance) = 'TRUE'
          THEN
             RETURN sdo_input;
          END IF;
          <>      ary_edges     := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_starts    := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_ends      := MDSYS.SDO_GEOMETRY_ARRAY();
          ary_nearest   := MDSYS.SDO_NUMBER_ARRAY();
          ary_distance  := MDSYS.SDO_NUMBER_ARRAY();
          -- Step 20
          -- Break multistring into edges and start and end nodes
          int_counter := SDO_UTIL.GETNUMELEM(sdo_input);     
          ary_edges.EXTEND(int_counter);
          ary_starts.EXTEND(int_counter);
          ary_ends.EXTEND(int_counter);
          FOR i IN 1 .. int_counter
          LOOP 
             ary_edges(i)  := SDO_UTIL.EXTRACT(sdo_input,i);
             ary_starts(i) := get_start_point(ary_edges(i));
             ary_ends(i)   := get_end_point(ary_edges(i));
          END LOOP;
          -- Step 30
          -- Determine the closest endpoints
          ary_nearest.EXTEND(int_counter);
          ary_distance.EXTEND(int_counter);
          FOR i IN 1 .. int_counter
          LOOP
             num_nearest := NULL;
             int_winner := NULL;
             FOR j IN 1 .. int_counter
             LOOP
                IF j != i
                THEN
                   num_temp := SDO_GEOM.SDO_DISTANCE(
                       ary_edges(i)
                      ,ary_edges(j)
                      ,num_tolerance
                   IF num_nearest IS NULL
                   OR num_temp < num_nearest
                   THEN
                      num_nearest := num_temp;
                      int_winner := j;
                   END IF;
                END IF;
             END LOOP;
             ary_nearest(i) := int_winner;
             ary_distance(i) := num_nearest;
          END LOOP;
          -- Step 40
          -- Find the smallest gap
          int_winner := NULL;
          num_nearest := NULL;
          FOR i IN 1 .. int_counter
          LOOP
             IF num_nearest IS NULL
             OR ary_distance(i) < num_nearest
             THEN
                 int_winner := i;
                 num_nearest := ary_distance(i);
                 int_winner2 := ary_nearest(i);
             END IF;
          END LOOP;
          -- Step 50
          -- Determine the endpoints to connect
          num_one := SDO_GEOM.SDO_DISTANCE(
             get_start_point(ary_edges(int_winner)),
             ary_edges(int_winner2),
             num_tolerance
          num_two := SDO_GEOM.SDO_DISTANCE(
             get_end_point(ary_edges(int_winner)),
             ary_edges(int_winner2),
             num_tolerance
          IF ( num_one = 0 AND SDO_GEOM.RELATE(
             get_start_point(ary_edges(int_winner)),
             'ANYINTERACT',
             ary_edges(int_winner2),
             num_tolerance
          ) = 'TRUE' )
          OR ( num_two = 0 AND SDO_GEOM.RELATE(
             get_end_point(ary_edges(int_winner)),
             'ANYINTERACT',
             ary_edges(int_winner2),
             num_tolerance
          ) = 'TRUE' )
          THEN
             sdo_point1 := NULL;
          ELSIF num_one < num_two
          THEN
             sdo_point1 := get_start_point(ary_edges(int_winner));
          ELSE
             sdo_point1 := get_end_point(ary_edges(int_winner));
          END IF;
          num_one := SDO_GEOM.SDO_DISTANCE(
             get_start_point(ary_edges(int_winner2)),
             ary_edges(int_winner),
             num_tolerance
          num_two := SDO_GEOM.SDO_DISTANCE(
             get_end_point(ary_edges(int_winner2)),
             ary_edges(int_winner),
             num_tolerance
          IF ( num_one = 0 AND SDO_GEOM.RELATE(
             get_start_point(ary_edges(int_winner2)),
             'ANYINTERACT',
             ary_edges(int_winner),
             num_tolerance
          ) = 'TRUE' )
          OR ( num_two = 0 AND SDO_GEOM.RELATE(
             get_end_point(ary_edges(int_winner2)),
             'ANYINTERACT',
             ary_edges(int_winner),
             num_tolerance
          ) = 'TRUE' )
          THEN
             sdo_point2 := NULL;
          ELSIF num_one < num_two
          THEN
             sdo_point2 := get_start_point(ary_edges(int_winner2));
          ELSE
             sdo_point2 := get_end_point(ary_edges(int_winner2));
          END IF;
          -- Step 50
          -- Smash together
          IF sdo_point1 IS NULL
          OR sdo_point2 IS NULL
          THEN
             sdo_input := SDO_UTIL.CONCAT_LINES(
                ary_edges(int_winner),
                ary_edges(int_winner2)
          ELSE
             sdo_input := SDO_UTIL.CONCAT_LINES(
                SDO_UTIL.CONCAT_LINES(
                   ary_edges(int_winner),
                   points2segment(sdo_point1,sdo_point2)
                ary_edges(int_winner2)
          END IF;
          boo_done := TRUE;
          FOR i IN 1 .. int_counter
          LOOP
             IF i NOT IN (int_winner,int_winner2)
             THEN
                sdo_input := SDO_UTIL.APPEND(sdo_input,ary_edges(i));
                boo_done := FALSE;
             END IF;
          END LOOP;
          -- Step 60
          -- Check if valid if returning
          IF sdo_input.get_gtype() = 2
          OR boo_done = TRUE
          THEN
             RETURN sdo_input;
          END IF;
          int_looper := int_looper + 1;
          GOTO TOP_OF_IT;
       END linear_gap_filler;
    END dz_gap_fill;

  • Error when using running total variable in formula

    This is probably an easy syntax problem, but I'm fairly new to Crystal reporting.  I created a running total variable (count) called InquiryTypeSubtotal that simply counts the number of records.  I have one grouping level, and in the group footer I'd like to print a line showing the total count for that group that looks like
    Total inquiries for Assistive Technology: 3
    To accomplish this I'm using a formula field with the following syntax:
    "Total inquiries for " + {CnAttrCat_1.CnAttrCat_1_Description} + ": " + ToText(@InquiryTypeSubtotal)
    When I try to check the formula, I get the error message "The ) is missing."  What am I doing wrong?
    Thanks,
    Alec

    I put in the curly brackets so my formula now reads
    "Total inquiries for " + {CnAttrCat_1.CnAttrCat_1_Description} + ": " + ToText({@InquiryTypeSubtotal})
    Now when I check the formula I get the error message "This field name is not known."
    Alec

  • 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.

  • 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

  • MDX - Running total

    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.

  • Keep one record during running total

    Post Author: masto123
    CA Forum: General
    Hi there,
    i am new to crystal so please bare with me.
    I have a field which displays a part number and a running total on the qty on hand. I wish to only display one record when the running total reaches a negative figure. See below on how the data looks like.
    ABC(PART ID)    4
    ABC    2  (WISH TO SUPRESS)
    ABC    0  (WISH TO SUPRESS)
    ABC    -2   (ONLY WISH TO DISPLAY THE RECORD WHEN THE PART(ABC OR DBD) GOES NEGATIVE AND ONLY SHOW THAT RECORD.
    ABC    -4   (I WISH TO SUPRESS RECORDS APART FROM THE FIRST RECORD THAT GOES NEGATIVE)
    DBD    6
    DBD    3
    DBD    0
    DBD    -3
    DBD     -6
    thankyou

    Post Author: Charliy
    CA Forum: General
    You'll probably need  variables so you can look at the value before you subtract the quantity from it.  It's not clear to me from your example where the initial quantity comes from. 
    Basically your formula needs to do this:
    IF the current balance is positive and subtracting the new transacation does not make it negative then just subtract
    IF the current balance is positive and subtractine the new transaction makes it negative then subtract and set print flag to YES
    IF the current balance is negative then set the print flag to NO
    Use a Print suppress formula that loks at the print flag variable.

  • How to calculate the total of bytes transferred when I submit a PDF Form in A. Reader

    Hello,
    I need to know some way for calculate the total of bytes transferred when I submit a PDF form using JavaScript, hereby:
    b ******************************************************************
    i var service_url = http://some_webservice/;
    i var send_type = "PDF";
    i var doc = event.target;
    i doc.submitForm( { cURL: service_url, cSubmitAs: send_type } );
    b ******************************************************************
    b The reason:
    I need to indicate the percentage of bytes sent to the server, in real time. Adobe Acrobat shows a progress bar and the transferred quantity in bytes, but Adobe Reader doesn't. Is in this case, when I need to find a way in order to make something similar.
    b Than you for your time.

    You can use SharePoint Designer and calculate the total in xslt view. Refer to the following post for more information
    http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2009/04/24/how-to-total-calculated-columns-in-a-sharepoint-list.aspx
    http://blog.metrostarsystems.com/2012/12/03/jennys-sharepoint-tip-sum-calculated-columns/
    Cheers,

  • Running total in group header doesn't display when it's at page bottom

    Post Author: Charles Denight
    CA Forum: Formula
    Hi, Using v.9 of Crystal Reports I've created some running totals using a cross-tab workaround to get the running totals into the group headers, but when the group header falls at the bottom of the page then the running total doesn't show up.Would appreciate knowing why and how to fix this.

    Replacing an item that is malfunctioning because of a manufacturing error is the bare minimum I would expect from customer service for any electronics item.
    The thing Apple does extremely well is their flat fee policy for repairs on their computers.
    I managed to break my MacBook pretty seriously (logic board needed to be replaced) and I'm sure it cost them more to repair the unit than the $328 they charged me.
    I probably would have been angry if it was something minor, but I'm guessing that most repairs to screens/motherboards/etc cost more than their flat fees.

  • Running Total does not reset when group changes

    I have a manual running total for group3 that does not reset for group2
    Group2 Header (Order Status 3=Open,4=Closed)
    WhilePrintingRecords;
    currencyVar WIP=0;
    Group3 footer (Order Number)
    WhilePrintingRecords;
    currencyVar  WIP;
    WIP := WIP + {@NETWIP}
    Group2 footer
    WhilePrintingRecords;
    currencyVar WIP;
    There are no Repeat Group header on any of the groups
    Will add Group1 total when this part works.

    I am not sure if you made a typo when making your post but you are missing a colon when resetting your variable
    change from this
    currencyVar WIP=0;
    to this
    currencyVar WIP:=0;

  • 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!
    Benny

    Post 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

  • Misc transactions running total turns blank when using different exp type

    Hi,
    I would like to ask for some advise on how to fix this issue:
    When entering miscellaneous transaction with 2 different expenditure type (Labor and Material) the running total will be blank. But if we enter the same expenditure type (both Labor or Material) the running total will have values.
    Any idea how to fix this? Thanks!
    Application: 11.5.10.2
    Edited by: JulieAnn on Mar 27, 2012 11:21 PM

    This was fixed by changing the "Pixel Format" in the catalyst control center to "RGB (Full RGB)".. Somehow it got changed to "YcBcr".
    I removed the /etc/ati/amdpcsdb file that the fglrx driver likes to put settings in and did a fresh reinstall of catalyst-test and everything looks good now. Really no idea how the pixel profile got changed. Also noticed that my resolution was much lower than it should have been (which for some reason doesn't affect XBMC which runs in native resolution no matter what?), but that was an easy fix of adding Mode "1920x1080" to my Display section in xorg.

  • 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.

Maybe you are looking for