Sample Data:
Date ASIN Shipped_Revenue Shipped_COGS Shipped_Units Customer_Returns priceperunit
2023-05-31 xyx 317 290 2 0 159
2023-06-11 xx 185 145 1 0 185
2023-06-18 x 185 145 1 0 185
2023-07-05 yy 187 145 1 0 187
For the provided dataset, I need to create two new columns:
-
PI (Previous Shipped Units):
- This column should display the shipped units from the previous row. The first row will have
null
since there is no previous data.
- This column should display the shipped units from the previous row. The first row will have
-
PP (Previous Price per Unit):
- This column should display the price per unit from the previous row. The first row will have
null
as there is no previous data.
- This column should display the price per unit from the previous row. The first row will have
Output:
Date ASIN Shipped_Revenue Shipped_COGS Shipped_Units Customer_Returns priceperunit PI PP
2023-05-31 xxx 317 290 2 0 159 null null
2023-06-11 xxx 185 145 1 0 185 2 159
2023-06-18 xxx 185 145 1 0 185 1 185
2023-07-05 xxx 187 145 1 0 187 1 185
In both cases, the first row will contain null
because it lacks previous data.
Here i need the previous records values to be avalible in the current records and i dont need any aggregation .
How to acheive this ?