This is for a Power Query:
I am working on a report that compiles information from different dates and I need a column that generates the most recent date in the list and the previous date to the most current one in separate columns:
Most Current Date must be the same for the whole column (same for Previous Date Column)
Table Name : Skipped_Issue
Worker |Case |Report_Date |MOST_CURRENT_DATE |PREVIOUS_DATE
Tran |3000 |1/2018
Dhni |52451 |4/2018
Dhtuni |39656 |2/2018
For the most recent date, you can create a custom column with this formula:
= Date.From(List.Max(NameOfPreviousStep[Report_Date]))
Where NameOfPreviousStep
references the prior step in your query (e.g. #"Changed Type"
or Source
).
To get the second to last date, you can create a custom column that evaluates the max after removing the MOST_CURRENT_DATE
= Date.From(
List.Max(
List.RemoveItems(#"Added Custom"[Report_Date],
#"Added Custom"[MOST_CURRENT_DATE])))
Here's the whole query for the sample data:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCilKzFPSUTI2MDAAUob6hvpGBoYWSrE60UouGXmZQDFTIxNTQyBtgipXUgqWNbY0MzUD0kZw2VgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Worker = _t, Case = _t, Report_Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Worker", type text}, {"Case", Int64.Type}, {"Report_Date", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "MOST_CURRENT_DATE", each Date.From(List.Max(Source[Report_Date])), type date),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "PREVIOUS_DATE", each Date.From(List.Max(List.RemoveItems(#"Added Custom"[Report_Date], #"Added Custom"[MOST_CURRENT_DATE]))), type date)
in
#"Added Custom1"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With