Divide sales by no of Days

Hi friends, here is my task, appreciate your help.
Table_A:
Code
Date
111
1/1/2014
111
1/2/2014
111
1/3/2014
111
1/4/2014
111
1/5/2014
111
2/1/2014
111
2/2/2014
111
2/3/2014
111
2/4/2014
111
2/5/2014
Table_B:
Code
Jan
Feb
111
1000
2000
Need Result As:
Code
Date
SplitByNoOfWorkDays
111
1/1/2014
    200
111
1/2/2014
    200
111
1/3/2014
    200
111
1/4/2014
    200
111
1/5/2014
    200
111
2/1/2014
    400
111
2/2/2014
    400
111
2/3/2014
    400
111
2/4/2014
    400
111
2/5/2014
    400
Royal Thomas

;with cte1 as (select code, LEFT(datename(month, [date]),3) as [Mnth], count(*) as cntDays
from table_a GROUP by [code], datename(month, [date]),3),
cte2 as (select [code], [Mnth], [Days] from table_b UNPIVOT ([Days] for [Mnth] IN ([Jan],[Feb])) unpvt)
select T.[Code], T.[Date], c.SplitByNoOfWorkDays] from Table_A T inner join 
(select c1.*, cast(c2.[Days]/c1.[cntDays] as decimal(10,2)) as [SplitByNoOfWorkDays]
from cte1 c1 inner join cte2 c2 on c1.[code] = c2.[code] and c1.[Mnth] = c2.[Mnth]) c
on T.[code] = c.[Code] and left(datename(month,T.[Date]),3) = c.[Mnth]
From the top of my head and not tested. Also assumes you only have 1 year of data in the table. 
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles

Similar Messages

  • Pivot sales analysis report by day for a particular month - sap has by month and annual

    Hi guys,
    I'm trying to come up with a pivot sales analysis query report for items for the month by displaying individual days sales, sales amount, gross profit, gross profit %
    e.g
    Month of March
    1st, 2nd, 3rd, 4th.....31st march. In sap their is a sales analysis report by
    days of the month
    1st March
    2nd march
    31st march
    item no
    item description
    Qty
    sale amount
    gross profit
    gross profit%
    qty
    sale amt
    gross profit
    gross profit %
    Qty
    sale amt
    gross profit
    gross profit %
    sugar
    20
    20,000
    5,000
    25
    30
    30,000
    10000
    33.3
    40
    40000
    15000
    37.5
    n02
    n03
    no4
    Regards Brian

    Hi,
    Due to pivot limitation, not possible to get above data in pivot table.
    Try this simple query which matches system sales analysis by item.
    SELECT t1.itemcode as Itemcode, T1.[Dscription] as 'Item description',  sum(T1.[Quantity]) as Qty, sum(T1.[LineTotal]) as 'sales amount', sum(T1.[GrssProfit]) as 'Gross Profit'
    FROM OINV T0  INNER JOIN INV1 T1 ON T0.DocEntry = T1.DocEntry WHERE month( T0.[DocDate]) = '1' and year( T0.[DocDate]) =2014 GROUP BY T1.[ItemCode], T1.[Dscription]
    Thanks & Regards,
    Nagarajan

  • Sales of Last two days of each week in a given Posting Period ???

    Hi,
    Here I would like to share one of my tech. requirement in Bex query, your inputs are much appreciated -
    Scenario - In report I want to show "Sales for Last two days of week". I elaborate more like -
    (1) User inputs will be given for "Fiscal period" through Variable.
    (2) In Row all weeks lying in this period will be displayed.
    (3) In Column 1, Sale for each week will be shown.
    (4) In Column 2, Sale for Last two days of each week is to be displayed. (here we need to restrict Sales with last 2 Calendar days of each week.)
    Point 4 is of my concern. Any suggestions will help a lot. Points must be assigned.
    Regards,
    Saurabh

    Hi,
    I do not have a very good solution for you - see if this is of use.
    Firstly, I am not sure if it is possible to show the query like you want, with the weekly sales and the "last 2 day/week" sales combined and intertwined in one query.
    To create a query which will only show the sales of last 2 days of every week, what you can do is to create a variable on 0calday which will be 'multiple single values' type and will be calculated based on the user input of fiscal period (exit variable). This exit logic should assign the variable the last 2 days of each week falling within this period.
    Now you can put 'week' in the in the rows and restrict the query filter using the 0calday variable; put the KF in the columns area. This would lead to one row being displayed for each week and sales for only the last 2 days showing in that row.
    Creating a query for weekly sales is simple - maybe then you can put these two queries side by side in a workbook/web template.

  • Calculate sales for last 60 days

    hello
    want to make key figure or formula, which calculate sales for last 60 days, but also i need to add week group in report, so for each week i need sum sales for last 60 days before this ...
    is any solution to that?
    thank you.

    Alex,
    I'm not very clear on what you are asking.
    If you use your time parameters in selections you can use caldays and weeks with your key figures.
    ie. Selection 1 has your key figure and calday restricted t the last 60 days.
    Selection 2 has your key figure and Fiscal Week but I am not clear on the range required for fiscal week.
    Regards
    Gill

  • Sales order based on day

    Hi all,
    Iu2019m am a beginner in billing, but have experience in MM & FICO.
    Just needed help on billing front.
    I have a scenario and here it goes.
    Our billing is done per day  based working days in month, the bill is generated in the month end.
    Eg :
    If the billing dates are from 1.11.08 to 30.11.08, assuming the total working days in a month are 23 and the rate is 255 INR per day the invoice amount should be 255* 23.
    I was able to achieve the billing amount by keying in manually no of days as 23 and the calculation goes through condition type in the sales order. But in case if the billing date extends to mid of next month then the system takes 23 days for next month billing, which should not be, instead it should be 1st to mid of the month(eg 14 days * 255 INR) and that should be billed.
    But what is required is, in few cases the billing date is in between the month (assume 17-11-08) then the system should calculate the days instead of keying in manually.
    I am not able to change the quantity field in the billing plan, if above cannot be automated then how do I configure to change the quantity in billing plan.
    Being a beginner I require your help and guidance.
    So pls help.
    Thanks,
    Chandru

    Hi ,
    In MD01 you have the Planning date butin MD02 you don't have the system date and sy-datum is picked by the system for Single item multi level plannng run.
    If you run the report in Midnight dates will change for MD02 but not for MD01.
    Also you should check the MD05 after each MD01 and MD02 for comparison.
    Don't use Creation indicator 3 in any case for for MD01 and MD02.
    Please don't see the result in Production server as there requirements are changing everysecond.
    - MD01 is generally used to run the MRP for all the materials in a plant .
    - MD02 is used to run MRP for materials which have a BOM i.e multi-level
    Check this thread also though it is not your problem but shows why difference is there between the results of MD01 and MD02
    MRP Run MD01 & MD02
    Regards
    Ankur

  • Need Avg sales for 90 fiscal days - thru customer exit or Offset  ? ? ? ?

    Hi Frns!
    My current report generates daily sales for fiscal period using a customer exit variable A.
    My requirement now is to have one more column having Average sales for 90 prior fiscal days when i enter a fiscal period thru the same variable A.
    As the customer exit variable is of Selection Options, I'm unable to create Offset for the same.
    Guyz do need ur help on this urgently.
    Cheers! Shana

    Any updates !!!!!!!!!!!!!

  • Good Issue date in the Sales order should 1 day difference from the MBDAT

    For the particular customer, i want to have difference of 1 day in between the material availability date & good issue date in the schedule line. As per standard i can't made any changes in route and shipping point. Suppose material availability date in sales order is 22.09.2010 than my good issue date should be 23.09.2010 in the sales order. Any body having any idea how can we handle this case and what are things we need consider impact of this change.
    Regards,
    Srinivas.

    Hi,
    I think you can easily enable this in Route scheduling /Delivery scheduling. You have to maintain the load time and pick/pack time as the total of 8hours. If this is done, then after material availability date, one more day will be added and the final day will be considered as GI date.
    If you dont want to do this, you only have to enable this by Z by using a user exit where you can add one day to the MBDAT and update that in GI date.

  • Sales returns after 180 days

    Dear team,
    I have one doubt in return order creation. There are two scenarios while creating return order, (1) if customer returns within 180 days (from invoice date) than i need to give him full credit (base price as well as tax) and (2) if customer returns after 180 days of invoice than only base price needs to be credited. Tax amount shoud not be credited.
    How can i map this in SAP ?..
    your helpful answers will be rewarded by points...thanks in advance...
    Thanks and regards,
    Tarpan Vadalia

    Hi
    While creating sale order, go to item or header billing screen, you have ALT Tax classific (at header) - select 0 to Tax exempt.
    At item level -billing - tax classification - select 0
    thank you
    Anirudh

  • I have sold some items on pre sale more than 31 days where do I find those transactions?

    You can adjust your Sold list to show up to 90 days of sales.It's a drop down menu. Since your buyers have already paid, the information should also be in Paypal - Recieved. Again you will have to adjust the calendar at the top of the listing to see more than your last ten sales.

    Sounds of custom email notifications in Mail you would like DockStar and MailActOn. These things should really spice up your email on your Mac.
    Message was edited by: satcomer

  • Is there a sale for father's day?

    Is there a sale for the ipad for father's day?

    Apple will sell the iPad for the same price as it did on Mother's Day (and yesterday, today and tomorrow).
     Cheers, Tom

  • 5 laks sales order generation per day is possible from SAP ?

    How many maximum number of invoice can SAP generation per a day (with max hardwar & no limitation in end users may with out automation). what are the alternative solutions fro SAP and is  SAP IS RETAILS can do this

    Hi Babu,
    It is possible. Please check with basis team about load and all.
    Regards,
    Madhu.

  • Sales order-future shipping day

    Hi all,
    A customer is asking not to ship something until 1/09.  We get an error message when we try to add the order, saying "Date deviates from permissible range" sales order-due date.
    Any help is appreciated.
    Thanks.
    Chloe

    All documents have 3 dates DocDate, DocDueDate, TaxDate. The date ranges for these dates are taken from the Active Posting period definition.
    Open Administration > System Initialization > General Settings > Posting Periods
    Click on the Yellow link arrow next to the current posting period and check the Due Date From and To Range and expand the To date to cover 01/31/2009
    Posting Date From
    Due Date From
    Document Date From
    Repeat this for all the Posting Periods (July 08, Aug 08, .....)
    NOTE: This is not related to Allow Future posting date....setting
    Suda

  • Sales difference day-by-day until today

    Hi
    I have a keyfigure Sales Volume  in my cube...
    I have calculated keyfigure Sales Difference which is calculated as 'Sales Volume Present Day'-'Sales Volume Previous Day'...Sales volume present day and previous day are based on kefigure 'Sales Volume' and OCALDAY with manual input variable .It shows Sales difference for chosen days.
    Now user wants a report that shows Sales difference day-by-day from beginning of year to chosen date....how can I get this?
    Any ideas..?
    Thanks alot.......

    The issue is more like this Ravikanth.
    The report should show Sales difference for every day(day-by-day) from beginning of year to date entered by user...
    Sales difference is calculated as Sales Current Day-Sales Yesterday
    so the report will be like below:
    Sales Day--Sales Today--
    Sales Difference
    03.01.2011--2million--
    100000(compared with 02.01.2011)
    04.01.2011--3 million--
    1million(compared with 03.01.2011)
    05.01.2011--4million--
    1million(compared with 04.01.2011)
    Like this,the report should show until current day chosen by user...
    how can I achieve this....
    SalesDay and Sales Today are in cube but not sales difference....How to define Sales Difference ...

  • Sales Qty and Days

    Dear Forums,
    If i want to get this report ;
    Item Code / Qty Sales (accumulate this month) / Days (how many days till this month) / Total days in this month
    eg . April 21
    542514 / 2.563 / 21 / 30
    can any one show me the query? thanks

    The "Union" is to list the all the items which has stock >0 and items not in Invoice
    SET ARITHABORT OFF SET ANSI_WARNINGS OFF
    SELECT T0.ItemCode, T0.Dscription,T1.OnHand, convert(varchar,SUM(T0.BaseQty*T1.NumInSale)) AS 'Qty Sales',DAY(GetDate()) as 'Days',
    Case WHEN Month(GetDate()) in (1,3,5,7,8,10,12) THEN 31 WHEN Month(GetDate()) in (2,4,6,9,11) THEN 30 ELSE 28 END AS 'Total days'
    ,convert (varchar,(t1.onhand/(SUM(T0.BaseQty*T1.NumInSale)/DAY(GetDate())* Case WHEN Month(GetDate()) in (1,3,5,7,8,10,12) THEN 31 WHEN Month(GetDate()) in (2,4,6,9,11) THEN 30 ELSE 28 END)))AS 'TURN OVER IN MONTH'
    FROM DBO.INV1 T0 INNER JOIN DBO.OITM T1 ON T0.ItemCode = T1.ItemCode
    WHERE Month(T0.DocDate) = Month(GetDate()) AND Year(T0.DocDate) = Year(GetDate())
    GROUP BY T0.ItemCode,T0.Dscription,T1.OnHand
    union
    SELECT T1.ItemCode, T1.itemname,T1.OnHand, '' AS 'Qty Sales',DAY(GetDate()) as 'Days',
    Case WHEN Month(GetDate()) in (1,3,5,7,8,10,12) THEN 31 WHEN Month(GetDate()) in (2,4,6,9,11) THEN 30 ELSE 28 END AS 'Total days'
    ,'No Sales' AS 'TURN OVER IN MONTH'
    FROM DBO.OITM T1
    WHERE T1.ITEMCODE NOT IN (SELECT ISNULL(ITEMCODE,0) FROM INV1)
    AND T1.ONHAND>0
    GROUP BY T1.ItemCode,T1.itemname,T1.OnHand
    ORDER BY 1
    Please let me know whether out is correct. If so i will try to include the A/R Credit Memo also

  • Calculated item divided by number of days in a month

    Hello.
    I'm trying to create a calculated item, that is supposed to represent a column member, divided by the number of days in a month that's selected from the dashboard prompt.
    I know that I need an SQL function to get the number of days, but I don't think that you can use SQL functions when creating calculated items.
    Is there a way to do this?

    Looks like you are thinking too much
    Use expression builder in the rpd and then just use available functions without 2nd thought.
    if helps mark

Maybe you are looking for