Date Grouping

Post Author: conrads
CA Forum: Formula
I have report that I need to group a range of eligibility records, I would like to display the min start date and max end date for each period of eligibility if there is no status change and no break in consecutive months of coverage. I am using Crystal XI and Oracle 10g. Here is an example of our data: Mem ID Plan ID Start Dt End Dt Status 255099 1917486 10/01/2003 06/30/2004 A 255099 1917493 07/01/2004 03/31/2005 A 255099 1917518 04/01/2005 12/31/2005 A 255099 1917522 01/01/2006 01/31/2006 A 255099 1917526 02/01/2006 06/30/2006 A 255099 1917530 07/01/2006 08/31/2006 H 255099 3359315 12/01/2006 01/31/2007 H 255099 4093936 04/01/2007 12/31/2099 A For the first group I need to display 10/01/2003 as the min start date and 06/30/2006 as the max end date. It should not include the next record of 07/01/2006 to 08/31/2006 since the status changed to "H". Can anyone help me with this?

Post Author: conrads
CA Forum: Formula
Yangster,  This is how I got the first record and last record to show.
if not onfirstrecord and {@Status Code} = previous({@Status Code})and {@Start Dt} = previous({@End Dt})then "" else totext({@Start Dt});
if not OnLastRecord and {@Status Code} = next({@Status Code})and {@End Dt} = next({@Start Dt})then "" else totext({@End Date})
Here is how my data looks and is formatted?
     Mem_id Plan Id     Start Dt         End Dt       Status  Date Begin      Date End
     255099   1917486   10/01/2003    06/30/2004   A       10/01/2003     255099   1917493   07/01/2004    03/31/2005   A     255099   1917518   04/01/2005    12/31/2005   A     255099   1917522   01/01/2006    01/31/2006   A     255099   1917526   02/01/2006    06/30/2006   A                             06/30/2006
     255099   1917530   07/01/2006    08/31/2006   H       07/01/2006     08/31/2006
     255099   3359315   12/01/2006    01/31/2007   H       12/01/2006     01/31/2007
     255099   4050419   04/01/2007    12/31/2099   A       04/01/2007     12/31/2099
I would like to show the dates between the Date Begin to be the same as the first record of that period and the end dates the same as the max date for that period so it looks something like this:
     255099   1917486   10/01/2003    06/30/2004   A       10/01/2003    06/30/2006     255099   1917493   07/01/2004    03/31/2005   A       10/01/2003    06/30/2006     255099   1917518   04/01/2005    12/31/2005   A       10/01/2003    06/30/2006     255099   1917522   01/01/2006    01/31/2006   A       10/01/2003    06/30/2006     255099   1917526   02/01/2006    06/30/2006   A       10/01/2003    06/30/2006
This is considered one eligible period since the status is the same and no breaks in consecutive months of covereage. Then I would like to suppress any other period that does not fall between the range of dates via a parameter entered by user.   I am unable to figure out how to do this.
Thanks

Similar Messages

  • AP Payment User Responsbility's Data Group to be assigned for application as Payables or Payments?

    Hi,
    I am in version R12.1.3 . I have a requirement to create a user who must have access only to create payments in AP module.So when i try to define a responsibility for this payment user
    there is a data group to be assigned. In this data group block for application there are 2 options i.e Payables & Payments? What should I select & what is the difference of selection one over the other?
    Appreciate your help.
    Thanks

    Hi,
    i did not see any difference .... I performed a test case, where i created a payment using the new responsibility i have created having data group application as Payments, the payment was successful ... Later i have modified the data group for this new responsibility from payments to payables, then the test payment i have made was also successful....
    Not sure about its impact, may be i am having responsibilities which has full access, hence i cannot see the difference in my environment ....
    Regards,
    Ivruksha

  • What is a data group and what use is it for?

    CAn some one explain me the concept of data group in EBS. What is it used for ? How does it enhance the security of Oracle Apps data ?
    I know that Data groups are used while defining a responsibility and are meant for data security purpose. But I want to know the conceptual details behind it.
    Thanks.

    Ok.. so with a data group we can have data security at Oracle schema level. I hope my understanding is correct.
    I can create a data base user called Sinha and create a data group with this user/schema.
    Now when I create a data group with this schema and assign it to a responsibility, which in turn is assigned to a user, he/she will have access only to those objects which are present in the schema called Sinha, right ?
    Now as all the objects in Oracle Apps are created under the Apps schema, what use this new data group (and schema) is of ?

  • Set date grouping option at run time

    Is there a way to change the date field grouping options at runtime?  What I would like to do is have the user select a parameter for monthly or weekly grouping; then set the "The section willl be printed:" area on the date group to either "for each week" or "for each month" based on the value of the parameter.

    Try to create two formula in the report like this
    @Monthly:
    whilereadingrecords;
    if {?Parameter}="Monthly" then
    {date field}
    @Weekly:
    whilereadingrecords;
    if {?Parameter}="Weekly" then
    {date field}
    Now remove the existing group GH1 in the report and insert a group on formula @Monthly and select for each month for this group.
    Now insert another group GH2 on the formula @Weekly and select for each week for this group in group options.
    Now the report works dynamically according to the selected value in the parameter.
    Hope this helps!
    Raghavendra

  • Consumption report Date to date ,Group & itemwise

    Dear Sap Expets,
    Can you please advise me that i want to make consumption report Date to date ,Group & itemwise ,in summary report (Total Qty and Value consumed).How is the possible it?
    Thanks
    mohit

    Hi,
    Use MB5B report for the same, it will give you qty & values for overall receipts and issues for certain period or else refer report MC.2
    Hope this will resolve your issue.
    Thanks & Regards,
    Sandesh Sawant

  • Converting Crystal Date Group to SQL Command

    When selecting the option to group on the server, I found that there are requirements in addition to selecting the option.
    I have a date grouping in Crystal like the following:
    dateadd("d", - weekday({table.date}, crMonday)+1,{table.date})
    Can this be converted to a SQL command?

    Hi Mark,
    Jyothi had given  an excellent query for you,  Congrats Jyothy!!
    But she didnt mantioned 'From clouse' on that.
    Let me correct that query with an example,
    My TableName: Invoice
    Primary Key: InvoicePID
    Date field:InvoiceDate
    Here the query will be
    select InvoicePID,  Dateadd(d,-(CASE  WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Monday' THEN 1
                            WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Tuesday' THEN 2     
                             WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Wednesday' THEN 3
                             WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Thursday' THEN 4
                             WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Friday' THEN 5
                             WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Saturday' THEN 6
                             WHEN DATEName(dw,Invoice.InvoiceDate ) = 'Sunday' THEN 7
    END
    )+1 ,Invoice.InvoiceDate)
    from Invoice
    You can change the tablename and field with respect to your DB.
    regards,
    Salah.

  • Error when creating volume on data group for acfs

    Hi,
    I want to create ACFS file system on solaris SPARC system which is running solaris 10.9. I have created data group successfully but i get an error when i try to create volume.
    ASMCMD> volcreate -G OEMLIB -s 30G oemlibvol1
    ORA-15032: not all alterations performed
    ORA-15472: volume library cannot be loaded. Platform may not support volume creation. (DBD ERROR: OCIStmtExecute)
    i read that solaris 10.8 or more support acfs and my oracle grid software is also 11.2 higher.
    what could be the issue? Do i need to manually load drivers for ADVM? where are they located?

    Thanks
    Thanks for your input.
    We are missing the ACFS binaries after we installed 11.2.0.1 GRID and Database on Solaris 10 Update 8.
    The following are missing from the GRID_HOME/bin:
    Acfsload, acfsroot, acfsdriverstate, acfsregitrymount, acfssinglefsmount.
    I see these in 11.2.0.1 version of a LINUX install in our datacenter but don’t see it in our Solaris Install.

  • Data Groups in EBS 11.5.10.2

    Hi ,
    Examining the current rows for the data groups , i found out that there is not even a record for the ORACLE ID which is different for the value APPS... in other words for all records the Oracle Id column of the form has the value APPS for the Standard Data Group...
    The above is true for both standard appls as well as custom....
    However , for a totally custom new application... isn't it better to register a new user(say it test) and in the relation between the Oracle Application Name and OracleId to assign this new db user to this new custom App...????
    And something else....
    I haven't understood why for the INV for example Application the Oracle Id user in the data group is APPS ... and not INV... since the basic tables/views for this INV APP are on INV db user.....!!!!
    Thanks a lot
    Sim

    Sim,
    You can select the ORACLE ID you want to assign your application. The application uses an ORACLE ID to access tables in the database. Each ORACLE ID allows access to a predefined set of tables in the database.
    For your custom application, you can assign it to a different Oracle ID (not APPS), but you need to make sure that the user have proper grants and synonyms. Such permissions are already granted to APPS user.
    More details can be found in:
    Oracle Applications System Administrator's Guide - Configuration
    http://download-uk.oracle.com/docs/cd/B25516_14/current/acrobat/115sacg.zip

  • IChart- x-axis data grouping

    Hi Experts,
    How can we do x-axis data grouping in icharts???
    In the below example I have shown a date and shift wise grouping in x-axis
    Is it possible in x-axis???
    Thanks in advance!!!
    Regards,
    Vinothkumar G.

    Already knew it is possible in bar chats.
    But my requirement is I need it in line charts.
    Thanks mate
    Vinoth

  • Use Date Group (Month) in a Results Filter

    Hyperion IR v 9
    I want to filter my results set by the Month Date Group.  I want Displayed in the column filter Jan, Feb, Mar....and so on.  However, when I drag that field to the filter and ask to "show values" it shows my actual dates, not the three character month value.  This monthly filter is essential for what I'm doing.  I tried creating a computed column off the month date group and set the datatype to text. All that did was retain the original date value again.  Is there a way around this?
    How can I do this?

    I've said it before in these forums:  To the maximum extent possible, avoid the built-in functions in computed items in Results.
    I've contacted Oracle about your specific deficiency (Month(column_name) returning a date rather than a month).  They say it's working as designed -- something about sorting properly.
    Use JavaScript.  Here's a definition for your computed item:
    ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][date_column.getMonth()]

  • Relation between Application and Data Group

    Hello All,
    Can someone please help me to get a query which tells me which Application is associated with which Data Group?
    Thanks,
    Moore

    Moore,
    Query FND_DATA_GROUP_UNITS_V -- http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_DATA_GROUP_UNITS_V&c_owner=APPS&c_type=VIEW
    If the view doesn't satisfy your requirements, then write your own query using the following tables:
    APPLSYS.FND_DATA_GROUPS
    http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_DATA_GROUPS&c_owner=APPLSYS&c_type=TABLE
    APPLSYS.FND_DATA_GROUP_UNITS
    http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_DATA_GROUP_UNITS&c_owner=APPLSYS&c_type=TABLE
    APPLSYS.FND_APPLICATION
    http://etrm.oracle.com/pls/et1211d9/etrm_pnav.show_object?c_name=FND_APPLICATION&c_owner=APPLSYS&c_type=TABLE
    Thanks,
    Hussein

  • Trying to get max date grouped by type

    hello,
    i have a request table with:
    request name
    request start date
    The requests run daily so i have multiple records. In answers i want to display request name and the max(request start date), grouped by request name. Is it possible to due this in answers only? if i must use the repository how do i do it? I'm new to building subject areas.

    You can do this in answers only, If you dont have access to RPD.
    Sol1: Create a report with two columns request name,request start date. Open pivot table and add request start date to measures and apply Aggregation of Max on date.
    sol2: Create a report with two columns request name,request start date, Change the Fx of request start date to max(request start date by request name) . This way table view also show request max date by request names.

  • How to migrate Data groups

    How to migrate data groups?? Is there any script for migrating datagroups using fndload ?? Or is there any special procedure to migrate them? Please help me.
    Thanks in advance.

    As per the FNDLOAD docs, you cannot use this tool to migrate the data groups and you will need to do it manually.
    You could log a SR to confirm this with Oracle Support.
    Thanks,
    Hussein

  • How to define Legislative Data group in HCM Extract?

    HI All,
    Can you please share the steps to define Legislative data group in HCM Extract ? During creation of HCM extract, I didn't find any option to define the Legislative data group , so my HCM Extract is created without having the Legislative data group and for that reason, I am not able to use extract rule Fast Formula (under a Legislative data group) in HCM Extract.
    Any suggestion would be helpful to me.
    Thanks & Regards,
    Sharmistha

    Hi Sharmistha,
    Once the extract is created there is no ability to add the LDG. A workaround i to export the extract and import it back inot9 the application - the import screen has LDG field.
    Regards,
    Elena

  • Date Grouping by specific interval

    Hi all,
    I have a case where i need to build a query to count the dates and then group them by a specific interval, I mean the user may select a date range 1 year but group the result by 7 days, so the query must return counts of dates for every 7 days.
    lets have the following table : (the real database store the date as long (date in milliseconds))
    Date | SevEnum
    1-Feb-2010 00:00:00 | 1
    1-Feb-2010 15:00:00 | 1
    2-Feb-2010 12:00:00 | 1
    2-Feb-2010 14:00:00 | 1
    3-Feb-2010 00:00:00 | 1
    3-Feb-2010 06:00:00 | 1
    The user can enter any interval he want, examples:
    grouping by *1 year*
    result must by :
    Date | Count
    2010 | 6
    grouing by *1 day*
    Date | Count
    1-Feb-2010 | 2
    2-Feb-2010 | 2
    3-Feb-2010 | 2
    grouing by *2 days*
    Date | Count
    1-Feb-2010 | 4
    3-Feb-2010 | 2
    the User can group the date by any time Unit (seconds, minutes, hours,days, week,months,years)
    I can't using TRUNC() because, its just for specific unit (ex. just 1 day, not 2 days).
    Is there any idea or logic to be general as possible, please advice.
    thanks,
    Edited by: user9183438 on Mar 9, 2010 3:20 AM
    Edited by: user9183438 on Mar 9, 2010 3:21 AM

    You can use TRUNC to truncate by day, month, hour, etc:
    SQL> SELECT TRUNC(sysdate, 'mm')
      2  FROM   dual;
    TRUNC(SYSDATE,'M
    01/03/2010 00:00As for the other requirement - do the users really need to be able to group by "2 days"? Is it meaningful?
    If so, then here's a method of doing what you're after (I've included various truncates just to give an idea of how the data may differ):
    with dates as (select trunc(sysdate, 'mm') -10 + level dt
                   from   dual
                   connect by level <= 40)
    select dt,
           trunc(dt, 'mm') by_month,
           trunc(dt, 'iw') by_week,
           trunc(dt, 'yyyy') by_year,
           trunc(dt, 'dd') by_day,
           trunc(dt, 'yyyy') + trunc(to_char(dt, 'ddd')/2)*2 by_2_days,
           trunc(dt, 'yyyy') + trunc(to_char(dt, 'ddd')/14)*14 by_14_days,
           trunc(dt, 'iyyy') + trunc(to_char(dt, 'iw')/2)*2*7 by_fortnight
    from   dates;
    DT         BY_MONTH   BY_WEEK    BY_YEAR    BY_DAY     BY_2_DAYS  BY_14_DAYS BY_FORTNIGHT
    20/02/2010 01/02/2010 15/02/2010 01/01/2010 20/02/2010 20/02/2010 12/02/2010 15/02/2010 
    21/02/2010 01/02/2010 15/02/2010 01/01/2010 21/02/2010 22/02/2010 12/02/2010 15/02/2010 
    22/02/2010 01/02/2010 22/02/2010 01/01/2010 22/02/2010 22/02/2010 12/02/2010 01/03/2010 
    23/02/2010 01/02/2010 22/02/2010 01/01/2010 23/02/2010 24/02/2010 12/02/2010 01/03/2010 
    24/02/2010 01/02/2010 22/02/2010 01/01/2010 24/02/2010 24/02/2010 12/02/2010 01/03/2010 
    25/02/2010 01/02/2010 22/02/2010 01/01/2010 25/02/2010 26/02/2010 26/02/2010 01/03/2010 
    26/02/2010 01/02/2010 22/02/2010 01/01/2010 26/02/2010 26/02/2010 26/02/2010 01/03/2010 
    27/02/2010 01/02/2010 22/02/2010 01/01/2010 27/02/2010 28/02/2010 26/02/2010 01/03/2010 
    28/02/2010 01/02/2010 22/02/2010 01/01/2010 28/02/2010 28/02/2010 26/02/2010 01/03/2010 
    01/03/2010 01/03/2010 01/03/2010 01/01/2010 01/03/2010 02/03/2010 26/02/2010 01/03/2010 
    02/03/2010 01/03/2010 01/03/2010 01/01/2010 02/03/2010 02/03/2010 26/02/2010 01/03/2010 
    03/03/2010 01/03/2010 01/03/2010 01/01/2010 03/03/2010 04/03/2010 26/02/2010 01/03/2010 
    04/03/2010 01/03/2010 01/03/2010 01/01/2010 04/03/2010 04/03/2010 26/02/2010 01/03/2010 
    05/03/2010 01/03/2010 01/03/2010 01/01/2010 05/03/2010 06/03/2010 26/02/2010 01/03/2010 
    06/03/2010 01/03/2010 01/03/2010 01/01/2010 06/03/2010 06/03/2010 26/02/2010 01/03/2010 
    07/03/2010 01/03/2010 01/03/2010 01/01/2010 07/03/2010 08/03/2010 26/02/2010 01/03/2010 
    08/03/2010 01/03/2010 08/03/2010 01/01/2010 08/03/2010 08/03/2010 26/02/2010 15/03/2010 
    09/03/2010 01/03/2010 08/03/2010 01/01/2010 09/03/2010 10/03/2010 26/02/2010 15/03/2010 
    10/03/2010 01/03/2010 08/03/2010 01/01/2010 10/03/2010 10/03/2010 26/02/2010 15/03/2010 
    11/03/2010 01/03/2010 08/03/2010 01/01/2010 11/03/2010 12/03/2010 12/03/2010 15/03/2010 
    12/03/2010 01/03/2010 08/03/2010 01/01/2010 12/03/2010 12/03/2010 12/03/2010 15/03/2010 
    13/03/2010 01/03/2010 08/03/2010 01/01/2010 13/03/2010 14/03/2010 12/03/2010 15/03/2010 
    14/03/2010 01/03/2010 08/03/2010 01/01/2010 14/03/2010 14/03/2010 12/03/2010 15/03/2010 
    15/03/2010 01/03/2010 15/03/2010 01/01/2010 15/03/2010 16/03/2010 12/03/2010 15/03/2010 
    16/03/2010 01/03/2010 15/03/2010 01/01/2010 16/03/2010 16/03/2010 12/03/2010 15/03/2010 
    17/03/2010 01/03/2010 15/03/2010 01/01/2010 17/03/2010 18/03/2010 12/03/2010 15/03/2010 
    18/03/2010 01/03/2010 15/03/2010 01/01/2010 18/03/2010 18/03/2010 12/03/2010 15/03/2010 
    19/03/2010 01/03/2010 15/03/2010 01/01/2010 19/03/2010 20/03/2010 12/03/2010 15/03/2010 
    20/03/2010 01/03/2010 15/03/2010 01/01/2010 20/03/2010 20/03/2010 12/03/2010 15/03/2010 
    21/03/2010 01/03/2010 15/03/2010 01/01/2010 21/03/2010 22/03/2010 12/03/2010 15/03/2010 
    22/03/2010 01/03/2010 22/03/2010 01/01/2010 22/03/2010 22/03/2010 12/03/2010 29/03/2010 
    23/03/2010 01/03/2010 22/03/2010 01/01/2010 23/03/2010 24/03/2010 12/03/2010 29/03/2010 
    24/03/2010 01/03/2010 22/03/2010 01/01/2010 24/03/2010 24/03/2010 12/03/2010 29/03/2010 
    25/03/2010 01/03/2010 22/03/2010 01/01/2010 25/03/2010 26/03/2010 26/03/2010 29/03/2010 
    26/03/2010 01/03/2010 22/03/2010 01/01/2010 26/03/2010 26/03/2010 26/03/2010 29/03/2010 
    27/03/2010 01/03/2010 22/03/2010 01/01/2010 27/03/2010 28/03/2010 26/03/2010 29/03/2010 
    28/03/2010 01/03/2010 22/03/2010 01/01/2010 28/03/2010 28/03/2010 26/03/2010 29/03/2010 
    29/03/2010 01/03/2010 29/03/2010 01/01/2010 29/03/2010 30/03/2010 26/03/2010 29/03/2010 
    30/03/2010 01/03/2010 29/03/2010 01/01/2010 30/03/2010 30/03/2010 26/03/2010 29/03/2010 
    31/03/2010 01/03/2010 29/03/2010 01/01/2010 31/03/2010 01/04/2010 26/03/2010 29/03/2010  You may find that you'll have to add or subtract onto the to_char(dt, 'ddd') values in order to make them us the same "start point" - eg. look at the difference for fortnight vs 14 days. Anyway, that should give you an idea of how you could do things.

  • SQL Query - Max Date - Group By

    Please see SQL below - this code is counting customers and grouping by their tenure since activation
    However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
    How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of records
    SELECT TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
    TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
    SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
    SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
    SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
    SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
    SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
    SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
    SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
    SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
    SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
    SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
    SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
    SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
    SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
    FROM FACT_RESULT_VW a,
    PLAN_VW b,
    SUB_VW c ,
    CUST_VW d,
    FACT_TRANS e,
    WHERE e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )+
    AND a.PP_KEY = b.PP_key
    AND a.ID = c.ID
    AND c.CUST_ID = d.CUST_ID
    AND c.ID = E.ID
    AND c.DATE_JOIN >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND c.DATE_JOIN < To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND a.DATE_KEY = 20100601
    AND A.PEF_ID = 1
    GROUP BY TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
         TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')

    Hi,
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements) and the results you want from that data.
    Simplify the problem as much as possible.
    Would you have the same problem if only two tables, fact_result_vw and fact_trans, were involved? Then post a question involving only those two tables. Once you have a solution for the simplified problem, adding the other tables will be easy.
    Would the problem be essentially the same if you were pivoting only 2 or 3 columns, instead of 13? Then post a question where you're only pivoting 2 or 3 columns. Once you have a solution, adding the others will be easy.
    787771 wrote:
    Please see SQL below - this code is counting customers and grouping by their tenure since activation
    However the table FACT_TRANS I am linking to contains multiple transactions for different dates and I only want to select the latest date.
    How can I return only the latest transaction from the FACT_TRANS table as the code below (In Bold)is not returning the correct number of recordsDo you want only the latest transaction from the fact_trans table, or the latest transaction for each customer ?
    What if there's a tie, and the same customer has two (or more) transactions at the same date, and none later?
    Since you're not using any of the data from the fact_trans table, the effect is just to eliminate customers who are not in fact_trans. You can do that more simply with an IN or EXISTS sub-query.
    If you really do need something from the fact_trans table in the main table, then one way you can get the results you want is to use the analytic RANK (or ROW_NUMBER) function to number the rows in fact_trans by trans_date (latest first), with a separate set of numbers (1, 2, 3, ...) for each customer, like this:
    WITH     fact_trans_1     AS
         SELECT     id     -- all columns that you need
         ,     RANK () OVER ( PARTITION BY  id
                          ORDER BY          date_trans     DESC
                        )     AS r_num
         FROM     fact_trans
    SELECT        TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
           TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999') AS TENURE,
           SUM(DECODE(A.RESULT_MNTHM12_VALUE,0,0,1)) AS M12,
           SUM(DECODE(A.RESULT_MNTHM11_VALUE,0,0,1)) AS M11,
           SUM(DECODE(A.RESULT_MNTHM10_VALUE,0,0,1)) AS M10,
           SUM(DECODE(A.RESULT_MNTHM9_VALUE,0,0,1)) AS M9,
           SUM(DECODE(A.RESULT_MNTHM8_VALUE,0,0,1)) AS M8,
           SUM(DECODE(A.RESULT_MNTHM7_VALUE,0,0,1)) AS M7,
           SUM(DECODE(A.RESULT_MNTHM6_VALUE,0,0,1)) AS M6,
           SUM(DECODE(A.RESULT_MNTHM5_VALUE,0,0,1)) AS M5,
           SUM(DECODE(A.RESULT_MNTHM4_VALUE,0,0,1)) AS M4,
           SUM(DECODE(A.RESULT_MNTHM3_VALUE,0,0,1)) AS M3,
           SUM(DECODE(A.RESULT_MNTHM2_VALUE,0,0,1)) AS M2,
           SUM(DECODE(A.RESULT_MNTHM1_VALUE,0,0,1)) AS M1,
           SUM(DECODE(A.CURRENT_RESULT_VALUE,0,0,1)) AS M0
    FROM        FACT_RESULT_VW      a,
           PLAN_VW           b,
           SUB_VW           c,
           CUST_VW           d,
           FACT_TRANS_1          e,
    WHERE        e.DATE_TRANS IN (SELECT MAX (FACT_TRANS.DATE_TRANS) FROM FACT_TRANS )
    AND       e.r_num     = 1
    AND        a.PP_KEY      = b.PP_key
    AND        a.ID           = c.ID
    AND       c.CUST_ID      = d.CUST_ID
    AND       c.ID           = E.ID
    AND       c.DATE_JOIN       >= To_DATE('01-09-2002 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND       c.DATE_JOIN      <  To_DATE('01-07-2010 00:00:00', 'dd-mm-yyyy hh24:mi:ss' )
    AND       a.DATE_KEY = 20100601
    AND       A.PEF_ID = 1
    GROUP BY  TO_NUMBER(MONTHS_BETWEEN(To_DATE(a.DATE_KEY, 'yyyymmdd' ),
           TO_DATE(ADD_MONTHS((LAST_DAY(c.DATE_JOIN)+1),-1),'dd-mm-yyyy')) -24000, '999')I hope this answers your question.
    If not, post some sample data (CREATE TABLE and INSERT statements) and the results you want from that data.

Maybe you are looking for