Forum Discussion
evebarratt
4 years agoHelper I
Latest and second latest date
Hi, I need to change a query from table A to table B as below. Basically I need to get the difference between the latest and the second latest date for each product ID. Is there any way...
- 4 years ago
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDLUBUKlWB1kASMsIsYQISOIkJGuqS6agLmuOaqABboKoICBUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product ID" = _t, #"Sold Date" = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Product ID", Int64.Type}, {"Sold Date", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Product ID"}, {{"Gap between last 2 days", each Duration.Days(List.Last(_[Sold Date])-List.First(List.LastN(_[Sold Date],2))), Int64.Type}}) in #"Grouped Rows"
Vijay_A_Verma
4 years agoMost Valuable Professional
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTIyMDLUBUKlWB1kASMsIsYQISOIkJGuqS6agLmuOaqABboKoICBUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product ID" = _t, #"Sold Date" = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Product ID", Int64.Type}, {"Sold Date", type date}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"Product ID"}, {{"Gap between last 2 days", each Duration.Days(List.Last(_[Sold Date])-List.First(List.LastN(_[Sold Date],2))), Int64.Type}})
in
#"Grouped Rows"evebarratt
4 years agoHelper I
It works great! Thank you.