A Report for top spent with Given Sitecode and Year

Customer Code
Name
Spent2011
xyzaa
Jon
700.00
nmcb
Stuart
400.00
bncx
Prakash
300.00
nmsd
Srinu
200.00
opkls
Kumar
90.00
                  Table above as retrieved data For
   Site 01
Rank the customers by top spent for 2011 or 2012 or 2013 or 2014
Ex: A Financial year 2011 to be considered between the dates April 1<sup>st</sup> 2011 and Marc 31<sup>st</sup> 2012
Customer table has the complete details of the customer 
and with unique customer code
Order Table has the details of the order placed and the Order Placed Date
Order Item Table has the Gross   price of each Item.
Site Table can be joined with Order Table (has a common column)
A  T-SQL query for  the SSRS report needs to be build with Inputs  site code and Year

Hi Visakh,
Please find the below script
--DECLARE @CustomerId varchar(255) = 'XX03045651';
DECLARE @STOREID VARCHAR(10) ='XX01'
SELECT
       OrderNumberStr,
       CustomerCodeStr
INTO
       #Sales
FROM
       OrderTable
        lEFT JOIN
 SiteShopTable
       ON
SiteShopTable.SiteCodeStr=LEFT(Ordertable.OrderNumberStr,4)
WHERE
       LEFT(Ordertable.OrderNumberStr,4)= @StoreID
                            AND
       LEFT(Ordertable.OrderedAtSiteCodeStr,4)=@StoreID
SELECT
       #Sales.CustomerCodeStr,
       SUM(OrderItemTable.FinalPriceGrossMoney) AS TotalSpend,
       SUM(OrderItemTable.QuantityOrderedInt) AS NoOfItems
--INTO
     --  #Spenders
FROM
       OrderItemTable
       INNER JOIN
       #Sales ON OrderItemTable.OrderNumberStr = #Sales.OrderNumberStr
GROUP BY
       #Sales.CustomerCodeStr
ORDER BY      
       TotalSpend DESC
SELECT
       distinct OrderTable.CustomerCodeStr,  
       '2014'=
       Case
       when year(Ordertable.OrderPlacedDateSdtm) = '2014' THEN sum(isnull(TotalSpend,0))  end,
       '2013'=
       Case when year(Ordertable.OrderPlacedDateSdtm) = '2013' THEN sum(isnull(TotalSpend,0)) end,
       '2012'=
       Case when year(Ordertable.OrderPlacedDateSdtm) = '2012' THEN sum(isnull(TotalSpend,0)) end ,
        'Before2012'=
       Case when year(Ordertable.OrderPlacedDateSdtm) < '2012' THEN sum(isnull(TotalSpend,0)) end
         --SUM(IF(year(Ordertable.OrderPlacedDateSdtm)=2010,orderitemtable.FinalPriceGrossMoney,0)) AS fy_2010
   --  , SUM(IF(fy.year=2011,i.invoiceValue,0)) AS fy_2011
   --  , SUM(IF(fy.year=2012,i.invoiceValue,0)) AS fy_2012
  FROM
#Spenders
left join
OrderTable  
on #Spenders.customercodestr=OrderTable.CustomerCodeStr
GROUP BY
        OrderTable.CustomerCodeStr,
       Ordertable.OrderPlacedDateSdtm
order by
OrderTable.CustomerCodeStr
drop table #Sales
drop table #Spenders

Similar Messages

  • Report for Billing doc with payment status and tax details

    Hi All,
    I want the report for payment due billing documents with following fields and after payment is done( F-28 ) that document should not appear in the report for the said period.
    Billing date, Billing doc no, Net value, Tax Amount
    Thanks and regards,

    Dear,
    Check S_ALR_87012172,S_ALR_87012186,S_ALR_87012168, S_ALR_87012197, S_ALR_87012173, S_ALR_87012174.
    Regards,
    Mahesh Wagh

  • Report for wage type with number, amount and amount per unit?

    Hi friends.
    I would like to know if there exits a report for wage type (like the PC00_M99_CWTR) that shows the number (anzhl), amount per unit (betpe) and the amount (betrg) of a person for a specific wage type.
    The standar report PC00_M99_CWTR does not display the amount per unit (betpe).
    Thanks in advance.
    Albio.-
    Edited by: Albio Manuel Vivas on Oct 20, 2011 6:13 PM

    Thanks,
    could you tell me what transaction i'll should use?
    thanks in advance
    Albio.-

  • Setup reports for pdf creation with company logo and printing without

    Hi,
    we want to have 2 different report-layouts.
    The first one is just for printing on company paper. So it doesn't need a logo.
    The second one is for exporting to PDF file. So it needs a logo.
    How can I realise it in SAP BO 2007 without changing the standard layout everytime?

    Meike,
    If sending out pdf's vs printed doc's depends on BP or user, you can play with setting up the default layout for specific users or BP's, otherwise you need to change the default one all the time.
    Regards,
    Nat

  • Report for failed delivery with reasons

    Hi all,
    Maybe i am blind, but I cant find a way to do an automatic report or email a report for bounced emails with details.
    So I need to get a report with the email address, message number and the reason for the bounce or failure for Example: bounced by destination server. Reason: 5.1.0 – Unknown address error ('554',
    Any where I can do this?
    I see the bounce logs have this information, but short of ftp'ing this daily then writing a script to email this out I cant see how to do this.
    It would be nice to just have a daily email report
    Regards
    Adam

    On box - no easy way that I can think of other than what you've mentioned.  You could however accomplish this (as well as any other custom reports you would want to create) with SawMill (https://www.sawmill.net). 
    This used to be used heavily back when the WSA was first released as on box reporting wasn't up-to-par.  However, it can be used for the ESA as well.

  • Report for CS15 tcode with multiple material nos. in selection screen.

    I want to develop a report for cs15 but with multiple materials.
    Like in cs15 we enter the material and its plant, then click on multi level check box and get the output. But cs15 works only for a single material. I want to develop a report in which i'll give multiple material nos. and then i should get the output for each material entered just as the output that would appear in cs15 for that material.
    How do i do it.
    I have tried but i'm not able to track back.

    Hi Priti,
          try develop a interactive report which lists all the materials in the first screen and when you double click on each of the material then call transaction CS15 output by skipping the first screen .Use set parameter to pass the material .
    Regards,
    Sirisha

  • Report for Purchasing Documents with Over Delivery or Under Delivery Tolera

    Dear All !
    please suggest me a report for Purchasing Documents with Over Delivery or Under Delivery Tolerance limit.
    thanks n regards
    Naagsekhar

    hi,
    Go to ME2N --> Use dynamic selection, choose for hte Puchase doc item --> here select for the over and under delivery and then execute the report..
    Hope it helps..
    Regards
    Priyanka.P

  • The very top bar, with mini,mize and close is missing -how can I reveal it?

    I seem to be missing a top bar, with minimize, Maximize, and close -and also am missing dropdowns for "Tools" and possibly others.

    Resolved -I had "overlooked" that the Menu bar was not clicked. Mea culpa.

  • I am trying to insert rows for alert_id 22 with diff abc_id and xyz_id

    I am trying to insert rows for alert_id 22 with diff abc_id and xyz_id
    these inserts will store in two tables that I have to join in the cursor.
    I have written cursor without passing cursor parameters. but here i need to pass acb_id and xyz_id along with alert_id.
    then if these are saticified with alert_id 22 then I want to stop the loop run, else i need to continue the loop. bcause the abc_id and xyz_id are diff for alert_id 22
    This is the issue I am facing!
    Please let me know if you have any idea. Let me know how to use cursor parameters here and in loop.
    Sample proc like this::
    Declare
    main_cursor
    another_cur
    alert_cur
    begin
    need to check first abc_id,xyz_id is already exist with alert_id 22
    if this set of records already exists then
    exit from the loop
    else
    continue with
    loop
    here coming the insert statements with different condition getting from first two cursors.(this part is ok for me)
    end loop
    end if
    Please write the logic if any idea on this.
    -LRK

    I want to stop if already alert_id is exist!

  • TO GET WEEKS for a given MONTH AND YEAR

    Is there any FM to get the no of weeks for a given month, say 01 2005.
    Can i get the week numbers say 1 2 3 4 5 for the given month and year.
    Please let me know.
    Happy Holidays.
    Regards,
    Manohar E

    Hi Manohar,
       Use FM DATE_GET_WEEK twice; first time pass first day of the month and again pass the last day of the month as a parameter. So u will be having week number(yyyyxx) for the first week of the month and week number for the last week of the month. From these two, in between week numbers u can easily fetch. I hope this will help u out.
    Regards,
    Kavya Shah

  • When trying to download 4.3.3 for iphone 4 with firewall off and antivirus off but i keep on getting the error code 3259 - sometimes it times out after a few seconds other times it will be half anhour - can anyone help?

    Hi,
    When trying to download 4.3.3 for iphone 4 with firewall off and antivirus off i keep on getting the error code 3259 - sometimes it times out after a few seconds other times it will be half an hour - can anyone help?
    Thanks

    Before beginning the download, try temporarily disabling the antivirus, anti-adware, anti-spyware, and any other anti-whatever that is required and is running with that secure OS.

  • I payed for an album with 32 songs and only got 16

    I payed for an album with 32 songs and only got 16 please help

    Contact iTunes Customer Service and request assistance
    Use this Link  >  Apple  Support  iTunes Store  Contact

  • ALV REPORT FOR TOP 10 CUSTOMERS

    hI,
    sap guys
    I need a help on alv. iam getting alv report. now i need to get TOP 10 customers in my report.
    My report having selling price , cost price , GP , GP% .
    Final internal table iam sorting based on Selling price. But how to Get the  Top 10 customers in my report.
    Plz help me..

    hi
    good day brother
    Before youve given the solution for top 20 cust as well as subtot.. iam getting a prob for one branch for subtot.
    Plz see the code..
    Ive dev the smart form for top 20 customers by Branch wise.. I have 17 branches in final itab.
    Every thing is fine except one branch for the Subtot.
    For getting  Subtot as well as Getting the top 20 cust.. the below code ive used.
    First branch like lt_br_out2 got 503 records
    lt_br_out3 == 213
    lt_br_out4 == 0
    lt_br_out5== 82
    lt_br_out6  ==89
    lt_br_out7 ==118
    lt_br_out8 == 45
    lt_br_out9 == 64
    lt_br_out10 == 53
    lt_br_out11 == 47
    lt_br_out12 == 56
    lt_br_out13 == 20 *************** "Problem with this internal table.
    lt_br_out14 ==170
    Problem: All Branches are getting subtotal and top 20 cust except " LT_BR_OUT13"...Before its going to cal the top 20 cust. its has only 20 records.
    Actually iam counting the top 20 cust as well as cal subtot and passing to Final Internal Table..
      SORT lt_br_out13  BY p1_a_p DESCENDING.
      CLEAR : lwa_out6.
      LOOP AT lt_br_out13 INTO lwa_out6.
        IF sy-tabix > 20.
          CLEAR: lwa_out6.
    ***adding the subtot
          lwa_out6-ort01 = lv_text.
          lwa_out6-p1_a_p = lv_brtot.
          lwa_out6-p2_a_p = lv_brtot1.
          lwa_out6-act_gross_p = lv_br.
          lwa_out6-act_gross_perc1 = lv_brperc1.
          APPEND  lwa_out6 TO lt_br_final.
          EXIT.
        ELSE.
    ***calc the sub tot
          lv_text    = 'Sub Total'.
          lv_brtot   = lv_brtot  + lwa_out6-p1_a_p.  " selling price
          lv_brtot1  = lv_brtot1 + lwa_out6-p2_a_p. " Cost price
          lv_br      = lv_brtot - lv_brtot1.
          lv_brperc   = ( lv_br / lv_brtot ) * 100.
          IF lv_brperc NE  0.
            WRITE lv_brperc TO lv_brperc1 LEFT-JUSTIFIED.
            CONCATENATE lv_brperc1 '%' INTO lv_brperc1 SEPARATED BY space.
          ENDIF.
          APPEND lwa_out6 TO lt_br_final.
        ENDIF.
      ENDLOOP.
    If i put sy-tabix >= 20, thne iam getting subtotal but iam getting only 19 records.
    Could u plz advice me.. Ive solved yesterday problem
    Regards

  • Create a site utilization report for SharePoint Site with these conditions

    HI,
    How do we create a site utilization report for a SharePoint 2007 site. I want to include the following conditions in the report
    a) The list of users who are accessing the site
    b) The list of users who have not accessed the site ( Can we do some filtration based on some conditions )
    c) When was the last date the user has accessed the site

    Hi Kalpana,
    Sorry for delay in reply. I don't think this can be possible from front end without involving SQL dbo users table. If you found any other alternate please share here.
    You can get site collection / sub site user details via
    SP user manager tool and for last access date - time you can use SharePoint object model. - ref : http://blogs.msdn.com/b/varun_malhotra/archive/2010/05/12/moss-2007-get-last-accessed-date-for-a-site.aspx
    Let us know if this helps
    Regards,
    Pratik Vyas | SharePoint Consultant |
    http://sharepointpratik.blogspot.com
    Posting is provided AS IS with no warranties, and confers no rights
    Please remember to click Mark As Answer if a post solves your problem or
    Vote As Helpful if it was useful.

  • Report for Vendor payment with check no, reference

    Hi Gurus;
    My client issue one cheque against multiple vendor invoices and used F-53 to knockoff vendor invoices against this cheque.
    He enter the check no. in assignment field.
    Now, he want a report for - Which check is used to knockoff (Paid) which invoice.
    Is there any way or report in SAP.
    Thanks in Advance.
    Devendra Singh Chauhan

    Hi Devendra,
    How about using the check register (transaction code S_P99_41000101) and select the radio button 'with items paid'. The report provides details such as check number, payment document, vendor invoice and other relavant details per bank account.
    Ashish

Maybe you are looking for

  • Os 10.4 won't install

    Hi. So I just bought a new hard drive and installed it on my ibook g4. When i try installing mac os 10.4, it keeps quitting shortly after starting (if it even passes the disk check). It will only tell me that "there were errors installing the softwar

  • More than 1 row is added but not!!!!

    The basic problem is that I execute the class that contains the code below multiple times, therefore, I assume that the contents of the prepared statement should be added to the database multiple times.  This is not happening as when I open the Acces

  • The problem about GPIB Wait

    Dear all, First, Thank you for your attention!!! I have to use a network analyzer to perform a test for the return loss of antenna. For convenience, I have to use both port 1 and port 2 in order to test two samples together. Because I plan to use mec

  • Do I need to uninstall Firefox 4 and start over?

    Firefox 4 upgrade worked for one user on my laptop, but not the other. All the features of the upgrade work for only one user.

  • SLT with MDC

    Hello experts, Is SLT working with MDC? If it is, how does SLT connect to the each tenant DB for data replication where there is one system DB? Please advise. Thanks.