Query for Total sales by customer

Hi,
I want to create a query for getting a total of all sales for all Customers for the date range entered by the user.
How can I do it?
Jyoti

If I can add my thoughts.  The query from Jyoti fails for me due to the Where statement.  Try the following:
SELECT T0.CardName, T0.Address, T1.CreditLine, T2.PymntGroup as 'Payment Terms', T1.Balance, T0.DocTotal
FROM OINV T0 INNER JOIN OCRD T1 ON T0.CardCode = T1.CardCode INNER JOIN OCTG T2 ON T0.GroupNum = T2.GroupNum
WHERE T0.DocDate BETWEEN '[%0]' AND '[%1]'
Having said that I use the built in Sales Analysis report to get the sales by customer by date.
regards,
Ralph

Similar Messages

  • Query for daily sales by warehouse

    Hi
    I need a query for   Daily sales by warehouse.  I am only new to this and struggling with generating.
    ideally it will look like the below.     With no selection criteria as I would like to schedule the report to email out at the end of each day.
    Warehouse      Revenue      GP          GP%
    NSW               $xxxx             $xxx       35%
    Would someone mind helping
    thanks

    thankyou ,   But i have multiple warehouse and i dont want to use a selection criteria.
    to expand on the original example
    Warehouse      Revenue      GP          GP%
    NSW                 $xxxx             $xxx           35%
    QLD                  $xxx               $xx            32%
    VIC                  $xxx               $xx            32%
    Also the results should only show figures for the day the query is executed
    Any help is appreciated.
    Similar layout to this,except using query and whs code.    the below is generated using sales analysis and customer group. 

  • Query for Weekly Sales Report

    Dear Experts,
    I have developed the query for weekly sales report for the alert management to send out the report on every Monday as follow :
    SELECT T0.[CardCode], T0.[CardName], T0.[DocDate], T1.[ItemCode], T1.[Dscription], T1.[Quantity], T1.[LineTotal] FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode WHERE T0.[DocDate] between GetDate()-8 and GetDate()-1
    The weekly report received on every Monday through email is without column total for the "Line Total".
    Can the Sum of column "Line Total" to be included in the query ?
    Thus, the auto send report on every Monday by alert management will display the total.
    Thanks in advance for all your kind assistance.
    Regards,
    Clara

    Ok you want it at the bottom.......
    then you must must try this if you are running query generator....
    Else a good option is Crystal Report.
    You need to only add Group Sum.......
    SELECT T0.CardCode, T0.CardName, T0.DocDate, T1.ItemCode, T1.Dscription, T1.Quantity, T1.LineTotal FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode WHERE T0.DocDate between GetDate()-8 and GetDate()-1
    Union All
    Select '','',Null, '','Total',Null, Sum(T1.LineTotal) FROM OINV T0 INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN OITM T2 ON T1.ItemCode = T2.ItemCode WHERE T0.DocDate between GetDate()-8 and GetDate()-1
    Regards,
    Rahul

  • Re: Statistics Query for Total runtimes for Process Chain incorrect

    Hi Guys,
    I am building a Query for Total runtimes for Process Chain Statistics. I used the Cube 0TCT_MC21 for Query - 0TCT_MC21_Q0101.
    I dragged in Keyfigure section - startdate, end date, Start time are all correct and fine but the End time (0TCTENDTIM) is coming incorrect. Is something else i should use to get the End time?
    Please let me know if any suggestions?
    Regards

    Just check if the end times are in GMT ?? usually happens with timestamps....

  • Query for Totals on a Sales Order

    Does someone have a query for sales order that sums the total # of orders for each user and sums total quantity and Amts?
    Thanks

    That would not be a hard query to write.  If you have started on the query, you may paste it if you are having difficulties getting the desired result.
    Suda

  • How to Apply YTM and MTD filter to the Query Calculating "Total Sales" Amt

    Hi,
    I got the requirement to calculate "Total Sales" amount in following format,
    1. Calculate Total Sales YTM per Country
    2. Calculate Total Sales MTD per Country
    I am done with Queries to get Country wise Total Sales amount but stuck at the point, how to apply YTM (Year to Month) and MTD (Month to Date) filter. Can anyone have idea about how to apply YTM and MTD filter to query??
    Regards,
    Priyanka

    Hi,
    I got the requirement to calculate "Total Sales" amount in following format,
    1. Calculate Total Sales YTM per Country
    2. Calculate Total Sales MTD per Country
    I am done with Queries to get Country wise Total Sales amount but stuck at the point, how to apply YTM (Year to Month) and MTD (Month to Date) filter. Can anyone have idea about how to apply YTM and MTD filter to query??
    Regards,
    Priyanka

  • Query for Itemwise Sales Register

    Hi Guys,
    Below is the query i have used to run Sales Register.But we need the sales register based on item wise and those Excise Duty calculations are needed for item wise instead of total document wise.
    Pls update the query ...
    SELECT M.DocNum AS 'Inv.No ', M.DocDate as 'Date', M.CardName as 'Customer Name',L.Dscription,L.Quantity,L.Price,
    (Select Sum(LineTotal) FROM INV1 L Where L.DocEntry=M.DocEntry) as 'Base Amt.(Rs.)',
    (SELECT Avg(TaxRate) FROM INV4 where statype=1 and DocEntry=M.DocEntry) as ' VAT % ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=1 and DocEntry=M.DocEntry) as ' VAT (Rs.) ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=4 and DocEntry=M.DocEntry) as ' CST % ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=4 and DocEntry=M.DocEntry) as ' CST (Rs.) ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=7 and DocEntry=M.DocEntry) as ' TAXEXEMPT % ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=7 and DocEntry=M.DocEntry) as ' TAXEXEMPT ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=8 and DocEntry=M.DocEntry) as ' VAT% ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=8 and DocEntry=M.DocEntry) as 'VAT12.5 ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=9 and DocEntry=M.DocEntry) as ' CST 2% ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=9 and DocEntry=M.DocEntry) as ' CST @2 ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=11 and DocEntry=M.DocEntry) as ' CENVCST % ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=11 and DocEntry=M.DocEntry) as ' CENVCST ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=-90 and DocEntry=M.DocEntry) as ' BED % ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=-90 and DocEntry=M.DocEntry) as ' BED ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=-60 and DocEntry=M.DocEntry) as ' Cess% ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=-60 and DocEntry=M.DocEntry) as ' Cess ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=-55 and DocEntry=M.DocEntry) as ' HCess % ',
           (SELECT Sum(TaxSum) FROM INV4 where statype=-55 and DocEntry=M.DocEntry) as ' Hcess ',
    L.LineTotal as 'Row Total (Rs.)',M.DocTotal as 'Doc Total'
    FROM OINV M LEFT OUTER JOIN INV1 L on L.DocEntry=M.DocEntry
    LEFT OUTER JOIN INV4 T on T.DocEntry=L.DocEntry and L.LineNum=T.LineNum
    LEFT OUTER JOIN INV5 J ON M.DocEntry = J.AbsEntry
    LEFT OUTER JOIN INV3 Q ON M.DocEntry = Q.DocEntry
    WHERE (M.DocDate >= '[%0]' AND M.DocDate <= '[%1]')  AND TargetType ! = 14
    GROUP BY
    M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.DiscSum,M.WTSum,L.Dscription,L.Quantity,L.Price,L.LineTotal,M.DocTotal
    ORDER BY
    M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.DiscSum,M.WTSum,L.Dscription,L.Quantity,L.Price,L.LineTotal,M.DocTotal
    Regards, Vamsi.

    Hi Guys, Below is the query i have used to run Sales Register.But we need the sales register based on item wise and those Excise Duty calculations are needed for item wise instead of total document wise. Pls update the query ...
    SELECT M.DocNum AS 'Inv.No ', M.DocDate as 'Date', M.CardName as 'Customer Name',
    L.Dscription,L.Quantity,L.Price, (Select Sum(LineTotal)
    FROM INV1 L Where L.DocEntry=M.DocEntry) as 'Base Amt.(Rs.)', (SELECT Avg(TaxRate)
    FROM INV4 where statype=1 and DocEntry=M.DocEntry) as ' VAT % ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=1 and DocEntry=M.DocEntry) as ' VAT (Rs.) ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=4 and DocEntry=M.DocEntry) as ' CST % ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=4 and DocEntry=M.DocEntry) as ' CST (Rs.) ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=7 and DocEntry=M.DocEntry) as ' TAXEXEMPT % ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=7 and DocEntry=M.DocEntry) as ' TAXEXEMPT ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=8 and DocEntry=M.DocEntry) as ' VAT% ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=8 and DocEntry=M.DocEntry) as 'VAT12.5 ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=9 and DocEntry=M.DocEntry) as ' CST 2% ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=9 and DocEntry=M.DocEntry) as ' CST @2 ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=11 and DocEntry=M.DocEntry) as ' CENVCST % ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=11 and DocEntry=M.DocEntry) as ' CENVCST ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=-90 and DocEntry=M.DocEntry) as ' BED % ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=-90 and DocEntry=M.DocEntry) as ' BED ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=-60 and DocEntry=M.DocEntry) as ' Cess% ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=-60 and DocEntry=M.DocEntry) as ' Cess ',
    (SELECT Avg(TaxRate) FROM INV4 where statype=-55 and DocEntry=M.DocEntry) as ' HCess % ',
    (SELECT Sum(TaxSum) FROM INV4 where statype=-55 and DocEntry=M.DocEntry) as ' Hcess ',
    L.LineTotal as 'Row Total (Rs.)',M.DocTotal as 'Doc Total'
    FROM OINV M LEFT OUTER JOIN INV1 L on L.DocEntry=M.DocEntry
    LEFT OUTER JOIN INV4 T on T.DocEntry=L.DocEntry and L.LineNum=T.LineNum
    LEFT OUTER JOIN INV5 J ON M.DocEntry = J.AbsEntry
    LEFT OUTER JOIN INV3 Q ON M.DocEntry = Q.DocEntry
    WHERE (M.DocDate >= '[%0]' AND M.DocDate <= '[%1]') AND TargetType ! = 14
    GROUP BY M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.DiscSum,M.WTSum,L.Dscription,L.Quantity,L.Price,L.LineTotal,M.DocTotalORDER BY M.DocNum,M.DocDate,M.CardName,M.NumAtCard,M.DocEntry,M.DiscSum,M.WTSum,L.Dscription,L.Quantity,L.Price,L.LineTotal,M.DocTotal

  • Query for Total Items

    Hi Experts..
    I need a query to find the total  items  sold in a particular period for an particular item.
    Pls help me in finding the query.
    Regards,
    Vamsi.
    Edited by: Parimis on Jan 20, 2010 5:10 AM

    Hi Vamsi,
    Check the thread,
    Help With Monthly Sales Query
    Regards,
    Madhan.

  • SQL Query for weekly sales

    Hi,
    This is my First table: REPORT
    with report as (
    select 'vendor_1' as vendor,to_date('1/1/2012','DD/MM/YYYY') supply_date, 'customer_1'as customer,'item_1' as item1, 110 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,120 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/3/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item1,130 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/4/2012','MM/DD/YYYY') supply_date,'customer_1'as customer, 'item_1' as item1,140 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/10/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item ,200as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/23/2012','MM/DD/YYYY') supply_date, 'customer_1'as customer, 'item_1' as item,0 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/6/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,160 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/7/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,170 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/8/2012','MM/DD/YYYY') supply_date,'customer_2'as customer, 'item_1' as item1,180 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/9/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,190 as cost from dual union all
    select 'vendor_1' as vendor,to_date('1/20/2012','MM/DD/YYYY') supply_date,'customer_2'as customer,'item_1' as item1,300 as cost from dual)
    THIS IS MY SECOND TABLE: TEMP_WEEK
    WITH temp_week a s(
    SELECT '01/01/2012 to 07/01/2012' AS week from dual union all
    SELECT '08/01/2012 to 14/01/2012' AS week from dual union all
    SELECT '15/01/2012 to 21/01/2012' AS week from dual union all
    SELECT '22/01/2012 to 28/01/2012' AS week from dual union all
    SELECT '29/01/2012 to 31/01/2012' AS week from dual)
    To find weekly sales i have wrote below query:
    SELECT week,vendor,customer,SUM (cost)
    FROM ( SELECT week,vendor,customer,SUM (cost) cost
    FROM (SELECT CASE
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 THEN
    '01/01/2012 to 07/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 THEN
    '08/01/2012 to 14/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
    '15/01/2012 to 21/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 THEN
    '22/01/2012 to 28/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 THEN
    '29/01/2012 to 31/01/2012'
    END
    week,vendor,customer,cost
    FROM report)
    GROUP BY week, vendor, customer
    UNION ALL
    SELECT tw.week,vendor,customer,0
    FROM ( SELECT week,vendor,customer,SUM (cost) cost
    FROM (SELECT CASE
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 1 AND 7 THEN
    '01/01/2012 to 07/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 8 AND 14 THEN
    '08/01/2012 to 14/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 15 AND 21 THEN
    '15/01/2012 to 21/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 22 AND 28 THEN
    '22/01/2012 to 28/01/2012'
    WHEN TO_NUMBER (TO_CHAR (TRUNC (supply_date), 'DD')) BETWEEN 29 AND 31 THEN
    '29/01/2012 to 31/01/2012'
    END
    week,vendor,customer,cost
    FROM report)
    GROUP BY week, vendor, customer),temp_week tw)
    GROUP BY week, vendor, customer
    ORDER BY vendor, customer, week ;
    with above query i am getting below output:
    with output as(
    select '01/01/2012 to 07/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 500 as cost from dual union all
    select '08/01/2012 to 14/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 200 as cost from dual union all
    select '15/01/2012 to 21/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 0 as cost from dual union all
    select '22/01/2012 to 28/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 0 as cost from dual union all
    select '29/01/2012 to 31/01/2012' as week,'vendor_1' as vendor,'customer_1' as customer, 0 as cost from dual union all
    select '01/01/2012 to 07/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 330 as cost from dual union all
    select '08/01/2012 to 14/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 370 as cost from dual union all
    select '15/01/2012 to 21/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 300 as cost from dual union all
    select '22/01/2012 to 28/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 0 as cost from dual union all
    select '29/01/2012 to 31/01/2012' as week,'vendor_1' as vendor,'customer_2' as customer, 0 as cost from dual )
    Clearly I have used cross join. But I want to get same output with some other way. I dont want to use cross join and Union
    please help me in this.

    DUPLICATE!
    SQL Query help.

  • Query for total size of the spatial data

    Hi,
    I found some posts to determine the size of the spatial table but is there a query I can use to determine the exact size of my spatial column. I have about 2 mil. geometry points and I would like to know exactly how many bytes it is.
    Thanks in advance.
    Aarthi

    Hi,
    I have an old analysis I did several years ago. I couldn't get size for the SDO_GEOMETRY column per se, but I could calculate the approximate size required (not including extra space required for block boundaries, etc.). Note this info is quite old, so your milage may vary...
    This is the summary:
    SDO_GTYPE 3 bytes plus 1 byte for every two numeric places  (four digit gtype=5 bytes)
    SDO_SRID 1 byte if NULL; or 3 bytes plus 1 byte for every two numeric places 
    SDO_POINT 1 byte if NULL; or for each of the three numeric values, 1 byte if
                 NULL, or 3 bytes plus 1 byte for every two numeric places 
    SDO_ELEM_INFO 1 byte if NULL; or for each numeric value, 3 bytes plus
                 1 byte for every two numeric places, plus 40 bytes overhead for the VARRAY. 
    SDO_ORDINATES 1 byte if NULL; or for each numeric value, 3 bytes plus
                 1 byte for every two numeric places, plus 40 bytes overhead for the VARRAY. 

  • Create multiple single unit wip jobs for total sales order line qty

    Hi all,
    I want to know if there's a standard way to create multiple single unit wip jobs from a sales order line which has 2 or more units, i mean...
    I have a sales order line with item A with 3 units. If I progress the sales order, a single job is automatically created in WIP with 3 units to be created. What i want is to create 3 jobs with one unit each, all of them linked to the sales line order...
    Thanks in advance!
    Regards!
    Answered.........
    Edited by: user604737 on Nov 10, 2010 3:51 PM

    Hi Sandeep
    We have similar requirement (SO qty = 3 then 3 WIP jobs should be created). However when planning releases WIP jobs it does not tie back(reserve) the jobs to sales order.
    Are you aware of any standard way to do the same??
    Regards
    Mudit Gupta

  • Regarding Customer Total Sales table

    Hi All SAP Experts
    I like to know which table will provide me total of each customers for year. an Actual sales for per customer. I know table VBAK with filed Net value. My question is that figure is right figure for each customer. I am looking for total sales. Report requirement is total sales it will not show line itemwise. Just total sales per customer.
    Thank you

    Welcome to the forum.  As a new member, I would like to inform you that there are certain rules and regulations applicable to this forum which you can find to your right screen where it has also been indicated that posting basic / repeated query is not allowed. Please search in this forum or Google it with the same text, so that you will find many threads discussed on the same topic.  Take the inputs from there and update still if you are not able to resolve.  Meanwhile, this thread would be locked.
    G. Lakshmipathi

  • MDX Query for Average customer first sale amount for each year

    Hello,
    I new to MDX, and I am looking to build a query that would get all the first sale amount for the customes and average that.  The intent is to use find an average each year.   I am looking to use this against the adventure works database.   
    I am not sure exatcly how to start this .  Any help is much appreciated.
    J

    Hi,
    I'll do it in several stages.
    let's first define an ordered set of date/sale to one customer over all periods:
    SELECT
    {[Measures].[Internet Sales Amount]} ON 0
    NonEmpty
    [Date].[Calendar].[Date]
    [Customer].[Customer].&[15561]
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customter].&[15561]
    ) ON 1
    FROM [Adventure Works];
    we retain the first line of the result set  with item(0):
    SELECT
    {[Measures].[Internet Sales Amount]} ON 0
    NonEmpty
    [Date].[Calendar].[Date]
    [Customer].[Customer].&[15561]
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].&[15561]
    ).Item(0) ON 1
    FROM [Adventure Works];
    next, for each year we define a measure that will retain the first sale for each customer
    (I  limit the customer set to the first 2000)
    WITH
    MEMBER [Measures].[Mymeasure 2006] AS
    NonEmpty
    Exists
    [Date].[Calendar].[Date].MEMBERS
    ,[Date].[Calendar].[Calendar Year].&[2006]
    [Customer].[Customer].CurrentMember
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].CurrentMember
    ).Item(0)
    ,[Measures].[Internet Sales Amount]
    MEMBER [Measures].[Mymeasure 2007] AS
    NonEmpty
    Exists
    [Date].[Calendar].[Date].MEMBERS
    ,[Date].[Calendar].[Calendar Year].&[2007]
    [Customer].[Customer].CurrentMember
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].CurrentMember
    ).Item(0)
    ,[Measures].[Internet Sales Amount]
    SELECT
    [Measures].[Mymeasure 2006]
    ,[Measures].[Mymeasure 2007]
    } ON 0
    ,NON EMPTY
    Head
    [Customer].[Customer].[Customer]
    ,2000
    ) ON 1
    FROM [Adventure Works];
    We then take the average for each year:
    WITH
    MEMBER [Measures].[AVG cust first sale 2006] AS
    Avg
    Head
    [Customer].[Customer].[Customer]
    ,2000
    NonEmpty
    Exists
    [Date].[Calendar].[Date].MEMBERS
    ,[Date].[Calendar].[Calendar Year].&[2006]
    [Customer].[Customer].CurrentMember
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].CurrentMember
    ).Item(0)
    ,[Measures].[Internet Sales Amount]
    MEMBER [Measures].[AVG cust first sale 2007] AS
    Avg
    Head
    [Customer].[Customer].[Customer]
    ,2000
    NonEmpty
    Exists
    [Date].[Calendar].[Date].MEMBERS
    ,[Date].[Calendar].[Calendar Year].&[2007]
    [Customer].[Customer].CurrentMember
    ,[Measures].[Internet Sales Amount]
    ,[Customer].[Customer].CurrentMember
    ).Item(0)
    ,[Measures].[Internet Sales Amount]
    SELECT
    [Measures].[AVG cust first sale 2006]
    ,[Measures].[AVG cust first sale 2007]
    } ON 0
    FROM [Adventure Works];
    Philip,

  • Sales Order Query for  in SAP B1

    Hi,
    I Need  to generate a report to Calculate the net sales orders for a particular customer in a given period. i can able to calculate the total sales order details itemwise but my query not works when the customer returns the particular products.( ie) I need to subtract the credit memo value from the order value of the particular product when the customer returns the product.
    Here is my Query Please any one Help me... what mistake in this query
    SELECT     A.CardName AS 'Customer Name', A.Address, A.DocNum AS 'Ord.No', CONVERT(varchar, A.DocDate, 3) AS 'Date', B.Dscription AS 'Item Name',
                          CASE WHEN B.itemcode = F .itemcode and A.CardCode = G.CardCode and A.Slpcode = F.Slpcode THEN B.quantity - F .quantity ELSE B.quantity END AS Quantity,
                          CASE WHEN B.itemcode = F .itemcode and  A.CardCode = G.CardCode and A.slpcode = F.slpcode THEN B.price - F .price ELSE B.price END AS Price, B.DiscPrcnt,
                          CASE WHEN B.itemcode = F .itemcode and A.CardCode = G.CardCode THEN B.linetotal - F .linetotal ELSE B.linetotal END AS Amount, B.VatPrcnt,F.ItemCode,E.Itemcode,D.Itemcode,C.Itemcode
    FROM
    ORDR A INNER JOIN
    RDR1 B ON A.Docentry = B.Docentry LEFT JOIN
    INV1 C ON A.Docentry = C.Baseref and C.Basetype=17 LEFT JOIN
    DLN1 D ON A.Docentry = D.BaseRef and D.Basetype=17 or C.Docentry=D.BaseRef and D.Basetype =13 LEFT JOIN
    RDN1 E ON D.Docentry = E.BaseRef and E.Basetype =15 LEFT JOIN
    RIN1 F ON C.Docentry =F.BaseEntry and F.Basetype = 13 or E.Docentry = F.BaseRef and F.BaseType = 16 or E.TrgetEntry = F.Docentry and F.Targettype= 14 LEFT JOIN
    ORIN G ON G.Docentry =F.Docentry Left join
    OSLP H ON A.Slpcode = H.Slpcode
    WHERE     (A.CardName = 'SHASUN CHEMICAL AND DRUGS') AND (A.DocDate >= '2000/9/30') AND (A.DocDate <= '2009/10/10')
    group by A.CardName , A.Address, A.DocNum , A.DocDate, B.Dscription,B.Itemcode,
    F.Itemcode,A.cardcode,G.cardcode,A.slpcode,
    F.Slpcode,B.quantity,F.quantity,B.Price,F.price,B.vatprcnt,B.discprcnt,B.Linetotal,F.linetotal,F.ItemCode,E.Itemcode,D.Itemcode,C.Itemcode
    ORDER BY 'Date'
    Thanks,
    vasanthapraba.

    Maybe this will help you further?
    SELECT A.CardCode, DocNum AS 'Ord.No', CONVERT(varchar, A.DocDate, 3) AS 'Date', B.Dscription AS 'Item Name', B.ItemCode AS 'Item Code'
    , SUM(B.quantity - D.quantity) AS 'Quantity'
    , SUM(B.price - D.price) AS 'Price'
    , SUM(B.LineTotal - D.LineTotal) AS 'Amount'
          FROM ORDR A
    INNER JOIN RDR1 B ON (A.DocEntry = B.DocEntry)
    LEFT JOIN DLN1 C ON (B.DocEntry = C.BaseEntry AND B.LineNum = C.BaseLine)
    LEFT JOIN RDN1 D ON (C.DocEntry = D.BaseEntry AND C.LineNum = D.BaseLine)
    WHERE (A.DocDate >= '20090925') AND (A.DocDate <= '20090925') AND (A.CardName = 'SHASUN CHEMICAL AND DRUGS')
    GROUP BY A.CardCode, A.DocNum, A.DocDate, B.Itemcode, B.Dscription
    ORDER BY 'Date'

  • Query for Sales order and corr.AR Invoice Info

    Hi,
    I need to write a query which gives the flollowing sales order info along with the coressponding AR invoices info
    Sales Order columns reqd:
    OPERATING_UNIT
    ORDER_NUMBER
    CUSTOMER_NUM
    CUSTOMER_NAME
    ORDERED_DATE
    FLOW_STATUS_CODE
    TOTAL_ORDER_AMOUNT
    AR invoice columns reqd for the sales orders:
    Invoice number,
    Invoice date,
    Invoice Total.
    Can anyone help me out with this?
    Thanks,
    Ash

    Hi Ash,
    There are some issues that must be defined before you have the exact query.
    Do you have freight charges or non-inclusive tax? If you have, freight charges and tax amounts must be included?
    Depending on you grouping rule, you can have lines from more than one order in a single invoice. In this case, as invoice amount you want the sum of all lines, or only the lines from that order?
    Below is an example using two views. It assumes that grouping rules split lines from different order into different invoices.
    Hope it helps,
    Ketter Ohnes
    create or replace view order_summary as
    select oh.org_id,
    oh.ORDER_NUMBER,
    oh.header_id,
    ott.name tt_name,
    ca.account_number,
    p.party_name,
    oh.ordered_date,
    oh.flow_status_code,
    sum(ol.ordered_quantity*ol.unit_selling_price) total,
    sum(ol.tax_value) tax,
    (select sum(operand)
    from OE_PRICE_ADJUSTMENTS_v x
    where x.header_id = oh.header_id
    and x.adjustment_type_code='FREIGHT_CHARGE') freight_charge
    from oe_order_headers_all oh,
    oe_order_lines_all ol,
    hz_cust_accounts ca,
    hz_parties p,
    oe_transaction_types_tl ott
    where ol.header_id=oh.header_id
    and oh.sold_to_org_id = ca.cust_account_id
    and ca.party_id = p.party_id
    and oh.order_type_id = ott.transaction_type_id
    and ott.language =
    (select language_code
    from fnd_languages
    where installed_flag = 'B')
    group by oh.org_id,
    oh.header_id,
    oh.ORDER_NUMBER ,
    ott.name,
    ca.account_number,
    p.party_name,
    oh.ordered_date,
    oh.flow_status_code;
    create or replace view invoice_summary as
    select a.interface_header_context,
    a.trx_date,
    a.trx_number,
    b.interface_line_attribute1,
    b.interface_line_attribute2 tt_name,
    a.customer_trx_id,
    sum(b.extended_amount) invoice_total
    from ra_customer_trx_all a,
    ra_customer_trx_lines_all b
    where a.customer_trx_id = b.customer_trx_id
    and b.interface_line_context = 'ORDER ENTRY'
    and b.line_type in ('LINE','FREIGHT')
    group by a.interface_header_context,
    a.trx_date, a.trx_number,
    b.interface_line_attribute1,
    b.interface_line_attribute2,
    a.customer_trx_id;
    select *
    from order_summary o,
    invoice_summary i
    where o.order_number between :1 and :2
    and o.order_number = i.interface_line_attribute1
    and o.tt_name = i.tt_name;

Maybe you are looking for

  • Rounding of Excise duty

    Hi, I have made  Excise duty   Rounding Rule "commercial" but still it is not rounding off in Sales Order. also i have made  Requirement     13- Rounding as per T001R still it not rounding Reg, amol

  • How to sequence the order of the elements in an Adobe Form?

    In one of my Adobe Forms, I have a table under a subform. Now I need to add a small gap and text above this table . So I started with a subform and a text box with in this subform. As soon as I add these, they are getting patched after the table. How

  • Save messages to memory card 3230

    does anyone know how to save incoming messages to memory card automatically instead of to phone memory in 3230 plz?

  • Vertical Centering of a page in GoLive

    I need a help in vertical centering a page. After long trials and with the help of others in this forum I was able a website that is functioning well enough. The only concern is that it needs to be centered vertically. You can see the website on: htt

  • Cant print single PDF pages

    Trying to print single PDF pages, forced to print all pages sent via email. Dialog box has greyed out page selection portion. Samsung Galaxy S4.   HP App loaded from Google Play. HP 4500 Envy. Thank you Thurston