dimanche 15 novembre 2015

MSSQL: Given Start and End Date calculate number of items and billed weeks

I have the following table, where I have aggregated the OrderNumber, Vendor, Item Description, Rate, Discount, Start and End Date. My end result needs to be one line item per Vendor PO with the Billed Weeks, Current Billed to Date and Forecast cost. I have been struggling with this for a while and cannot seem to find a way to do this.

Here is what the table currently looks like:

vendor         OrderNo      OrderDate     Item      Description       Count    rate     unitdiscnt  dayinweek   startDate     EndDate      Billed Weeks
JO SERVICES    N2764       2015-04-29     5000      BASEPLATE          4       1.250      0.00       0.900      2015-04-29    2015-06-10        7
JO SERVICES    N2764       2015-04-29     4100      PIGTAIL           24       0.250      0.00       0.900      2015-04-29    2015-06-10        7
JO SERVICES    N2764       2015-04-29     4100      PIGTAIL            4       0.250      0.00       0.900      2015-05-06    2015-06-10        6
TIM JOEANNE    N2760       2015-04-29     4290      STEEL CASTOR       8       6.000      0.00       0.900      2015-04-29    2015-06-10        7

In this case the two records of PigTail Should be a single line item, the Start and End Date does not have to appear in the table but the count with be 24+4, and the Actual Billed to Date will be From the Start Date until today's date (calculated in Billing Weeks * Count * rate - Discount amount). The forecast Date would be anything after today's date billed until the end date.

As an aside, I also need to create a graph that will give me the overall cost month by month From the beginning of the year until the end of the year.

How would I go about doing these both. I have been struggling with this for a couple of days and any direction would be extremely helpful and appreciated.

Aucun commentaire:

Enregistrer un commentaire