CrossTab Questions

I have a crosstab that looks something like this:
     Jan-08     Feb-08     Mar-08     Apr-08     May-08     Jun-08
Jan-08     A     B     C     D     E     F
Feb-08          G     H     I     J     K
Mar-08               L     M     N     O
Apr-08                    P     Q     R
May-08                         S     T
Jun-08                              U
There are two things I need to be able to do with this crosstab.  First, I need to be able to paint the diagonals in different colors.  For example, AGLPSU needs to be red, BHMQT needs to be blue, CINR needs to be green, DJO needs to be orange, EK needs to be brown and F needs to be yellow.  There is no specific rule for these colors, just that each object within a diagonal needs to be the same color and each diagonal line needs to be a different color.  In otherwords, the highlighting of each object is based on location and not value.
The second thing I need is to present a version of this crosstab as a % where AGLPSU are all 100%, B is the % if G, C and H are % of L, DIM are each the % of P, etc.
I can't figure out how to do either of these, or if it is possible to do either of these.  If not, the client will be forced to export to Excel which frustrates the purpose of the report.
Fuskie
Who hopes someone has a positive answer...

Brilliant.  I never would have thought of this.  I had to put the column total formula into the Horizontal Alignment format property condition since the client wanted column totals suppressed and I extended the color selection to 13 (they run the report for 13 months), but it looks great.  Now if only you could center a cross-tab horizontally on a page.
Here is a better discription of the second question. Take the following crosstab data:
     Jan-08     Feb-08     Mar-08     Apr-08     May-08     Jun-08
Jan-08     481     169     139     111     104     95
Feb-08          506     207     155     131     121
Mar-08               489     174     132     122
Apr-08                    388     175     138
May-08                         475     157
Jun-08                              426
I want the second crosstab to look like this:
     Jan-08     Feb-08     Mar-08     Apr-08     May-08     Jun-08
Jan-08     100%     33%     28%     29%     22%     22%
Feb-08          100%     42%     40%     28%     28%
Mar-08               100%     45%     28%     29%
Apr-08                    100%     37%     32%
May-08                         100%     37%
Jun-08                              100%
For February 08, 33% is 169/506.  For March 08, 28% is 139/489 and 42% is 207/489, etc.  Hope this is more clear.
Fuskie
Who is learning to think outside the crosstab...

Similar Messages

  • General CROSSTAB question

    Is it possible to create a crosstab report similar to:
    FIELD A-designation(value 1,2 or 3)
    FIELD B-year
    C| data
    D| data
    whereby designation 1 will always have under it both columns with data for the requested year and columns with data for the requested year - 1, while designation with value 2 or 3 will have columns of data only for the requested year?
    From my knowledge I can't see how it is possible to describe it in the layout; I am double-checking if there is a way around it.
    Thank you .
    Leah

    Please disregard this question. I think that it will all work out.
    Thanks to anyone who thought about my question.

  • Crosstab Question

    Is it possible to do crosstab query in oracle ? Basically, I've got information in this format:
    ShopName userid     Method Sum(Amount_Paid)Count(Amount_paid)
    Shop1      1     Master_Card     400     1
    Shop1      1     Cash     500     2
    Shop1      2     Cash     1300     2
    Shop2     3     Cash     130     1
    Shop2     3     Master Card     900     1
    Shop2     4     Cash     50     1
    & I want to get the information in this format:
    ShopName userid     Sum(Master_Card)Count(Master_Card)
    Sum(Cash)Count(Cash)......
    Shop1      1     400     1 500     2
    Shop1      2     0     0 1300 2
    Shop2     3     900     1 130     1
    Shop2     4     0     0 50     1
    Note that the payment method (cash, master card .....)
    isn't fixed they came from another table

    I beleive that crosstab and pivot table are the same
    where I have family names I am thinking would be your shop1
    job would be master card, cash
    dept would be shop
    Hope this will help you get started
    SQL> break on report
    SQL> compute sum LABEL 'TOTAL' of 'dept_10' on report
    SQL> compute sum of 'dept_20' on report
    SQL> compute sum of 'dept_30' on report
    SQL> compute sum of total on report
    SQL>
    SQL> select job,
    2 max( decode(deptno, 10, SPENT, 0 ) ) dept_10,
    3 max( decode(deptno, 20, SPENT, 0 ) ) dept_20,
    4 max (decode (deptno, 30, SPENT, 0)) dept_30,
    5 max( decode(deptno, 10, SPENT, 0 ) ) +
    6 max( decode(deptno, 20, SPENT, 0 ) ) +
    7 max (decode (deptno, 30, SPENT, 0)) TOTAL
    8 from (select job, deptno, sum(nvl(sal,0)) spent from emp group by job, deptno)
    9 GROUP BY job;
    JOB DEPT_10 DEPT_20 DEPT_30 TOTAL
    ANALYST 0 6000 0 6000
    CLERK 1300 1900 950 4150
    MANAGER 2450 2975 2850 8275
    PRESIDENT 5000 0 0 5000
    SALESMAN 0 0 5600 5600
    TOTAL 8750 10875 9400 29025

  • Pivot (Crosstab) question

    Is there a way to use a function for column or row definition in a pivot (crosstab) table in a RTF template ?
    For example, if our data set has a date field, and we want ta pivot table that has columns based on the year of that field, how would we create that pivot table? Accoirding to the BIP documentation, there is a function <?xdoxslt:get_year('2000-04-08', $_XDOLOCALE)?> that returns the year of a date field. Using this in the column definition, gives me a error. ie
    changing
    <?crosstab:c9827;"//G_1";"PRG_TITLE{PRG_CODE,o=a,t=t}";"PL_DATE{,o=a,t=t}";"AMOUNT";"sum"?>
    to
    <?crosstab:c9827;"//G_1";"PRG_TITLE{PRG_CODE,o=a,t=t}";"xdoxslt:get_year(PL_DATE,$_XDOLOCALE){,o=a,t=t}";"AMOUNT";"sum"?>
    Using the XQuery conversion function year-from-date gives me again an error.
    Of course, we could go ahead, and insert the year filed in our data and use it, but what we aiming is a general solution - is one exists .
    Thank you

    Thanks, again, but no it doesn't. Double-clicking (at least on my computer) merely collapses (or expands) the particular item in the pivot.
    Oh, well. This would be a useful (and logical) feature. That is, while in the pivot table, when clicking (double-clicking, whatever), be taken to the original point in the worksheet (for editing purposes). It servers no logical purpose whatsoever to open
    a new Worksheet.
    It works perfectly OK at this end.
    I disagree that it serves no useful purpose: its purpose is to provide a breakdown of the aggregated figure in the pivot and this is something that users often require (the ability to, "drill down" and see how a number is made up).
    Go to my website:-
    http://www.pierrefondes.com/
     - and open item 201.
    It should open to the Worksheet called:-
    pivot_chart
    Double click in cell:-
    B4
     - which has a total of:-
    58
     - in it.
    A new Worksheet called:-
    Sheet1
     - should now open showing you how that:-
    58
     - is made up.
    Does that help?

  • Question Regarding Crosstab or Matrix Reporting

    Hi,
    I have a Requirement Where I have to Create a Cross-tab Report,
    We use XMLPublisher which is Bundled with R12...
    our ERP version is :12.1.3
    Our XML Publisher is :5.6.3.x.x
    The Requirement Output is
    I have Generate a report which should be a Pivot Report for Every item Entered by the User (it may be one or Multiple Item)
    if one Item is Entered
    I have To list the report as below
    ITEM ID:1234 ITEM DESC: SquarePaper Plate =>Item Detail to be printed on top of the table.. Followed by
    DATE is the Column field for the Crosstab
    ORDER STATUS  is the Row Field( Order Status will be of Five Types( BOOKED,ENTERED,AWAITING_SHIPPING,AWAITING_SHIPPING,SHIPPED,CLOSED) for the Crosstab
    QTY is the Field Data Field  for the Row Field(Order Status)..for the Crosstab
    If More than One Entered
    Then I have to Repeat the Same Logic to Produce Pivot Table for that many Items entered by the User..
    For Cross Tab I have Found this Link by Vetsrini
    http://winrichman.blogspot.com/2008/08/pivot-table-cross-table-with-fixed.html
    I followed his Template and I am Getting the Crosstab Output but I am getting for all the Items as One report,
    I could not get a Logic to Group or ( Repeating Group) by Item and Item Description..
    Please help as I am Stuck at this Logic for almost 3 weeks and I have posted so 4-5 questions on this regards unfortunately No replies..
    Thanks

    Hi, Nagornyi,
    Thanks for the Reply,
    <?if:count(ITEM)=1?>
    CROSSTAB_1
    <?end if?>
    <?if:count(ITEM)>1?>
    CROSSTAB_2
    <?end if?>
    When I use this Method, I am getting this Error..
    ConfFile: C:\Program Files\Oracle\BI Publisher\BI Publisher Desktop\Template Builder for Word\config\xdoconfig.xml
    Font Dir: C:\Program Files\Oracle\BI Publisher\BI Publisher Desktop\Template Builder for Word\fonts
    Run XDO Start
    Template: C:\Documents and Settings\aranganathan\Desktop\Currently Working\RTF\tpc_item_count_sum_ver6_test.rtf
    RTFProcessor setLocale: en-us
    FOProcessor setData: C:\Documents and Settings\aranganathan\Desktop\cross_tab_test\tpc_item_count_sample2.xml
    FOProcessor setLocale: en-us
    Output type: MHTML
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
         at java.lang.reflect.Method.invoke(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLT10gR1.invokeNewXSLStylesheet(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLT10gR1.transform(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLT10gR1.transform(Unknown Source)
         at oracle.apps.xdo.common.xml.XSLTWrapper.transform(Unknown Source)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(Unknown Source)
         at oracle.apps.xdo.template.fo.util.FOUtility.generateFO(Unknown Source)
         at oracle.apps.xdo.template.FOProcessor.createFO(Unknown Source)
         at oracle.apps.xdo.template.FOProcessor.generate(Unknown Source)
         at RTF2PDF.runRTFto(RTF2PDF.java:629)
         at RTF2PDF.runXDO(RTF2PDF.java:470)
         at RTF2PDF.main(RTF2PDF.java:289)
    Caused by: oracle.xdo.parser.v2.XPathException: Error in expression: './/=1'.
         at oracle.xdo.parser.v2.XSLProcessor.reportException(XSLProcessor.java:806)
         at oracle.xdo.parser.v2.XSLProcessor.newXSLStylesheet(XSLProcessor.java:614)
         ... 15 more
    Also
    My Question was
    For Every ITEM_ID entered by the User, I have to Create Crosstab result grouped by ITEM_ID's
    Say
    if the User Enters one ITEM_ID then
    I should Create the Report as
    ITEM ID : 1234 ITEM_DESC: SQUARE PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    Say if the ITEM is more than ONE
    ITEM ID : 1234 ITEM_DESC: SQUARE PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    ITEM ID : 2341 ITEM_DESC: ROUND PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    ITEM ID : 3421 ITEM_DESC: RECTANGULAR PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    ITEM ID : 4123 ITEM_DESC: TRANGULAR PAPER PLATE -- Heading
    CROSSTAB - Report result under the ITEM_ID, and ITEM_DESC
    Thanks
    once again

  • Quick Question about Transposing/Crosstab SQL or PL/SQL query

    Hi All,
    Looking for how to transpose rows into column in SQL and/or PLSQL
    I've got thousands of rows in the format
    phone_no Code
    4161231234 A
    4161231234 B
    4161231234 C
    6471231234 A
    6471231234 B
    6471231234 C
    need to transpose this to
    phone_no Code_1 Code_2 Code_3
    4161231234 A B C
    6471231234 A B C
    Think max number of codes for phone_no is something like 10.
    Would appreciate if anybody gave guidance or direction.
    Cheers,

    Again Posted on another theard
    Sorry wanted to add 1 amendment as well in terms of Question 2)
    First Question 1)
    phone_no Code
    4161231234 A
    4161231234 B
    6471231234 A
    6471231234 C
    6471231234 D
    need to transpose this to
    phone_no A B C D
    4161231234 Y Y N N
    6471231234 Y N Y Y
    New Records such as
    6471231234 E would be appending later therefore the max number of codes for phone_no is dynamic
    Question 2)
    I also need the ability of the above table to add values of a third colum into the cross tab
    phone_no Code No_of_codes
    4161231234 A 2
    4161231234 B 1
    6471231234 A 3
    6471231234 C 1
    6471231234 D 5
    Transposes to
    phone_no A B C D
    4161231234 2 1 0 0
    6471231234 3 0 1 5
    and again
    New Records such as
    6471231234 E 7 would be appending later therefore the max number of codes for phone_no is dynamic
    Thanks for any help!!

  • Quick Question about Transposing/Crosstab SQL or PL/SQL query Version II

    Hi All,
    2nd time I'm asking this but a little different
    Looking for how to transpose rows into column in SQL and/or PLSQL but use the transpose into column headings.
    I've got thousands of rows in the format
    phone_no Code
    4161231234 A
    4161231234 B
    6471231234 A
    6471231234 C
    6471231234 D
    need to transpose this to
    phone_no A B C D
    4161231234 Y Y N N
    6471231234 Y N Y Y
    New Records such as
    6471231234 E would be appending later therefore the max number of codes for phone_no is dynamic
    Would appreciate if anybody gave guidance or direction.
    Cheers,

    Hi,
    If the number of columns is unknown, but within a known bound, then you can do something like this:
    WITH     got_jnum    AS
         SELECT       deptno
         ,       job
         ,       sal
         ,       DENSE_RANK () OVER (ORDER BY job)     AS jnum
         FROM       scott.emp
    SELECT       deptno
    ,       TO_CHAR (SUM (CASE WHEN jnum = 1 THEN sal END), '99999999')     AS job_1
    ,       TO_CHAR (SUM (CASE WHEN jnum = 2 THEN sal END), '99999999')     AS job_2
    ,       TO_CHAR (SUM (CASE WHEN jnum = 3 THEN sal END), '99999999')     AS job_3
    ,       TO_CHAR (SUM (CASE WHEN jnum = 4 THEN sal END), '99999999')     AS job_4
    FROM       got_jnum
    GROUP BY  deptno
        UNION ALL
    SELECT       NULL                                   AS deptno
    ,       MIN (CASE WHEN jnum = 1 THEN LPAD (job, 9) END)     AS job_1
    ,       MIN (CASE WHEN jnum = 2 THEN LPAD (job, 9) END)     AS job_2
    ,       MIN (CASE WHEN jnum = 3 THEN LPAD (job, 9) END)     AS job_3
    ,       MIN (CASE WHEN jnum = 4 THEN LPAD (job, 9) END)     AS job_4
    FROM       got_jnum
    ORDER BY  deptno     NULLS FIRST
    ;Output:
    .    DEPTNO JOB_1     JOB_2     JOB_3     JOB_4
                 ANALYST     CLERK   MANAGER PRESIDENT
            10                1300      2450      5000
            20      6000      1900      2975
            30                 950      2850See [this thread|http://forums.oracle.com/forums/thread.jspa?messageID=4051662&#4051662] for context.
    As mentioned there, String Aggregation is another possibility.
    If the number of columns is completely unknown, then I see your options as:
    (1) String Aggregation
    (2) Dynamic SQL
    (3) Wrapping (See [this thread|http://forums.oracle.com/forums/thread.jspa?messageID=3527823])

  • Crosstab formatting question -- not sure if possible

    I'm trying to copy an existing report from Crystal to Discoverer on student data at a college.
    Because a student can have multiple addresses(local, permanent, parents) I need to have a report that is something like:
    <with any luck the formatting will stay intact>
    (student ID) (Name) (Type) (Address) (grade Level)
    1234 Mary Smith Local 123 main st Freshman
    perm 567 wild ave
    parent 987654 willy wonka lane
    5678 John Doe Local 5411 silly drive Senior
    parent 99 redhat way
    In essence, I'm needing each student to only display things like ID, name, grade, etc, once, but each address needs to be displayed in an address column, but without duplicating the ID, name, etc
    I suspect that this can't be done in Discoverer, but thought I'd ask before I venture a different route. Makes my job easier if I can keep the formatting the same for those that use the report.
    I hope this made sense, I can get a jpg posted if it would help to understand.
    matt

    Let me try formatting again:
    (student ID) (Name) (Type) (Address) (grade Level)
    1234 Mary Smithiewe Local 123 main st Freshman
    <-----------BLANK------------>perm 567 wild ave <-- no_level-->
    <----------------BLANK-------->parent 987654 willy wonka lane <-- no_level-->
    5678 John Doenagleongler Local 5411 silly drive Senior
    <------------BLANK------------>perm 99 redhat way <-- no_level-->
    <------------BLANK------------>parent 99 redhat way <-- no_level-->
    Matt

  • How to avoid crosstab - Show number of days according to groups

    Morning all,
    I think you all would agree with me that even having crosstab as a great tool in Crystal 2008, there are still quite allot of limitations to it.
    I have created a report using crosstab which shows number of days and jobs according to those days grouped by account number, product code, sales area. This report is working fine until my director asked me to further group those days according to sub categories of lenses.
    For example
    Crosstab shows
    Number of days - Day 1,day 2, day 3
    Number of jobs - 111----123--1213
    Percentage - -
    12%---34% 60%
    Now if you look at the example it says day 1, 111 jobs went out. What the director would like to see is those jobs being sub divided into types of lenses.
    So out of 111 jobs, 25 would be Finished lenses, 30 could be uncut lenses and so on.
    The new report should be like this
    Number of days -
    Day1---Day2---Day3
    Number of Jobs:-
    Finished -
    25--34-----23
    Uncut--3045-----23
    AR--7056-----76
    Total----125135----122
    Percentage:-
    Finished -
    25%--34%-----23%
    Uncut--30%45%-----23%
    AR--70%56%-----76%
    Total----100%100%----100%
    Now if we look at the above criteria it seems that I have to use groups even further down the report where I am using crosstab at the moment. This means I have to get rid of the crosstab and run a report manually.
    However the big question is, how to get the report calculating number of days and jobs according to customer account number, product code and sales area manually?
    I tried the following formula but this requires to write way too many formulas, for example some of the jobs have taken more than 60 days and if i use this formula I have to write 60 formulas for number of days which is not feasable.
    **//provided by IIbas in another forum**
    whileprintingrecords;
    numbervar day0;
    numbervar day1;
    numbervar day2;
    if {@workingdays} = 0 then
    day0 := day0 + 1 else
    if {@workingdays} = 1 then
    day1 := day1 + 1 else
    if {@workingdays} = 2 then
    day2 := day2 + 1 else //up to the maximum number of days.
    Then in the report footer, reference the days in separate formulas, and identify them with text boxes, e.g.,
    //{@day0};
    whileprintingrecords;
    numbervar day0;
    I can sort out the Finished, uncut,AR by grouping them however I am wondering how to create a manual running total of jobs complying with number of days without using crosstab.
    Any ideas?
    Many thanks
    Regards
    Jehanzeb

    no answer closing

  • How to delete the Data Points label with a crosstab layout

    Hi, just a question.
    I created a report which uses a crosstab layout; so...I have the Company Name on the left, Status Code above and the Count(tickets) as Data Points.
    As soon as I put the Count(tickets) inside the report, the label "Data Points: Incident Id Count appears above just at the bottom of the Status Code
    Is there a way to avoid this tedious label ?
    As workaround, I changed the Data Points' format heading (text and background) in such a way to see only a Grey space...but this is not so useful (from the customer side...)
    I also looked for inside the crosstab layout properties...but I didn't found nothing.....
    Any help will be appreciate
    Alex

    Well, I think you are out of luck. You are basically saying you want to control when you have a column heading and when you don't want to have a column heading. Most of us users do want column headings in our reports. In fact I have a hard time trying to figure out why you don't want a column heading. How are the report users going to know what the numbers in the column mean if you don't have a heading on the column? Maybe the initial users of the report know, but what happens when they leave and someone else takes over their duties? I would suggest putting in an enhancement request for Discoverer to give you the option to not display a column heading, if you really want something like this. This needs to be at the workbook level, I am thinking.
    John Dickey

  • Need help in creating custom crosstab reports

    Hello
    I need some help in creating custom crosstab reports.
    My current report shows the number of events that have occured over the time in a day
    The events and the eventdetails are read from the database before being printed on the crosstab
    i.e something like this.
    Note : there are no events between 3:00-3:59,5:00-5:59;6:00-6:59,7:00-7:59  (not present in the database)
    hence not displayed in the reports
    *08/07/2009*         01:00        02:00         04:00          08:00          10:00*
    Event X                    1               1                 4                 1                  3
    Event Y                   3               3                 2                 2                  1
    Total                        4                4                 6                 3                  4
    So far so good...
    Now i have to enhance my reporting application to include the event details which have not happened i.e to include the time details in the crosstab reports where no events have happened
    08/07/2009             01:00        02:00         03:00          04:00          05:00         6:00         07:00         8:00     9:00     10:00
    Event X                     1               1                0                 4                  0             4             0                1            0           3
    Event Y                     3               3                0                 2                  0             2             0                2            0           1
    Total                         4                4                0                 6                  0             6             0                3            0           4
    I have fell short of ideas this time around to implement such a thing
    Any help in this direction is deeply appreciated
    Regards
    Srivatsa
    Edited by: Srivatsa HG on Jul 8, 2009 10:56 AM

    Hi,
    It seems that you are having issue with Crystal Report Design.
    Post your question in [Crystal Report Design Forum|SAP Crystal Reports;
    That forum is monitored by qualified technicians and you will get a faster response there. Also, all Design queries remain in one place and thus can be easily searched in one place.
    Regards,
    Shweta

  • Really working Crosstab / Pivot Report example

    try it here:
    http://apex.oracle.com/pls/otn/f?p=20819:2
    Details:
    Create Report - based on PL/SQL ************************************
    DECLARE
    l_return_value VARCHAR2(32000) DEFAULT NULL;
    BEGIN
    l_return_value := PK_PIVOT.PivotSQL('SELECT * FROM TESTDATA', 'country,city,product','FDate', 'SUM', 'amount', nvl(:P2_PAGENUMBER,1) );
    --:P2_PAGENUMBER - Textbox above the report
    RETURN l_return_value;
    END;
    Create Supporting PACKAGE PK_PIVOT ************************************
    create or replace
    PACKAGE PK_PIVOT
    --AUTHID CURRENT_USER
    as
    --code based on famous Tom Kyte's books examples
    --but not copy-pasted from there
    type refcursor is ref cursor;
    type array is table of varchar2(30);
    type array_varchar2 is table of varchar2(255);
    Function PivotSQL (
    p_query in varchar2, --query string which returns data you want to make crosstab on
    p_rowfields in varchar2, --row fields separated by comma
    p_columnfield in varchar2, --one column field
    p_function in varchar2,--aggregate function ('SUM','AVG','COUNT','MIN','MAX')
    p_functionfield in varchar2 --field for aggregate function
    , p_page in number default 1--page from right to left (not all columns can be shown on one page)
    ) return varchar2; --returns query text for crosstab
    example:
    SELECT PK_CROSSTAB.PivotSQL('SELECT * FROM scott.emp','empno','job','sum','sal') FROM SYS.DUAL
    SELECT deptno
    ,sum(DECODE(job,'BOSS',sal,null)) as BOSS
    ,sum(DECODE(job,'FIN',sal,null)) as FIN
    ,sum(DECODE(job,'HR',sal,null)) as HR
    ,sum(DECODE(job,'Sales',sal,null)) as Sales
    FROM (SELECT * FROM scott.emp)
    GROUP BY deptno
    ORDER BY deptno
    end;
    create or replace PACKAGE BODY PK_PIVOT as
    Procedure FormatParam (var_data in varchar2, var_type in number, out_decode in out varchar2, out_col in out varchar2);
    Function PivotSQL (
    p_query in varchar2,--
    p_rowfields in varchar2,
    p_columnfield in varchar2,
    p_function in varchar2,
    p_functionfield in varchar2,
    p_page in number default 1
    ) return varchar2
    as
    l_max_cols number;
    l_query long;
    l_columnnames array_varchar2 :=array_varchar2();
    l_cursor refcursor;
    tmp long;
    --dbms_sql types:
    l_theCursor integer default dbms_sql.open_cursor;--get col types
    l_colCnt number default 0;
    l_descTbl dbms_sql.desc_tab;
    col_num number;
    l_columnfieldtype number;
    --decode names   
    o_decode varchar2(50);
    o_col varchar2(50);
    l_cols_per_page number := 50;
    l_begcol number;
    l_endcol number;
    begin
    --check params
    IF instr(p_columnfield,',')>0 THEN
    raise_application_error (-20001, 'Can use only 1 columnfield');
    ELSIF upper(p_function) not in ('SUM','AVG','COUNT','MIN','MAX') THEN
    raise_application_error (-20001, 'Can use only standard aggregate functions');
    END IF;
    /* analyse query */
    dbms_sql.parse(l_theCursor, p_query, dbms_sql.native);
    /* get described columns for analysed query */
    dbms_sql.describe_columns(l_theCursor, l_colCnt, l_descTbl);
    /* Tom Kyte:
    * Following loop could simply be for j in 1..col_cnt loop.
    * Here we are simply illustrating some of the PL/SQL table
    * features.
    col_num := l_descTbl.first;
    loop
    exit when (col_num is null);
    --find column field type
    if l_descTbl(col_num).col_name=upper(p_columnfield) then
    l_columnfieldtype:=l_descTbl(col_num).col_type;
    --dbms_output.put_line('Col#:'||col_num||' Name:'||l_descTbl(col_num).col_name||' Type:'||l_descTbl(col_num).col_type);
    end if;
    col_num := l_descTbl.next(col_num);
    end loop;
    --return 'test ok';
    -- figure out the column names we must support for horizontal cross
    if (p_columnfield is not null) then
    tmp:='SELECT DISTINCT ' || p_columnfield || ' FROM (' || p_query || ') ORDER BY ' || p_columnfield;
    -- dbms_output.put_line('columns cursor:'||tmp);
    OPEN l_cursor for tmp;
    LOOP
    l_columnnames.EXTEND;
    FETCH l_cursor into l_columnnames(l_columnnames.COUNT);
    --dbms_output.put_line('l_columnnames:'||l_columnnames(l_columnnames.COUNT));
    EXIT WHEN l_cursor%NOTFOUND;
    END LOOP;
    CLOSE l_cursor;
    -- execute immediate 'SELECT DISTINCT ' || p_columnfield || ' FROM (' || p_query || ')' bulk collect into l_columnnames ;
    else
    raise_application_error (-20001, 'Cannot figure out max cols');
    end if;
    -- Now, construct the query that can answer the question for us...
    l_query := 'SELECT ' || p_rowfields ;
    l_begcol:=l_cols_per_page*(p_page-1)+1;
    l_endcol:=l_cols_per_page*p_page;
    if l_begcol>l_columnnames.count-1 then
    l_begcol := l_columnnames.count-1;
    end if;
    if l_endcol>l_columnnames.count-1 then
    l_endcol := l_columnnames.count-1;
    end if;
    --for i in  1 .. l_columnnames.count-1 loop
    for i in l_begcol..l_endcol loop
    FormatParam(l_columnnames(i),l_columnfieldtype, o_decode, o_col);--format params
    l_query := l_query || ',' || p_function || '(DECODE(' || p_columnfield || ',' || o_decode || ','|| p_functionfield ||',null)) as "'|| o_col ||'" ' ; --" для строк с пробелами
    end loop;
    l_query := l_query || ' FROM (' || p_query || ')';
    l_query := l_query || ' GROUP BY ' || p_rowfields || ' ORDER BY ' || p_rowfields;
    /* close cursor */
    dbms_sql.close_cursor(l_theCursor);
    return l_query;
    EXCEPTION
    WHEN OTHERS THEN
    /* close cursor */
    dbms_sql.close_cursor(l_theCursor);
    raise_application_error (-20001,'Error in PivotSQL:' || SQLERRM);
    end;
    --=========================
    Procedure FormatParam (var_data in varchar2, var_type in number, out_decode in out varchar2, out_col in out varchar2)
    --format parameter based on its type - for PivotSQL
    --get parameter and its type
    -- return strings for decode function and column name
    /* dbms_sql.describe_columns types:
    DATE Type:12
    Varchar2 Type:1
    Number Type:2
    IS
    BEGIN
    IF var_data is null THEN
    out_decode:='NULL';
    out_col:='==NULL==';
    ELSIF var_type = 1 THEN -- Varchar2
    out_decode:=''''||var_data||'''';--add quotes
    out_col:=substr(var_data,1,30);
    ELSIF var_type = 2 THEN --Number
    out_decode:=var_data;--do nothing
    out_col:=substr(var_data,1,30);
    ELSIF var_type = 12 THEN --DATE
    out_decode:='to_date('''||var_data||''')';--format as internal date
    out_col:=to_char(to_date(var_data),'YYYY-MM-DD');
    ELSE
    out_decode:='== UNDEFINED TYPE:'||var_type;
    out_col:='== UNDEFINED TYPE';
    END IF;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error (-20001,'Error in FormatParam:' || SQLERRM);
    END;
    end;

    Hi,
    Thank you for providing such an excellent piece of code. I have used it and it works like a charm. However I faced a problem today and needed your help.
    I am executing this code using the following code :
    SELECT PK_PIVOT.PivotSQL('SELECT sfid.bill_date ,cust.customer_name FROM split_file_detail sfd,customer cust,split_file_invoice_details sfid where sfd.CUSTOMER_SYS_ID=cust.CUSTOMER_SYS_ID and sfid.SPLIT_FILE_DETAIL_SYS_ID = sfd.SPLIT_FILE_DETAIL_SYS_ID'
    ,'cust.customer_name','bill_date','count','cust.customer_name') FROM SYS.DUAL
    Now when I do so I get the following error :
    ORA -20001 : Error in PivotSQL: ORA-06502 and ORA-06512.
    Now I guess the error maybe because:
    1. The p_query parameter is huge and the tmp long type is not able to hold the value.
    2. bill_date holds 200+ values and the ref_cursor is not able to handle it.
    I have tried breaking p_query down to some more bits but I face the problem when I concatenate them back together.
    Can you help me please?

  • How do I 'remove' a dimension from a cube when creating a crosstab?

    I have a CUBE with 9 dimensions and one measure, This is based of a fact table that has a Materialized View with just 4 dimensions.
    In JDeveloper I used the wizard to create a new crosstab using just the four dimensions that exist in the MV (removing the others).
    ....eventually the page was generated but it takes minutes....
    Q. Is there a way to 'DROP' a dimension from JDeveloper crosstab when you query a CUBE?
    [It looks like Oracle is internally using all 9 dimensions when some are "Hidden"  or not required!]
    The only solution I have found is to create an extra CUBE using just the 4 dimensions (this works within couple of seconds)! But I will end up with 6 CUBES holding different dimensions combination, this feels wrong?
    Q2. Is it bad practice to have multiple CUBES all based on one fact table, just to improve performace?
    I hope you can help.
    Steve

    i think this question is more for the technical teams at the olap forum ;)
    nevertheless: if you have a cube defined with 9 dimensions,all of them are necessary for retrieving the data, "hiding" some of them is possible by the means of "hidden dimensions"
    nevertheless you have to specify which dimension, value gets substitued for those dimensions: usually it is a TOTAL level.
    otherwise your results may be misleading or wrong, so specifying a dimension value for those hidden dimensions is the only choice to be consistent with the OLAP data model
    btw: you can easily use a materialized view in this environment as well, when using the concept of a TOTAL dimension value
    regards,
    thomas

  • Flexible crosstab report layout - Word template builder

    I'm new to BI Publisher and learning new things every day. I'm now working on a complex template layout and I'm not even sure if it can be handled at this point. Looking for any advice someone can provide?
    The layout is very similar to a crosstab report, but with some flexibility in terms of layout. Here's a brief description:
    A1 G1
    A2 G2
    A3 B3 C3 D3 E3 F3 G3 G4
    Cells A1 and A2 are static (text labels read from the XML)
    Cells A3 - F3 are columns of the crosstab report. Column A and B always will appear, columns C - F may or may not appear (2 or 3 will appear - just don't know which ones)
    Cells G1 - G2 - Data column headers - This is a repeating column for different data points. There may be 1 up to 20 columns. Only want to display 5 of these per table, since more will go off the page. The next columns should go to a new table
    Cells G3 and G4 - These are the data points for the "crosstab". One is a min value / one is a max value for the specific row / column combination.
    Right now, I've got the columns A3 - F3 generating correctly, but cells A1 and A2 do not shrink and take up the same space as all 6 columns would if columns A3 to F2 were to be displayed. I've got a for-each in A3 that ends in F3. I've also got a for-each in G1 - G2 to extend the repeating columns for the data points.
    Is it possible to have cells A1 and A2 size differently based on how many columns are to be displayed between A3 and F3?
    Is there a better layout than the one above to tackle the creation of this data table?
    Thanks in advance for any ideas!

    Hi Vivek,
    I have LabVIEW 8.5 Development version and the report generation tool kit.  I will be writing VI to fill the data in and generate a word report with Up to 873 different tests.  The template that I attached is the sample template for only one test, I will be doing 873 tests.  The sample test template consists of scope shot and some measured parameters.
    My situation - the VI that I will be writing will fill in the sample template that I attached for 873 times.  For me to generate a word report for all tests, I would have to create a report template with 873 sample templates.  Where there is a red box, I would have to create a field for each box so the LabVIEW will know where to put the data in. 
    Well, that is lot of work in the first place.  Secondly, to keep up with 873 different permuation fields can create lot of unnecessary programming mess.  Lastly, if the user decide to run only part of the test, then there would be lot of empty test templates.  If user decide to run only 10 tests the final report will have 860 empty boxes.  That is not efficient.
    My goal is to create the word report using just one sample template rather than 873.  I would like to copy the sample template based on number of tests user defines. 
    My question is-  Is there any way to copy the sample test template that I attached using the report generation toolkit?
    Regards,
    Chetna Tailor

  • Question about Portal and BI Beans

    Hi,
    I am trying to create a Portlet that displays Thin BI Beans crosstab. Using the "URL-Based Portlet (inline rendering)", I could display the Thin BI Beans crosstab inside the Portal. But, when I try to drill down or change the page edge, it ends up with "No Page Found" error. My question is...
    1) Is it possible to embed a Thin BI Beans crosstab inside the Portal and manipulate it dynamically?
    2) If it is possible, how can I do that?
    I will attach my provider.xml and JSP file that creates the crosstab. Please let me know if you need more information. Thank you very much.
    Seiji Minabe
    Technical Director
    IAF Software, Inc.
    provider.xml
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <?providerDefinition version="3.1"?>
    <provider class="oracle.portal.provider.v2.http.URLProviderDefinition">
    <providerInstanceClass>oracle.portal.provider.v2.http.URLProviderInstance</providerInstanceClass>
    <session>true</session>
         <portlet class="oracle.portal.provider.v2.DefaultPortletDefinition">
              <id>1</id>
              <name>Sample Portal</name>
              <title>SamplePortal</title>
              <shortTitle>SamplePortal</shortTitle>
              <description>SamplePortal.</description>
              <timeout>10000</timeout>
              <timeoutMessage>SamplePortal portlet timed out</timeoutMessage>
              <acceptContentType>text/html</acceptContentType>
              <renderer class="oracle.portal.provider.v2.render.RenderManager">
                   <contentType>text/html</contentType>
                   <charSet>UTF-8</charSet>
                   <showPage>/sampleView.jsp</showPage>
              </renderer>
         </portlet>
         <portlet class="oracle.portal.provider.v2.http.URLPortletDefinition">
              <id>2</id>
              <name>Sample URL Based Portlet</name>
              <title>Sample URL Based Portlet</title>
              <description>Display Sample as a portlet.</description>
              <timeout>100</timeout>
              <timeoutMessage>Timed out waiting for Sample Portlet.</timeoutMessage>
              <acceptContentType>text/html</acceptContentType>
              <showEdit>false</showEdit>
              <showEditToPublic>false</showEditToPublic>
              <showEditDefault>false</showEditDefault>
              <showPreview>false</showPreview>
              <showDetails>false</showDetails>
              <hasHelp>false</hasHelp>
              <hasAbout>false</hasAbout>
              <renderer class="oracle.portal.provider.v2.render.RenderManager">
              <contentType>text/html</contentType>
              <showPage class="oracle.portal.provider.v2.render.http.URLRenderer">
              <contentType>text/html</contentType>
              <charSet>ISO-8859-1</charSet>
              <pageUrl>http://iafsoft06.iafsoft.com:7779/SamplePortal/sampleView.jsp</pageUrl>
              <filter class="oracle.portal.provider.v2.render.HtmlFilter">
              <headerTrimTag>&lt;body</headerTrimTag>
              <footerTrimTag>/body></footerTrimTag>
              <inlineRendering>true</inlineRendering>
              </filter>
              </showPage>
              </renderer>
         </portlet>
    </provider>
    sampleView.jsp
    <%@ taglib uri="http://xmlns.oracle.com/bibeans" prefix="orabi" %>
    <%@ page contentType="text/html;charset=windows-1252"%>
    <%@ page import="oracle.portal.provider.v2.render.*"%>
    <%@ page import="oracle.portal.provider.v2.http.*"%>
    <%-- Start synchronization of the BI tags --%>
    <% synchronized(session){ %>
    <orabi:BIThinSession id="BIThinSession1" configuration="/Project1BIConfig1.xml" >
    <orabi:Presentation id="sampleView_Presentation1" location="sampleCrosstab" />
    </orabi:BIThinSession>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>
    Sample View
    </title>
    </head>
    <body>
    <FORM name="BIForm">
    <!-- Insert your Business Intelligence tags here -->
    <orabi:Render targetId="sampleView_Presentation1" parentForm="BIForm" />
    <%-- The InsertHiddenFields tag adds state fields to the parent form tag --%>
    <orabi:InsertHiddenFields parentForm="BIForm" biThinSessionId="BIThinSession1" />
    </FORM>
    </body>
    </html>
    <% } %>
    <%-- End synchronization of the BI tags --%>

    The versions of products I use are...
    Oracle Database 9.2.0.2
    9iAS 9.0.2
    JDeveloper903
    bibeans903a

Maybe you are looking for