date difference in one column based on second column value Power Query

Viewed 26

I need to find the number of days between maximum and minimum date based on whenever there is a value in Tonnage.For example for the name K701 I need to find out number of days from 12/09/2022 till 30/09/2022 with the condition that tonnage is more than 0

1 Answers

In powerquery, filter tonnage, group on name, subtract the min from max date

let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Filtered Rows" = Table.SelectRows(Source, each ([Tonage] <> 0)),
#"Grouped Rows" = Table.Group(#"Filtered Rows", {"Name"}, {{"days", each Number.From(List.Max(_[Shift.2]))-Number.From(List.Min(_[Shift.2]) ) }})
in #"Grouped Rows"
Related