initial work on parameterizing baselining process
This commit is contained in:
parent
6d2cacb726
commit
975ea43b65
@ -1,3 +1,4 @@
|
|||||||
|
--a baseline period will have to be identified
|
||||||
WITH
|
WITH
|
||||||
baseline AS (
|
baseline AS (
|
||||||
-----------------------copy YTD sales---------------------------------------------------------------------
|
-----------------------copy YTD sales---------------------------------------------------------------------
|
||||||
@ -15,15 +16,13 @@ baseline AS (
|
|||||||
WHERE
|
WHERE
|
||||||
(
|
(
|
||||||
--base period orders booked....
|
--base period orders booked....
|
||||||
o.odate BETWEEN '2019-06-01' AND '2020-02-29'
|
[target_odate] BETWEEN [target_odate_from] AND [target_odate_to]
|
||||||
--...or any open orders currently booked before cutoff....
|
--...or any open orders currently booked before cutoff....
|
||||||
OR (o.calc_status IN ('OPEN','BACKORDER') and o.odate < '2020-03-01')
|
OR ([status_flag] IN ([status_list]) and [target_date] <= [target_date_from])
|
||||||
--...or anything that shipped in that period
|
--...or anything that shipped in that period
|
||||||
OR o.fspr BETWEEN '2001' AND '2009'
|
OR ([target_sdate] BETWEEN [target_sdate_from] AND [target_sdate_to])
|
||||||
)
|
)
|
||||||
AND fs_line = '41010'
|
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
||||||
AND calc_status <> 'CANCELED'
|
|
||||||
AND NOT (calc_status = 'CLOSED' AND flag = 'REMAINDER')
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
---------option 1: fill in the rest of the year, with the prior years sales-sales----------------------------
|
---------option 1: fill in the rest of the year, with the prior years sales-sales----------------------------
|
||||||
SELECT
|
SELECT
|
||||||
@ -36,11 +35,8 @@ baseline AS (
|
|||||||
LEFT OUTER JOIN gld ss ON
|
LEFT OUTER JOIN gld ss ON
|
||||||
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
|
greatest(least(o.sdate,gld.edat),gld.sdat) + interval '1 year' BETWEEN ss.sdat AND ss.edat
|
||||||
WHERE
|
WHERE
|
||||||
o.odate BETWEEN '2019-03-01' AND '2019-05-31'
|
[target_odate] BETWEEN [target_odate_plug_from] AND [target_odate_plug_to]
|
||||||
AND fs_line = '41010'
|
--be sure to pre-exclude unwanted items, like canceled orders, non-gross sales, and short-ships
|
||||||
AND calc_status <> 'CANCELED'
|
|
||||||
------exclude actuals for now and use forecast to get the plug for the rest of the year
|
|
||||||
AND false
|
|
||||||
UNION ALL
|
UNION ALL
|
||||||
--------option 2: fill in the remainder of the current year with current forecase-----------------------------
|
--------option 2: fill in the remainder of the current year with current forecase-----------------------------
|
||||||
SELECT
|
SELECT
|
||||||
@ -53,9 +49,8 @@ baseline AS (
|
|||||||
LEFT OUTER JOIN gld ss ON
|
LEFT OUTER JOIN gld ss ON
|
||||||
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
greatest(least(o.sdate,gld.edat),gld.sdat) BETWEEN ss.sdat AND ss.edat
|
||||||
WHERE
|
WHERE
|
||||||
o.odate BETWEEN '2020-03-01' AND '2020-05-31'
|
[target_odate] BETWEEN [target_odate_plug_from] AND [target_odate_plug_to]
|
||||||
AND fs_line = '41010'
|
AND false
|
||||||
AND calc_status <> 'CANCELED'
|
|
||||||
)
|
)
|
||||||
-------------------copy the baseline just generated and increment all the dates by one year------------------------------------
|
-------------------copy the baseline just generated and increment all the dates by one year------------------------------------
|
||||||
,incr AS (
|
,incr AS (
|
||||||
|
Loading…
Reference in New Issue
Block a user