A/R Aging query

Hello Guys,
I am trying to understand the structure of SAP BI A/R aging query. I have a question about the definition of the monthly buckets.
In one of the selections, we have
Item status - open
Net due date - 1 - 30 Days
Document Date <= net due date
Amount = Debit/Credit amount in local currency
My questions is: what do we mean by  document date <= net due date
Here net due date is an interval of 1-30 days
Eg: Assume user entered key/due date - 3/31/2011
Net due date bucket for 1-30 days mean: Net due date <= 3/30/2011 and Net due date >= 3/1/2011
what will be the value for document date?
Please let me know.
Thanks.

Hi George,
Document Date <= Key Date
Mean the report should consider only those documents that are posted before User Key Date.

Similar Messages

  • Aging Query

    Hi,
    I am working on an aging query.  This query must have the sales org in the column and the quantity and SO count should be bucketed depending on difference between the current date and another date.
    Output should resemble as below:
    Sorg   <30days       >31<60  >60<90    >90
                count | Qty    Qty        Qty        Qty
    1111         xxx           xxx       xxx         xxx
    I created a structure in the Rows and then created formula variables "Current date-given date < 30" and another variable " Current date-given date >31<60" etc
    I get correct values if I include the given date and the Sdoc number into my query.  If I move the Sdoc number to free char, my output values are zeros.
    How can I get a summarize view of my output without including the Sdoc number into the query.  I did try searching for similar issue within the forum.  Dint find it helpful So any feedback is appreciated.
    Thanks,
    Rad

    Hi Rad,
    When you include sales organization alone in the column, you get wrong result...that happens coz several document numbers are falling under 1 organization, when you run query it accumulates the data based on query design. As you have only sales org which in turn contains many sales document's so it aggregates all of them and dont able to identify what date it should pick up for calculation's hence output is not fine.
    So any how u have to go to lowest level for date calculation but you might not have to show them in your query, then please include the sales document number and in display please select hide and supress result display for document number.
    Hope its clear to you.
    Thanks
    dipika

  • AR Aging query

    Hi Experts,
    I have a client who needs a AR Aging query that only shows totals (not individual BP balances) for 30, 60, 90, 120 and over 120 days.
    I can get the total with this query, but do now know how to go about the 30,60....
    SELECT SUM(T0.BalanceSys) AS 'Total AR'
    FROM  OCRD T0
    WHERE T0.CardType = 'C'
    Any help would be appreciated.
    Marli

    Gordon,
    Thanks so much for this help.
    I have tested this in a Demo database and found that this results is not the same as the Aging report. Then I tested it in another database where I do not have as many transactions and still this was not the same.
    I started to take only parts of the query and run them seperately. In this database I have only $80,954.85 due in the >120 days aging. Nothing else. Here is what this part of the query brought back: $425,929.06
    SELECT SUM(T2.SYSDeb- T2.SYSCred)
    FROM  dbo.OCRD T0 INNER JOIN dbo.JDT1 T2 ON T2.ShortName = T0.CardCode
    WHERE T2.[Account] = '_SYS00000000010'
    AND T0.CardType = 'C' AND DateDiff(DD,T2.Duedate,GetDate()) >120
    When I delete the DateDiff part I get the right total: $80,954.85
    SELECT SUM(T2.SYSDeb- T2.SYSCred)
    FROM  dbo.OCRD T0 INNER JOIN dbo.JDT1 T2 ON T2.ShortName = T0.CardCode
    WHERE T2.[Account] = '_SYS00000000010'
    AND T0.CardType = 'C'
    Thanks for your help,
    Marli

  • Customer Ageing query

    Hi
    We have a standard query in BW for customer ageing query 0FIAR_C03_Q0002.
    In this query we have several dates
    1. Document date
    2. Posting date
    3. Base line date
    4. Net due date.
    Its very tough to understand what is the significance of these dates and how the query is calculated based on which date. I am finding it difficult to xplani to the client about this report.
    Can anyone explain me about these dates and how the query is calculated on which date.
    Regards
    Annie

    Hi
    When i execute the query, there is a variable called KEY DATE(*). What is that date. When i see in the query designer, there is no variable specified in filter, free characteristics or Rows. Then from where is this varialbe is getting popping up.
    and when i enter a date, how it is going to calculate. I am very much confused. need your inputs.
    Regards
    Annie

  • What is aging report or aging query

    hi
      i am suresh,
            what is aging report or aging query.
            can any one tell.

    Hello Suresh,
    Based on the business requirements you design the inventory aging report. Here are few scenarios:
    1) Technical Name: 0IC_C03_Q0021
    Use
    This query displays the inventory aging for selected materials per week and calendar year, and is used in the KPI monitor.
    2) Technical Name: 0IC_C01_Q0009
    Use
    The percentage of total gross inventory (based on value) covered by expected demand within a specific time bucket.
    3)
    With this picking strategy the system proposes the oldest quant in the storage type as the quant that should be transferred.
    The system generally calculates the "age" (length of time in storage) of a quant on the basis of the goods receipt posting date from the Inventory Management (IM) application component. The system automatically sets the goods receipt date in the quant and in the transfer requirement for every goods receipt posting in IM. When the transfer order is created, this date is copied over to the quant record of the destination storage bin.
    You can accept the goods receipt date that the system sets or you can enter a different date. Regardless of whether the system proposes the goods receipt date or you enter a different date, the date is used to calculate the age of the quant. This date influences the sorting sequence for each material.
    Prerequisites
    When you define the storage type record to use this strategy, enter f in the Picking strategy field.
    you can find more details in Help.sap.com which fields needs to used etc.
    Hope this helps,
    Bye,
    Naga.
    Message was edited by: Naga Timmaraju

  • Inventory Ageing query performance

    Hi All,
       I have created inventory ageing query on our custom cube which is replica of 0IC_C03. We have data from 2003 onwards. the performance of the query is very poor the system almost hangs. I tried to create aggregates to improve performance but its failed. What i should do to improve the performance and why the aggregate filling is failed. Cube have compressed data. Pls guide.
    Regards:
    Jitendra

    Inaddition to the above posts
    Check the below points ... and take action accordingly to increase the query performance.
    mainly check --Is the Cube data Compressed. it will increase the performance of the query..
    1)If exclusions exist, make sure they exist in the global filter area. Try to remove exclusions by subtracting out inclusions.
    2)Check code for all exit variables used in a report.
    3)Check the read mode for the query. recommended is H.
    4)If Alternative UOM solution is used, turn off query cache.
    5)Use Constant Selection instead of SUMCT and SUMGT within formulas.
    6)Check aggregation and exception aggregation on calculated key figures. Before aggregation is generally slower and should not be used unless explicitly needed.
    7)Check if large hierarchies are used and the entry hierarchy level is as deep as possible. This limits the levels of the hierarchy that must be processed.
    Use SE16 on the inclusion tables and use the List of Value feature on the column successor and predecessor to see which entry level of the hierarchy is used.
    8)Within the free characteristics, filter on the least granular objects first and make sure those come first in the order.
    9)If hierarchies are used, minimize the number of nodes to include in the query results. Including all nodes in the query results (even the ones that are not needed or blank) slows down the query processing.
    10)Check the user exits usage involved in OLAP run time?
    11)Use Constant Selection instead of SUMCT and SUMGT within formulas.
    12)
    Turn on the BW Statistics: RSA1, choose Tools -> BW statistics for InfoCubes(Choose OLAP and WHM for your relevant Cubes)
    To check the Query Performance problem
    Use ST03N -> BW System load values to recognize the problem. Use the number given in table 'Reporting - InfoCubes:Share of total time (s)' to check if one of the columns %OLAP, %DB, %Frontend shows a high number in all InfoCubes.
    You need to run ST03N in expert mode to get these values
    based on the analysis and the values taken from the above  - Check if an aggregate is suitable or setting OLAP etc.
    Edited by: prashanthk on Nov 26, 2010 9:17 AM

  • How to create ageing query?

    Hi Folks,
    Could you give me an idea how to create an AGEING query  by below requirement ?
    Purpose is to calculate the Ageing, which can be defined as the difference between the Document Date and the current date.
    As the current date is not practical (the AR gets updated once a month, and financial ageing reports usually report compared with end-of-the-month), I propose the
    u2018Last working day of previous month.
    When this interval is created per document the total revenue should be divided into columns based on the ageing:
    1-30 days
    31-60 days
    61-90 days
    91-120 days
    121-360 days
    >360 days.
    Reporting Fields  are :
    Rows & Columns
    Company code
    SAP ID
    Customer name
    Country
    City
    Address
    Postal code
    Total AR
    Current
    1-30
    31-60
    61-90
    91-120
    >120
    >360
    Appreciate your response on this.  Thanks  : Surendra

    Hi,
    In this  you follow th ebelow steps easy
    Go To Create CK F menu-----
    Craete  one Formual Variable on Document Date  with replacement path as 0document posted date
    one more variable Formula Variable with customer exit  on cal cal day
    for that getting the current date  write below code
    WHEN 'ZCDATE'.
    CLEAR: L_S_RANGE.
    L_S_RANGE-LOW = SY-DATUM.
    L_S_RANGE-SIGN = 'I'.
    L_S_RANGE-OPT = 'EQ'.
    APPENDL_S_RANGETO E_T_RANGE.
    ENDCASE.
    when you are creating varaible there is tab in that ( last tab) currency/unit  here you should mention date.
    now use these two formula varaibles Current date formula variable- document date formula varaible
    now uare getting the days
    based on your requirement
    use that
    same Ckf
    one ckf cuurent datevariable -posting datevariable  >30( it gives 0-30)
    in next Ckf current adte - posting date >30<60
    like that you can create as you like.
    Thansk & Regarsd,
    sathish

  • Customer aging query - show balance as of a specific date

    I am working on a query for a vendor aging to show information that is not available in the vendor aging report. However, I want to show the balance that was open at a specific point in time. i.e. today is Aug 17 and i want to show what was due at June 30. All the June invoices have been paid as of Aug 17 so i cannot use docstatus. The aging report gives you the option to select Vendors with a zero balance and reconciled transactions. How do i show that information in a query?

    Hi Vicki,
    I'm trying to do the exact same thing. Get the aging balance at any point in time in verion 2007.
    Have you succeded so far?.
    I use to run a query to get the balance at any point in 2005 like this..
    SELECT     T2.CardCode, T2.CardName , T0.[BatchNum], T0.[TransId], T0.[TransType], T1.[CreatedBy], T1.[RefDate], T1.[DueDate], T1.[MthDate],
    T1.[LineMemo], T0.[Ref1], T1.[BaseRef], T1.[Credit], T1.[Debit], T1.[FCCredit], T1.[FCDebit], T1.[SYSCred],
    T1.[SYSDeb], T1.[SourceLine], T1.[Ref1], T1.[LineType], T1.[TaxDate], T1.[Account], T1.FCCurrency, T1.[ObjType]
    FROM     [dbo].[OJDT] T0
    INNER     JOIN [dbo].[JDT1] T1 ON T1.[TransId] = T0.TransId
    INNER     JOIN [dbo].[OCRD] T2 ON T1.[ShortName] = T2.CardCode
    WHERE     T1.[Account] IN (SELECT AcctCode FROM oact WHERE LocManTran = 'Y' AND GroupMask = 1)
    AND      T1.[RefDate] <= '20091026'
    AND      (T1.[MthDate] > '20091026'
    OR      T1.[IntrnMatch] = 0 )
    ORDER BY T0.[TransType], T1.[RefDate], T2.CardCode, T1.DueDate
    But this baby shows more documents than needed and a lot of work has to be done to place payments on the right invoices to como up with the right balance age.
    I'd appreciate if you could help me out or let me know what have you found so far.
    Best,
    Ricardo Sada

  • Stock Aging Query/Report

    Dear all,
    We are on SAP B1 2007 PL42 and using Moving average as our cost valuation method.
    It doesn't have an inbuilt stock aging report, I have searched through the forum but none of the queries arebshowing the correct aging of stocks. Could anyone have a query/report/addon for stock aging?
    Kind Regards,
    Asif

    Hi,
    Try this one,with warehouse code as input parameter
    select b.code, b.name, b.Wh, b.Bal, b.Val,
    isnull(case when b.days <30 then b.bal end,0)'0-30 Days' ,
    isnull(case when b.days between 30 and 60 then b.bal end,0) '30-60 Days',
    isnull(case when b.days between 60 and 90 then b.bal end,0) '60-90 Days',
    isnull(case when b.days between 90 and 120 then b.bal end,0) '90-120 Days',
    isnull(case when b.days between 120 and 150 then b.bal end,0) '120-150 Days',
    isnull(case when b.days between 150 and 180 then b.bal end,0) '150-180 Days',
    isnull(case when b.days >180 then b.bal end,0) 'Above 180 Days'
    from (
    select a.code,a.name,a.wh,a.bal,a.val,datediff(dd,dt,getdate())'days'
    from (
    select max(t0.itemcode)'Code',max(t0.Dscription)'Name',
    max(t0.Warehouse)'Wh',
    sum(t0.inqty-t0.outqty)'Bal',sum(t0.transvalue)'Val',max(t0.docdate)'dt'
    from oinm t0 inner join oitm t1 on t0.itemcode=t1.itemcode
    where t0.warehouse='[%1]'
    group by t0.itemcode
    )a
    )b order by code

  • Open invoice customer ageing query

    I have set up a query to find a customer aging report - open ivoices. I just want to have open records... does anyone have a better query for this?
    SELECT     TOP (100) PERCENT dbo.OCRD.CardName, dbo.OCRD.Balance, (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 0 AND
                          30 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [0-30], (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE())
                          BETWEEN 31 AND 60 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [31-60], (CASE WHEN DATEDIFF(DD,
                          T0.REFDATE, GETDATE()) BETWEEN 61 AND 90 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [61-90],
                          (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) > 91 THEN CASE WHEN T1.SYSCred <> 0 THEN T1.SYSCred * - 1 ELSE T1.SYSDeb END ELSE 0 END) AS [90+],
                          dbo.OCRD.CardType, T1.TransType, T1.TransCode, T1.LineMemo, T1.BaseRef, dbo.OCRD.CardCode, T1.BalDueDeb
    FROM         dbo.OJDT AS T0 INNER JOIN
                          dbo.JDT1 AS T1 ON T1.TransId = T0.TransId INNER JOIN
                          dbo.OCRD ON dbo.OCRD.CardCode = T1.ShortName
    WHERE     (dbo.OCRD.Balance >= 1) AND (dbo.OCRD.CardType = 'C') AND (T1.BalDueDeb > 0)
    ORDER BY dbo.OCRD.CardName
    Regards,
    knut

    Knut,
    Try this:
    SELECT T2.CardName, T2.Balance,
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 0 AND
    30 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '0-30',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 31 AND
    60 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '31-60',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) BETWEEN 61 AND
    90 THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '61-90',
    (CASE WHEN DATEDIFF(DD, T0.REFDATE, GETDATE()) >90
    THEN CASE WHEN T1.SYSCred != 0 THEN -T1.SYSCred ELSE T1.SYSDeb END ELSE 0 END) AS '90+',
    T1.TransType, T1.TransCode, T1.LineMemo, T1.BaseRef, T2.CardCode
    FROM dbo.OJDT T0
    INNER JOIN dbo.JDT1 T1 ON T1.TransId = T0.TransId
    INNER JOIN dbo.OCRD T2 ON T2.CardCode = T1.ShortName
    WHERE (T2.Balance >= 1) AND (T2.CardType = 'C') AND (T1.BalDueDeb != T1.BalDueCred)
    Thanks,
    Gordon

  • Multi-Currency Customer Receivables Aging Query

    Hello Everyone,
    SAP B1 2005 SP 01 PL 42
    We cannot produce customer statements for multi-currency accounts (CND & USD) through the Customer Receivables Aging report.  The report converts all FC to LC which is not useful to the customer.
    The statement must show the open invoices in USD and open invoices in CND so that the customer can pay in the appropriate currency.
    We are attempting to create a query to solve this issue and assign a PLD to execute the calculations, but cannot see the best way to execute the task.
    The customer account balance (displaying only unreconciled tans.) would be the most reliable data set (form 809), but it is not available as a table in the query manager.  Any other table suggestions?
    We would like to avoid building the query from scratch (collecting all open invoices, credits, payments etc...) to avoid error.  We would also like to avoid exporting the data as this is very time consuming.  Any suggestions?
    Thanks in advance,
    Tamara

    We have found it better to set up two customers where different currencies are transacted - one in each currency. That way you can produce a statement in each currency.
    I know it's not a perfect solution, but a good work around?
    The only way to get the data you need would be to use OJDT and JDT1 tables, but you would need to join to the reconciliation table as well (OITR?) to get open transactions.

  • Statement of account aging query

    hi,
    im using 12.1.3
    what is the query to find out the aging of a particular ACCOUNT as shown on footer of STATEMENT OF ACCOUNTS report?

    Open the report using Reports Builder 10g and check the query used.
    Thanks,
    Hussein

  • Help with aging query. not sure how to acomplish this???

    Guys im a bit stuck usually i have a slight idea how to even start my query but for this particular one I just dont even know where to start to tackle
    i have a table like so.
           create table TRRACCD (
           TRRACCD_GRNT_CODE varchar2(6),
           TRRACCD_TRANS_dATE date,
           TRRACCD_AMOUNT number(17,2),
           trraccd_detail_code varchar2(6))with data like so
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('15-FEB-10', 'DD-MM-RR'),19764.77,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('12-MAR-10', 'DD-MM-RR'),2054.29,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('20-APR-10', 'DD-MM-RR'),4111.46,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('14-MAY-10', 'DD-MM-RR'),2570.1,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('10-JUN-10', 'DD-MM-RR'),2176.16,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('12-JUL-10', 'DD-MM-RR'),4756.29,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('13-AUG-10', 'DD-MM-RR'),28500.62,'GCSH');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('16-AUG-10', 'DD-MM-RR'),3602.3,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('17-SEP-10', 'DD-MM-RR'),3995.79,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('11-OCT-10', 'DD-MM-RR'),3413.6,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('11-NOV-10', 'DD-MM-RR'),2119.86,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('10-DEC-10', 'DD-MM-RR'),5905.52,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('10-DEC-10', 'DD-MM-RR'),12008.21,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('11-JAN-11', 'DD-MM-RR'),-10574.05,'GBIL');
    INSERT INTO TRRACCD (TRRACCD_GRNT_CODE, TRRACCD_TRANS_DATE, TRRACCD_AMOUNT, TRRACCD_DETAIL_CODE) VALUES ('400364',to_date('11-JAN-11', 'DD-MM-RR'),20241.9,'GBIL');however what i need to do is end up with an aging for the items summarize so the expected output should be something like
    tbrraccd_grnt_Code      30-60                    60-90         over90
    400364                      20,241.90              2119.86       7,370.09 
    if your confused about how i arrived at the 7370.90 is because i have to subtract entries with GCSH on them and i also need to take
    entries that are - and applied them to the oldest period if the balance of the period is positive. im inclined to say that i can do this with sql but the only other way i can think of is using plsql?... any suggestions or solutions would be greatly appreciated.
    the closest that i have gotten to acomplishing this query without pl is this. i know is lame but i need help.
    SELECT TRRACCD_GRNT_CODE,
           TRRACCD_TRANS_dATE,
           TRRACCD_AMOUNT,
           trraccd_detail_code,
           round(sysdate - TRRACCD_TRANS_dATE) "total days"
           --sum(case when round(sysdate - TRRACCD_TRANS_dATE)>190 then "greater then 190"end )
           FROM TRRACCD
           where trraccd_grnt_Code = '400364'
           ORDER BY TRRACCD_GRNT_CODE,
                    TRRACCD_TRANS_dATE,
                    trraccd_detail_code;  

    Hi, Miguel,
    I should have mentioned this before: I'm assuming SYSDATE is some point on January 22, 2011, after 00:00. I don't think this has caused any confusion so far, but if the discussion continues for a day or two, let's be clear about that.
    I think I see what you want regarding the rows where trraccd+detailcode='GSCH'. If we completly ignored all the GSCH rows, we would get this output:
    TRRACC       0-29      30-59      60-89    90-over
    400364   ...
    400404   19904.97    6625.27    4757.01   67618.68You want GSCH amounts to cancel other amounts in the last column only until that column reaches 0 ; the remaining GSCH amount will cancel amounts in to "60-89" column, again, only until that amount reaches 0 . If there is anything left over, it will cancel amounts in the "30-59" column, and if there is still some left over, the "0-29" column.
    To be specific, trraccd_grnt_code=400404 has a total of 72475.69 from GSCH rows. That counts against the "90-over" total.
    67618.68 - 72475.69 = -4757.01; you want to dispaly 0 in the "90-over" column, and apply the remaining 4757.01 to the next column to the left.
    That column contains 4757.01, which happens to be the exact maount left over from the previous subtraction, so you want to diesplay 0 in the "60-89" column.
    The remaining columns to the left should contain their regular totals.
    Here's one way to do that:
    WITH     got_col_num     AS
         SELECT     trraccd_grnt_code
         ,     CASE
                   WHEN  trraccd_detail_code != 'GCSH'     THEN  trraccd_amount
              END          AS net_amount
         ,     SUM ( CASE
                        WHEN trraccd_detail_code = 'GCSH'     THEN  trraccd_amount
                    END
                  ) OVER (PARTITION BY trraccd_grnt_code)     
                                 AS gsch_total
         ,     CASE
                  WHEN  trraccd_amount < 0               THEN  4
                  WHEN  trraccd_trans_date > SYSDATE - 30     THEN  1
                  WHEN  trraccd_trans_date > SYSDATE - 60     THEN  2
                  WHEN  trraccd_trans_date > SYSDATE - 90     THEN  3
                                            ELSE  4
              END          AS col_num
         FROM     trraccd
         WHERE     trraccd_trans_date     <= SYSDATE
    ,     got_sum          AS
         SELECT       trraccd_grnt_code
         ,       col_num
         ,       LEAST ( SUM (net_amount)
                     , GREATEST ( 0
                                , SUM (SUM (net_amount)) OVER ( PARTITION BY  trraccd_grnt_code
                                                                 ORDER BY        col_num   DESC
                                  - gsch_total
                   )  AS total
         FROM       got_col_num
         GROUP BY  trraccd_grnt_code
         ,       col_num
         ,       gsch_total
    SELECT       trraccd_grnt_code
    ,       SUM (CASE WHEN col_num = 1 THEN total END)     AS "0-29"
    ,       SUM (CASE WHEN col_num = 2 THEN total END)     AS "30-59"
    ,       SUM (CASE WHEN col_num = 3 THEN total END)     AS "60-89"
    ,       SUM (CASE WHEN col_num = 4 THEN total END)     AS "90-over"
    FROM       got_sum
    GROUP BY  trraccd_grnt_code
    ORDER BY  trraccd_grnt_code
    ;Whenever you want to understand a query like this, run just the first sub-query (in this case, got_col_num) and make sure you understand what it's doing. When you do, add one more sub-query, and make sure you understand what it's doing.
    Add morte columns to the display to help you understand it better. For example, when you get to the point where you're trying to understand the 2nd sub-query above, got_sum, you might run this query:
    WITH     got_col_num     AS
         SELECT     trraccd_grnt_code
         ,     CASE
                   WHEN  trraccd_detail_code != 'GCSH'     THEN  trraccd_amount
              END          AS net_amount
         ,     SUM ( CASE
                        WHEN trraccd_detail_code = 'GCSH'     THEN  trraccd_amount
                    END
                  ) OVER (PARTITION BY trraccd_grnt_code)     
                                 AS gsch_total
         ,     CASE
                  WHEN  trraccd_amount < 0               THEN  4
                  WHEN  trraccd_trans_date > SYSDATE - 30     THEN  1
                  WHEN  trraccd_trans_date > SYSDATE - 60     THEN  2
                  WHEN  trraccd_trans_date > SYSDATE - 90     THEN  3
                                            ELSE  4
              END          AS col_num
         FROM     trraccd
         WHERE     trraccd_trans_date     <= SYSDATE
    ,     got_sum          AS
         SELECT       trraccd_grnt_code
         ,       col_num
         ,       gsch_total
         ,       SUM (net_amount)               AS period_sum
         ,       SUM (SUM (net_amount)) OVER ( PARTITION BY  trraccd_grnt_code
                                              ORDER BY      col_num     DESC
                                   )         AS running_sum
         ,       LEAST ( SUM (net_amount)
                     , GREATEST ( 0
                                , SUM (SUM (net_amount)) OVER ( PARTITION BY  trraccd_grnt_code
                                                                 ORDER BY        col_num   DESC
                                  - gsch_total
                   )  AS total
         FROM       got_col_num
         GROUP BY  trraccd_grnt_code
         ,       col_num
         ,       gsch_total
    SELECT       *
    FROM       got_sum
    ORDER BY  trraccd_grnt_code
    ,            col_num
    ;which produces this output:
    TRRACC    COL_NUM GSCH_TOTAL PERIOD_SUM RUNNING_SUM      TOTAL
    400364          1   28500.62    20241.9     76146.2    20241.9
    400364          2   28500.62   17913.73     55904.3   17913.73
    400364          3   28500.62    2119.86    37990.57    2119.86
    400364          4   28500.62   35870.71    35870.71    7370.09
    400404          1   72475.69   19904.97    99005.93   19904.97
    400404          2   72475.69    6625.27    79100.96    6625.27
    400404          3   72475.69    4857.01    72475.69          0
    400404          4   72475.69   67618.68    67618.68          0The total column in that sub-query is very complicated, so break it down some. You can see that it is based on an analytic SUM whose argumenet is an aggregate SUM, all wrapped in LEAST and GREATEST. That can be very hard to underrstand, so break it down. Display the aggregate SUM by itself (period_sum) and also display the analytic SUM, without the GREATEST and LEAST.
    mlov83 wrote:
    where can i get more information about these types of querys?Can you be more specific? What types of queries do you mean? Complicated queries? Pivots? GROUP BY?
    ... I'm always leary of using a solution that i dont understand Excellent reaction!
    would you mind expalining it to me a little.Again, could you be more specific? I don't mind explaining things to you, but I don't want to explain parts you already understand. If something is new, you'll want to read the SQL Language manual, or other sources, anyway, so it's more efficient to do that first, and then post specific questions on this forum.
    An example of a more specific question is: "When I looked up "WITH clause" in the SQL Language reference, I found this page:
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9758
    but I don't understand where it says ...
    The query above says ... Is that what the manual is talking about when it says ...?"
    Another example of a good question is
    "The query you posted says ... I don't understand what that's doing. I looked for ... and ... but that didn't seem to have anything to do with this query. What should I look for?
    The Oracle 10 SQL Language manual is indexed pretty poorly. If you can't find something, it may not be your fault.

  • Stock Ageing Query With Stock Value

    Dear Experts,
    Greeting for the day...!
    I am using Batch wise stock, so consumption done by batch wise.
    Please forward me the query for the Product Code, Products Name, Batch No, Batch Qty (Under respective ageing days), Batch Amount (Under respective ageing days).
    The parameter will be from date & to date & group.
    Thanks in advance.
    Regards
    Datta Kharat

    Hi,
    Please check this thread:
    http://scn.sap.com/thread/3372541
    Thanks & Regards,
    Nagarajan

  • Aging query for an approval procedure

    I need to include the customer accounts receivable aging in a approval procedure. Is there any  way that I could have the query that is used in the report that SBO has.?

    Hi,
    The aging is not store in the certain table. I am not sure you could do that. The aging is vary and it is also difficult to include it. Although it seems that you could use terms based on user queries but it will take a lot of work. So, I suggest just use account balance of the customer.
    Rgds,

Maybe you are looking for