I have the following data table:
month marketid totalsold totalshipped lefttoship_thismonth
....
01-01-2015 1 100 50 50
01-01-2015 2 10 3 7
01-01-2015 3 0 0 0
01-02-2015 1 0 50 -50
01-02-2015 2 20 0 20
01-02-2015 3 0 0 0
Basically this table shows information about orders and shipments per market per month.
The date 01-01-2015
in month
column actually represents Jan 2015
(the whole month).
I want to SUM
the lefttoship_thismonth
per market for each month with all previous months. This is needed as someone can place order in January which was supplied in February. So I want to know how many items I still need to ship per month.
The output should be:
month marketid totalsold totalshipped totallefttoship TOTALLEFT
01-01-2015 1 100 50 50 50
01-01-2015 2 10 3 7 7
01-01-2015 3 0 0 0 0
01-02-2015 1 0 50 -50 0 /50-50
01-02-2015 2 20 0 20 27 /7+20
01-02-2015 3 0 0 0 0 / 0+0
How can I do that?
I have no idea how to sum this way and the month
column is very hard to work with.