on 08-10-2015 1:29 PM
Hello everybody!
I have two identical tables, one contains the stock from day - 2, the other contains the stock from day - 1.
*Day
*Stock
*Store
Quantity
I need to create a calculation view comparing the content of these two tables, and taking only the records from table "Day - 1" which are different from table "Day - 2".
What is the best way to do this using Calculation?
Thank you in advance!
Cris.
Hi,
Could you please tell the Table Definition and Sample data?
Thanks,
Pragati
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The tables are as follows, the key fields contain the * symbol:
*Day
*Store
*Product
Quantity
Table D - 2
Day Store Product Quantity
08/08/2015 StoreA MatA 10
08/08/2015 StoreA MatB 10
08/08/2015 StoreB MatA 10
08/08/2015 StoreB MatB 5
Table D-1
Day Store Product Quantity
09/08/2015 StoreA MatA 20
09/08/2015 StoreA MatB 10
09/08/2015 StoreB MatA 10
09/08/2015 StoreB MatC 5
Result should be:
Store Product Quantity
StoreA MatA 20
StoreB MatC 5
StoreB MatB 0
Thanks!
Ok, this is a typical stock reporting requirement.
But it seems that the requirement is not complete.
What do you do when there is no stock entry for a specific product-location-combination for a specific date? I would assume you would like to have the "latest"/"most current" value then.
Or maybe, you'd say, if there wasn't an entry in there for more than x days, there must be something wrong and I need to mark this.
Also: why are the two views on the stock data separate? Isn't your stock kept in a single table?
In fact, this is not "that" typical.. It´s a special requirement, not an usual stock report.
There will be an initial load, with all stores and products. After that, I just need to send what has changed, it doesn't matter why it has changed. And I need to send the total in stock of what has changed,
That´s why I have two tables. This table contains 16 Million records for one day. I can't keep the history because of it's size. So the solution was to always keep D - 2 and D -1 , in order to compare what has changed between these two tables, and provide these changes in a third view.
So, if I understand correctly, then D-1 contains only yesterdays data and D-2 the data from the day before yesterday.
If that's true, one simple and efficient approach would be to perform a UNION of both tables, mapping the quantity information to a separate column each (with a constant 0 in the "missing" component).
Once this is done, an aggregation melts the records together and a calculated column can deliver the difference/delta value.
Let me know how you go with that.
In that case, don't compute the difference 🙂
To be honest, I only now understand that you want to filter out the records where no change happened and keep only those where there is a difference... *slow-thinking-today*...
I see the following approaches here:
In fact I would probably do the whole thing in a plain SQL view anyhow - much less overhead from a design perspective and very expressive for this requirement.
So, my recommendation would be to do version 1.
- Lars
This would be an example code for this problem (on anyDB, but works in HANA the same way):
Note that the requirement to print out
StoreB MatB 0
is not fulfilled with that.
And to be honest, I don't really see the reasoning behind that,
StoreB/MatB did't change. It simply doesn't occur in D-1...
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.