简体   繁体   中英

Weekly Sales Total in Fact Table using SSIS

I have 3 sales data tables that I have converted into 4 Dimension tables and 1 Fact table.

I have everything populated properly, and am wanting a "daily-sales" and "weekly-sales" in my Fact table.

My original 3 tables are as follows is as follows:

  • Order (order# (PK), product-id (FK), order-date, total-order, customer# (FK))
    domains are numeric, numeric, Date, Currency,numeric

  • Product (product-id (PK), prod-name, unit-cost, manufacture-name)
    domains are numeric, nvarchar, money, nvarchar.

  • Customer (customer# (PK), cust-name, address, telephone#)
    domains are Number, nvarchar, nvarchar, nvarchar

The Star Schema of the data warehouse is linked here:

在此输入图像描述

So I have only 10 records in each table(tiny!), and am just testing concept now. "daily-order" in the Fact table is easily translated from "total-order" in the Order table. My difficulty is getting the weekly totals. I used a derived column and expression "DATEPART("wk",[order-date])" to create my week column in the time dimension.

So I guess my question is, how do I get the weekly-sales from this point? My first guess is to use another derived column after the end of my Lookup sequences used to load my Fact table. My second guess is..... ask for help on stackoverflow. Any help would be appreciated, I will supply any info needed! Thanks in advance!

For the record I tried creating the derived column as I previously described, but could not figure out syntax that would be accepted....

EDIT I want to list the weekly-sales column by product level, and as I used DATEPART to derive the week column I do not need last 7 days but rather just a total for each week. My sales data stretches across only 2 consecutive weeks, so my fact table should list 1 total 7 times and a second total 3 times. I can either derive this from the original Order table, or from the tables I have in my DW environment. Preferably the latter. One note is that I am mainly restricted to SSIS and its tools (There is "Execute SQL syntax" tool, so I can still use a query)

Within your data flow for Fact-sales , it would challenging to fill the weekly-order amount as you are loading daily data. You would need to use a Multicast Transformation, add an Aggregate to that to sum your value for the product, customer, order and week. That's easy. The problem is how are you going to tie that data back to the actual detail level information in the data flow. It can be done, Merge Join, but don't.

As ElectricLlama is pointing out in the comments, what you are about to do is mix your level of granularity. If the weekly amount wasn't stored on the table, then you can add all the amounts, sliced by whatever dimensions you want. Once you put that weekly level data at the same level, your users will only be able to summarize the daily columns. The weekly values would not be additive, probably.

I say probably because you could fake it by accumulating the weekly values but only storing on them on an arbitrary record: the first day of the week, third, last, whatever. That solves the additive problem but now users have to remember which day of the week is holds the summarized value for the week. Plus, you'd be generating a fake order record for that summary row unless they placed the order on the exact day of the week you picked to solve the additive value problem.

The right, unasked for, solution is to remove the weekly-order from the fact table and beef up your data dimension to allow people to determine the weekly amounts. If you aren't bringing the data out of the warehouse and into an analytics engine, you could precompute the weekly aggregates and materialize them to a reporting table/view.

Source data

Let's look at a simple scenario. A customer places 3 orders, two on the same day for same product (maybe one was expedited shipping, other standard)

SalesDate |Customer|Product|Order|Amount
2013-01-01|1       |20     |77   |30
2013-01-01|1       |30     |77   |10
2013-01-02|1       |20     |88   |1
2013-01-02|1       |20     |99   |19

Fact table

Your user is going to point their tool of choice at the table and you'll be getting a call because the numbers aren't right. Or you'll get a call later because they restocked with 150 units of product 20 when they only needed to reorder 50. I wouldn't want to field either of those calls.

SalesDate |Customer|Product|Order|daily-order|weekly-order
2013-01-01|1       |20     |77   |30         |50
2013-01-01|1       |30     |77   |10         |10
2013-01-02|1       |20     |88   |1          |50
2013-01-02|1       |20     |99   |19         |50

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM