Example data set:
tibble::tribble(
~Item, ~Date, ~quantity,
"saw", "01/01/2020", 0L,
"saw", "02/01/2020", 10L,
"saw", "03/01/2020", 5L,
"saw", "04/01/2020", 20L,
"saw", "05/01/2020", 30L,
"saw", "06/01/2020", 0L,
"saw", "07/01/2020", 0L,
"hammer", "08/01/2020", 60L,
"hammer", "09/01/2020", 70L,
"hammer", "10/01/2020", 40L
)
I want to subtract quantity in the min date from the max date for each material and so it ignores the dates that have 0
desired result:
tibble::tribble(
~Item, ~difference,
"saw", -20L,
"hammer", 20L
)