To get cross tab view fo each year sales

Please can you help to write the sql to get crosstab  view of report  for each year and  for each company. It would be very appreciate.
Company 
polachan

If you want to crosstab multiple fields then classical crosstab query is better
ie like
SELECT Company,
SUM(CASE WHEN YrVal = 2010 THEN Sales END) AS Sales2010,
SUM(CASE WHEN YrVal = 2010 THEN Cost END) AS Cost2010,
SUM(CASE WHEN YrVal = 2010 THEN Profit END) AS Profit2010,
SUM(CASE WHEN YrVal = 2011 THEN Sales END) AS Sales2011,
SUM(CASE WHEN YrVal = 2011 THEN Cost END) AS Cost2011,
SUM(CASE WHEN YrVal = 2011 THEN Profit END) AS Profit2011,
SUM(CASE WHEN YrVal = 2012 THEN Sales END) AS Sales2012,
SUM(CASE WHEN YrVal = 2012 THEN Cost END) AS Cost2012,
SUM(CASE WHEN YrVal = 2012 THEN Profit END) AS Profit2012,
FROM
SELECT Company,YEAR([date]) AS YrVal,Sales,Cost,Profit
FROM table
)t
GROUP BY Company
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page

Similar Messages

  • How to create a Cross Tab view

    hi all
    I have a table with records with this format:
    Year, Month, Id, Value
    2006, 01, 1, 10
    2006, 02, 1, 15
    2006 03, 1, 5
    2006, 01, 2, 6
    2008, 05, 1, 8
    What I need to do is a view that will select these records for a specific year and show a column per month and a total column for the whole year. Rows will be by ID and every cell will show values
    how can I do that?

    Something like...
    SQL> with t as (select 2006 as yr, 1 as mnth, 1 as id, 10 as val, 5 as daysusage from dual union all
      2             select 2006, 2, 1, 15, 2 from dual union all
      3             select 2006, 3, 1, 20, 1 from dual union all
      4             select 2006, 4, 1, 2, 1 from dual union all
      5             select 2007, 1, 1, 11, 7 from dual union all
      6             select 2007, 2, 1, 10, 7 from dual union all
      7             select 2007, 3, 1, 22, 6 from dual union all
      8             select 2007, 4, 1, 20, 10 from dual)
      9  -- ### END OF TEST DATA ###
    10  select yr, id
    11        ,max(decode(mnth, 1, val)) as m1_val
    12        ,max(decode(mnth, 1, daysusage)) as m1_days
    13        ,max(decode(mnth, 2, val)) as m2_val
    14        ,max(decode(mnth, 2, daysusage)) as m2_days
    15        ,max(decode(mnth, 3, val)) as m3_val
    16        ,max(decode(mnth, 3, daysusage)) as m3_days
    17        ,max(decode(mnth, 4, val)) as m4_val
    18        ,max(decode(mnth, 4, daysusage)) as m4_days
    19        ,sum(daysusage) as total
    20  from t
    21  group by yr, id
    22  order by yr, id
    23  /
            YR         ID     M1_VAL    M1_DAYS     M2_VAL    M2_DAYS     M3_VAL    M3_DAYS     M4_VAL    M4_DAYS      TOTAL
          2006          1         10          5         15          2         20          1          2       1             9
          2007          1         11          7         10          7         22          6         20      10            30
    SQL>

  • Show statistics of year against month in cross tab

    Dear All,
    I want to create a report to show some statistics (measure), e.g. sales revenue of different year and month in cross tab format, i.e. year as the vertical axis and month as the horizontal axis. So that I can compare the revenue of specific among different years and show the tendency for analysis.
    However, what I got the statistics is being grouped by the year (vertical axis) only and being the same across month ( horizontal axis).
    should any coding be added to achieve such purpose? Please kindly advise.
    Thanks and Regards,
    Cherry

    OK, let me explain in this way.
    I have a table:
    FiscalYr-Month(yyyymm)-Sales
    -2006-200601--
    1,000,000
    -2006-200602--
    1,000,100
    -2006-200603--
    1,000,200
    -2007-200701--
    1,001,000
    -2007-200702--
    1,001,100
    -2007-200703--
    1,001,200
    and in the report, i want to compare the data in format of crosstab as follow:
    -FiscalYr\Month---01+02+03--
    +
    --2006----------1,000,000+---1,000,100+---1,000,200--
    +
    --2007----------1,001,000+---1,001,100+---1,001,200--
    +
    -Sum/Diff/Avg-.................
    So that I can compare the trend of sales of same month against different years.
    The original data saves month in format of yyyymm instead of the month number to ease some of calculations of another module. Still, there is a time dimension table which can convert yyyymm to month number. Therefore I thought it should be possible to display month in number in the report.
    However, what I get now, the sales are being grouped by the Fiscal Yr like this:
    -FiscalYr\Month---01+02+03--
    +
    --2006----------3,000,300+---3,000,300+---3,000,300--
    +
    --2007----------3,003,300+---3,003,300+---3,003,300--
    +
    -Sum/Diff/Avg-.................
    I am not sure if there is something wrong in my structure (now year and month and 2 dimensions) or I can make use of some formula/coding in the report (or universe?).
    Please kindly give me some idea.
    Thanks a lot.
    Cherry
    Edited by: Cherry Wan on Jun 2, 2009 3:23 AM

  • Need a multi-level control break report displaying a cross-tab for each ...

    I need a multi-level control break report that displays a cross-tab report for each
    detail and subtotal. The individual cross-tabs are no problem. There are two issues:
    1) How to get many cross-tabs (thousands) to appear in one report.
    2) How to provide cross-tabs in-line on the multi-level subtotal lines.
    Here is a concrete example.
    Suppose the data base contains this table:
    road (
    id_number number, -- this is an artificial PK
    city varchar2,
    county varchar2,
    state varchar2,
    length number,
    owner varchar2, -- roads may be owned by cities, counties, states, and others
    surface_type varchar2 -- the surface type may be gravel, asphalt, concrete, and others
    The table is populated with several million records that include every
    length of road in a US city.
    It is OK to suppose that all the attributes in all the records are not null.
    Without the PK, there would be millions of duplicates,
    which should all contribute to the summed lengths.
    The report I need is like a control break report with a detail line for each
    city together with subtotals for each county and state and
    a grand total for the US at the end.
    However, each detail and total line needs to be a cross-tab report
    summing the length over the city, county, state or US
    (whichever is called for at that location)
    for each combination of owner and surface_type.
    so the report would have the following structure:
    a city cross-tab for the first city in county 1/state 1
    a city cross tab for the last city in county 1/state 1
    a cross-tab for count 1
    a city cross tab for the first city in county 2/state 1
    a city cross tab for the last city in county 2/state 1
    a cross tab for state 1
    a cross-tab for the US
    Any suggestions will be appreciated.
    This problem comes up because my client's legacy system,
    which is being replaced,
    already has such a report (in COBOL).
    Thanks!!!
    Steve
    PS, I know one ugly way to do it. Namely, make a variable for each
    possible combination of owner and surface. Then code an ordinary control
    break report. However, I am looking for something better.

    Hi Jenna_Fire,
    According to your description, you have a matrix contains total for each group on each level. Now your requirement is, when you click on any number (data field or total), it will go to the detail report which returns all the detail information of the people
    within the group scope. For example, if you click on the total of Active users in United States, it will return the detail information of Active users in New York and Texas. Right?
    In this scenario, we should set the parameter (@Country, @State, @City) allow multiple values in both main and detail report. And in Default Value (@Country, @State, @City), query out all distinct values. In the textbox which contains
    those total values, when set use these parameters to run the report, we only need to pass the parameters of parent groups. For example, if we click on the total of Active users in New York, we only need to pass Country, State, Status to detail report, and
    in the detail report, the City parameter will use all distinct values (Default Values) because we don't pass the City parameter. We have tested this case with sample data in our local environment. Here are steps and screenshots for your reference:
    1. Create parameter Country, State, City and Status in both main report and detail report. Set both Available Value and Default Value get values from query (Create a dataset for each parameter, use "select distinct [column] from [table]" as query). Set allow
    multiple values for parameter Country, State and City in both reports.
    2. In corresponding textbox, pass appropriate parameters in go to report Action.
    4. Filter data in detail report (in where clause or using filters).
    5. Save and preview. It looks like below:
    Reference:
    Using Parameters to Connect to Other Reports
    If you have any question, please feel free to ask.
    Best Regards,
    Simon Hou

  • Help in Cross Tab!!!

    Hi All,
    I have a samll issue when creating a cross tab report with the format like this:
    Year (Group By Year)
    Quarter (repeats for every Year)
    Actual Budget Short
    customer name Quarter amounts
    TOTAL TOTAL AMOUNTS
    I have been able to create a cross tab report with only year...i am having difficulties putting in the quarters....
    any help is much appreciated.
    I can pass the rtf template created for the yearly data.
    Thanks,
    Madhavan G V

    Hi Vetsrini,
    No offence taken. I appreciate all the help i can get from this forum.
    Anyways, please find the the xml & code generated.
    XML:
    ====
    <ROWSET>
    <RESULTS>
    <INDUSTRY>Motor Vehicle Dealers</INDUSTRY>
    <YEAR>2005</YEAR>
    <QUARTER>Q1</QUARTER>
    <SALES>1000</SALES>
    </RESULTS>
    <RESULTS>
    <INDUSTRY>Motor Vehicle Dealers</INDUSTRY>
    <YEAR>2005</YEAR>
    <QUARTER>Q2</QUARTER>
    <SALES>2000</SALES>
    </RESULTS>
    <RESULTS>
    <INDUSTRY>Motor Vehicle Dealers</INDUSTRY>
    <YEAR>2004</YEAR>
    <QUARTER>Q1</QUARTER>
    <SALES>3000</SALES>
    </RESULTS>
    <RESULTS>
    <INDUSTRY>Motor Vehicle Dealers</INDUSTRY>
    <YEAR>2004</YEAR>
    <QUARTER>Q2</QUARTER>
    <SALES>3000</SALES>
    </RESULTS>
    </ROWSET>
    Code:
    ====
    <?variable:c297;xdoxslt:create_groups($_XDOCTX, RESULTS/node()[local-name()='YEAR' or local-name()='QUARTER'], 'YEAR;QUARTER', 'v')?><?horizontal-break-table:1?>
    <?for-each@cell:$c297?>
    <?for-each@cell:xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?end for-each?><?end for-each?>
    <?for-each@column:$c297?>
    <?.?>
    <?for-each@column:xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?.?>
    <?end for-each?><?end for-each?>
    <?for-each-group:RESULTS;./INDUSTRY?><?variable@incontext:G1;current-group()?>
    <?INDUSTRY?>
    <?for-each@cell:$c297?>
    <?sum ($G1[(./YEAR=current())]/SALES)?>
    <?for-each@cell:xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?sum ($G1[(QUARTER=current())]/SALES)?> -- Problematic part. [i get the total of quarters rather than total of quarter on a year basis)
    <?end for-each?><?end for-each?>
    <?sum ($G1/SALES)?>
    <?end for-each-group?>
    <?variable@incontext:T;.//RESULTS?>
    <?for-each@cell:$c297?>
    <?for-each@cell:$c297?>
    <?for-each@cell:xdoxslt:get_groups($_XDOCTX,'v','YEAR',string(.))?>
    <?sum ($T[(./QUARTER=current())]/SALES)?>
    <?end for-each?><?end for-each?>
    <?sum ($T/SALES)?>
    Thanks,

  • Is there a limit to no. of summary fields that can be used in a cross tab?

    Hi,
    While creating a cross tab is there a limitation to number of summarized fields that can be used?
    - The cross tab when uses 184 fields as summary fields leads to Crystal report application to crash at the time of export to excel.
    - Tried with two Datasources: XML and excel
    - If we reduce the number of summary fields used to 102 exactly, export works fine in excel.
    - If 2 cross tabs are used each containing 92 summary fields(in order to show 184) export to excel works fine.
    Please let me know if there is any such limitation which leads to CR application to crash when exporting in excel?
    Thanks
    Regards,
    Nidhi

    I suggest you purchase a case and have a dedicated support engineer work with you directly:
    http://www.sdn.sap.com/irj/boc/gettingstarted
    Or
    http://store.businessobjects.com/store/bobjects/Content/pbPage.CSC_map_countyselector/pgm.67024400?resid=jFmmLgoBAlcAAALO-iYAAAAP&rests=1278687224728
    If this is a bug you'll get a refund, if not post your enhancement request in the Idea Place. Or the Rep will suggest a better way to create your report.

  • Sorting a cross tab total

    I am a newcomer (user) to Discoverer so would appreciate some help.
    I have written a cross tab report which shows my sales people in the rows and different sales catagories in the columns. I have then put a total on my rows (total for each sales person) which works fine.
    I then want to sort my sales people by their "total sales" ie my calculation.
    Looking in the sort functionality I appear to only be able to sort the sales people by each of the actual columns of data which come back in the report (ie the sales categories - cat 1 or 2 as below)
    E.g
    Cat 1 Cat 2 Total
    Sales Man 1 10 15 25
    Sales Man 2 15 30 45
    I want to sort so that the 45 is viewed and Sales Man 2 is sorted to the top.
    Help?
    Ed

    Hi,
    Sorting a crosstab how you want is always difficult. If you only ever want two categories as column headers then it will be easier to use a table report and decode out the categories and sort by the total.
    Otherwise you will have to use a analytic sum with a partition to calculate the total for each sales in a calculation and then include that calculation as a dimension. You will then be able to sort the crosstab using this dimension and if necessary hide the content of the field using formatting.
    Rod West

  • To Merge Cross Tab Header in Web-I XI R2

    Hello All,
    I have one cross tab report and Its header is Name field.When we run the report, suppose we get 15 columns so 15 times the report header displays the "Name" in cross tab. I want to display the 'Name ' field only once in middle of cross tab header.
    The Scenario :--
         Name     Name     Name     Name     Name     Name     Name     Name
    Region     q     wr     er     dv     vderg     gr     gff     dfgf
    Region                                        
    Region                                        
    Region                                        
    Region                                        
    Region                                        
    Region                                        
    The expected result :--
                                                                             Name                                   
    Region     q     wr     er     dv     vderg     gr     gff     dfgf
    Region                                        
    Region                                        
    Region                                        
    Region                                        
    Region                                        
    Region                                        
    As per the cross tab basics --- we can not merge the cross tab header however I want any alternative solution or any work-around for it.
    Thank you.
    Bhushan

    Hi Sunil Kumar ,
    I tried this way my user wants a report year,quarter,sales and quantity in cross tab format..
    YEAR
    Q1
    Q2
    sales
    quantity
    sales
    quantity
    2009
    XXXXX
    XXXXX
    XXXXX
    XXXXX
    2010
    XXXXX
    XXXXX
    XXXXX
    XXXXX
    2011
    XXXXX
    XXXXX
    XXXXX
    XXXXX
    2012
    XXXXX
    XXXXX
    XXXXX
    XXXXX
    If any inputs always welcome.
    Regards
    Durgaprasad.yelluri

  • Crystal Report Cross Tab Report

    In crystal report 2008, i created a cross tab report. Column shows sales order number and rows show item number.
    For columns that shows sales order #, I also wanted to show sales person name field right beside it. In cross tab expert, I added the field salesperson name.
    However, crystal cross tab shows the sales person at a separate column with duplicate information. I only want to show sales order no. with sales person name under one column. Is there a way to achieve this? Thanks.

    This would be a hard job.
    Have you tried Pivot Table function in Excel? You can play with it and get some ideas.
    Thanks,
    Gordon

  • Every time I open a tab i get several tab that open up one after another all labeled Index of file:///C:/Program Files (x86)/Mozilla Firefox/

    When I open Mozilla Foxfire I get several tabs that automatically each heading is (Index of file:///C:/Program Files (x86)/Mozilla Firefox/) then shows all file in Mozilla installation Dir. This is the address in the address bar (file:///C:/Program%20Files%20%28x86%29/Mozilla%20Firefox/). My home page is set for MSN.com

    If you get a program called malware bytes it blocks that window from popping up. Hope that helps :)

  • How to add an image or static text in the header of EACH page of a cross-Tab report

    Post Author: rtutus
    CA Forum: General
    Hi, I use Crustal 11.0.
    I have a cross Tab. I display the items on the left column and the months horizontally, the items are grouped by category field. The values are the sum of quantities are displayed for each month. Like this:
                             Items         Jan       Feb       March .....................Total
    Category 1                       
                             Item11         val11     Val12      Val13                     Total values
                             Item12         val21     Val22      Val23                     Total values
                             Item13         val31     Val32      Val33                     Total values
    Category 2                       
                             Item21         val11     Val12      Val13                     Total values
                             Item22         val21     Val22      Val23                     Total values
                             Item23         val31     Val32      Val33                     Total values
    Category 3                       
                             Item31         val11     Val12      Val13                     Total values
                             Item32         val21     Val22      Val23                     Total values
                             Item33         val31     Val32      Val33                     Total values
    The problem, I want to add a page header for each page of the report.
    When Crystal reports first displays my cross-tab in the designer, CR displays the cross tab in the Report header section. I d like to add text or image for each page and not only at the begining of my Cross-Tab.
    If I just add an image or text at the top of the report designer, which is my report header, I get the image or text only on the begining of the 1st page of my report but never in the other following pages.
    If I try to work around the problem and move the cross Tab to a group section instead, and then put the Image in the group header, I get what I want, but the problem is that:
    The columns header: Jan, February....December are displayed for each group of my report and not only in the beginning of the report. I get something like this:
                             Items         Jan       Feb       March .....................Total
    Category 1                       
                             Item11         val11     Val12      Val13                     Total values
                             Item12         val21     Val22      Val23                     Total values
                             Item13         val31     Val32      Val33                     Total values
                             Items         Jan       Feb       March .....................Total
    Category 2                       
                             Item21         val11     Val12      Val13                     Total values
                             Item22         val21     Val22      Val23                     Total values
                             Item23         val31     Val32      Val33                     Total values
                             Items         Jan       Feb       March .....................Total
    Category 3                       
                             Item31         val11     Val12      Val13                     Total values
                             Item32         val21     Val22      Val23                     Total values
                             Item33         val31     Val32      Val33                     Total values
    You see the months get duplicated. Any way, my real need is to add an image or text in the header of EACH page of a cross-Tab report.
    Thanks a lot for your help.

    Hi Divya,
    you could do for example in the wdDoInit() of the view
    wdContext.currentContextElement().setPicture("picture.gif");
    Now you assign this context variable to the Tab using the Tab_header's imageSource-Property. When you click on its value column, you see a button with three dots on it. If you click on this button, you will get all context nodes and attributes for this View. Usable variables are clearly marked, you now choose the one named Picture or what ever name you prefer to use. But it must correspond to the one set in the wdDoInit.
    I think setting a picture (not necessarily for the tab-page) is done in one of the excellent tutorials. If you are a newcomer I strongly recommend doing some of the tutorials.  I have learned tremendously from them.
    Hope this helped
    Harald

  • Cross Tab display problem in viewer.

    Post Author: SamCCO
    CA Forum: .NET
    I am having a problem with the CrystalReportViewer in Visual Studio 2005.  I have a report which contains a cross tab object that has the upper column labels rotated 90 degrees so that the column widths remain small.  When I view the report in the web viewer in VS 2005, the column labels are all horizontal and unreadable because they run into each other across the top of the cross tab.  Why won't the labels render in a 90 degree fashion?
    When you print the document from the viewer it shows the labels at 90 degrees.  Is this a bug in the report viewer?

    Update
    Hi Guys the report is working fine with cross tab . Its giving the above error when ever I click the Drill to link which takes to the another detail report.
    thanks in advance

  • Cross tab data is getting multiplied if i use multiple queris in asingle report

    HI,
      i am using multiple queris for displaying data and graphs(charts).
      my requirement is to display 2 charts and data in crosstab in a single report.
      all the three thing (2charts and crosstab) will use diffrent values.
    I am writing 3 sql queries for getting appropriate values for charts and crosstab.
      Now the problem, both charts and crosstab are taking the values of all 3 queris
    i.e if i added crosstab  first to the report values are coming correctly. After  that if i add graph cross tab values are getting changed and graph values are not getting properly.
    if i add graph first then its coming correctly.
    if i tried to add all 3 components then values are going cores...... ?

    When you say you are writing 3 sql queries what do you mean? Are you creating 3 SQL command objects in the database expert? If so this is your problem, Crystal will pull a cartesian product through (this is every possible combinatin of rows from the 3 queries).
    If your 2 graphs and 1 crosstab are based on different datasets the way to approach this is to create each on a seperate report, then create a new blank report and add each of your 3 reports as subreports in the report footer.
    Hope this helps,
    Toby

  • How to get the last "reported" value in a cross tab

    Dear all,
    based on a BeX Query Universe I have built a report with a cross tab in webI.
    Maybe you can help me with the following issue. There I have a problem: I want to get in the Total-column always the last reported value, e.g. for Number Total Customers "66", not for Mar or Apr, because they are null.
    Calendar Month                      |Jan| |Feb| |Mar| |Apr| |Total|
    Number Total Customers         |54|    |66|  | |      | |       66
    Number Active Customers      |57|    |71|  | |      | |       71
    I hope that you understand my problem and could help as soon as possible.
    Thanks a lot in advance for your support.
    Best regards.
    Edited by: HOLWUE on Feb 8, 2010 1:40 PM

    Hi,
    If this question is related to Webi then post in the below forum.
    http://scn.sap.com/community/businessobjects-web-intelligence/content?filterID=content~objecttype~objecttype[thread]
    Regards,
    Sujit.

  • My Mac Book Pro changes the saved home page each time I start Safari.  I also get new tabs that randomly open asking to clean up my Apple

    My Mac Book Pro changes the saved home page each time I open Safari.  I am also getting random tabs opening with various "cleaning up" my computer junk.
    How do I get rid of this?  I tried some of the fixes listed but they don't seem to work or I am doing something wrong.
    THanks
    Wendi

    You may have installed one or more of the common types of ad-injection malware. Follow the instructions on this Apple Support page to remove it. It's been reported that some variants of the "VSearch" malware block access to the page. If that happens, start in safe mode by holding down the shift key at the startup chime, then try again.
    Back up all data before making any changes.
    One of the steps in the article is to remove malicious Safari extensions. Do the equivalent in the Chrome and Firefox browsers, if you use either of those. If Safari crashes on launch, skip that step and come back to it after you've done everything else.
    If you don't find any of the files or extensions listed, or if removing them doesn't stop the ad injection, ask for further instructions.
    Make sure you don't repeat the mistake that led you to install the malware. It may have come from an Internet cesspit such as "Softonic" or "CNET Download." Never visit either of those sites again. You might also have downloaded it from an ad in a page on some other site. The ad would probably have included a large green button labeled "Download" or "Download Now" in white letters. The button is designed to confuse people who intend to download something else on the same page. If you ever download a file that isn't obviously what you expected, delete it immediately.
    Malware is also found on websites that traffic in pirated content such as video. If you, or anyone else who uses the computer, visit such sites and follow prompts to install software, you can expect more of the same, and worse, to follow. Never install any software that you downloaded from a bittorrent, or that was downloaded by someone else from an unknown source.
    In the Security & Privacy pane of System Preferences, select the General tab. The radio button marked Anywhere  should not be selected. If it is, click the lock icon to unlock the settings, then select one of the other buttons. After that, don't ignore a warning that you are about to run or install an application from an unknown developer.
    Still in System Preferences, open the App Store or Software Update pane and check the box marked
              Install system data files and security updates (OS X 10.10 or later)
    or
              Download updates automatically (OS X 10.9 or earlier)
    if it's not already checked.

Maybe you are looking for