I have a data frame as below
cust start-dt end-dt item item_type sales cost trans-dat
A 07-01-2019 07-01-2020 AA xxxxxxxxx 1500 1400 08-01-2019
A 07-01-2019 07-01-2020 AA xxxxxxxxx 2000 1600 09-01-2019
A 07-01-2019 07-01-2020 AA xxxxxxxxx 2500 1000 07-12-2019
A 07-01-2019 07-01-2020 AA xxxxxxxxx 1600 1300 05-01-2020
A 07-01-2019 07-01-2020 AA xxxxxxxxx 2400 1700 02-01-2020
A 07-01-2019 07-01-2020 AA xxxxxxxxx 2200 1300 04-01-2020
I need to convert to year wise data as below. based on the customer and the item they bought across every year
cust start-dt end-dt item item_type year sales cost
A 07-01-2019 07-01-2020 AA xxxxxxxxx 2019 6000 4000
A 07-01-2019 07-01-2020 AA xxxxxxxxx 2020 6200 4300
i tried melt and cast but melt doesnt create new columns/rows.
this data is only an example. I have multiple customers and multiple items for every customer and the start and end also differs for every cust.
Please guide me on how to approach the issue.