Forum Discussion
DAX help: most recent event
- 2 years ago
Hi,
This M code works
let Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content], #"Grouped Rows" = Table.Group(Source, {"Customer Confirmation Number", "Delivery Confirmation Number"}, {{"Count", each Table.Max(_,{"Last Event Date","Last Event Time"})}}), #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"Manifest Date", "Receive Date", "Last Event Date", "Last Event Time", "Last Event Description"}, {"Manifest Date", "Receive Date", "Last Event Date", "Last Event Time", "Last Event Description"}), #"Changed Type" = Table.TransformColumnTypes(#"Expanded Count",{{"Last Event Date", type date}, {"Last Event Time", type time}}) in #"Changed Type"Hope this helps.
Hi,
Share data in a format that can be pasted in an MS Excel file. Show the expected result as well.
| Customer Confirmation Number | Delivery Confirmation Number | Manifest Date | Receive Date | Last Event Date | Last Event Time | Last Event Description |
| '78510745 | '9274890326139904723314 | 1/25/2024 5:07 | 1/22/2024 19:02 | 1/26/2024 | 6:10:00 AM | OUT FOR DELIVERY |
| '78542345 | '9274890326139904739452 | 1/25/2024 5:07 | 1/23/2024 18:58 | 1/26/2024 | 6:21:00 AM | OUT FOR DELIVERY |
| '78510884 | '9274890326139904736161 | 1/25/2024 5:07 | 1/23/2024 18:58 | 1/26/2024 | 6:55:00 AM | OUT FOR DELIVERY |
| '78541001 | '9261290326139904737940 | 1/25/2024 1:08 | 1/23/2024 18:59 | 1/26/2024 | 6:10:00 AM | OUT FOR DELIVERY |
| '78510745 | '9274890326139904723314 | 1/25/2024 5:07 | 1/22/2024 19:02 | 1/26/2024 | 6:10:00 AM | DELIVERED |
| '78542345 | '9274890326139904739452 | 1/25/2024 5:07 | 1/23/2024 18:58 | 1/26/2024 | 6:21:00 AM | DELIVERED |
| '78510884 | '9274890326139904736161 | 1/25/2024 5:07 | 1/23/2024 18:58 | 1/26/2024 | 6:55:00 AM | DELIVERED |
| '78541001 | '9261290326139904737940 | 1/25/2024 1:08 | 1/23/2024 18:59 | 1/26/2024 | 6:10:00 AM | DELIVERED |
- Ashish_Mathur2 years ago
Super User
Hi,
Based on the Table that you have shared, please also show the expected result.
- MJAGUSIAK2 years ago
Helper I
The expected result is the following and it should not show back the other rows:
'78541001 '9261290326139904737940 1/25/2024 1:08 1/23/2024 18:59 1/26/2024 6:10:00 AM DELIVERED '78541001 '9261290326139904737940 1/25/2024 1:08 1/23/2024 18:59 1/26/2024 6:10:00 AM DELIVERED - Ashish_Mathur2 years ago
Super User
Hi,
"Last Event Description" is a column with text entries. So what do you mean by "Find the last status update"? [from your first post]
- MJAGUSIAK2 years ago
Helper I
It should pull back the data where it is showing only a unique value for Delivery Confirmation Number with the most recent "Last date and time" showing the "last Event Description"
Customer Confirmation Number Delivery Confirmation Number Manifest Date Receive Date Last Event Date Last Event Time Last Event Description '78510745 '9274890326139904723314 1/25/2024 5:07 1/22/2024 19:02 1/26/2024 6:10:00 AM DELIVERED '78542345 '9274890326139904739452 1/25/2024 5:07 1/23/2024 18:58 1/26/2024 6:21:00 AM DELIVERED '78510884 '9274890326139904736161 1/25/2024 5:07 1/23/2024 18:58 1/26/2024 6:55:00 AM DELIVERED '78541001 '9261290326139904737940 1/25/2024 1:08 1/23/2024 18:59 1/26/2024 6:10:00 AM DELIVERED - Ashish_Mathur2 years ago
Super User
9274890326139904723314 has 2 entries and both have the same end date and time. Why shoud the delivered row show up in the result.
- MJAGUSIAK2 years ago
Helper I
Sorry, didnt catch that when I created the sample data. please use below.
Customer Confirmation Number Delivery Confirmation Number Manifest Date Receive Date Last Event Date Last Event Time Last Event Description '78510745 '9274890326139904723314 1/25/2024 5:07 1/22/2024 19:02 1/25/2024 6:10:00 AM OUT FOR DELIVERY '78542345 '9274890326139904739452 1/25/2024 5:07 1/23/2024 18:58 1/25/2024 6:21:00 AM OUT FOR DELIVERY '78510884 '9274890326139904736161 1/25/2024 5:07 1/23/2024 18:58 1/25/2024 6:55:00 AM OUT FOR DELIVERY '78541001 '9261290326139904737940 1/25/2024 1:08 1/23/2024 18:59 1/25/2024 6:10:00 AM OUT FOR DELIVERY '78510745 '9274890326139904723314 1/25/2024 5:07 1/22/2024 19:02 1/26/2024 6:10:00 AM DELIVERED '78542345 '9274890326139904739452 1/25/2024 5:07 1/23/2024 18:58 1/26/2024 6:21:00 AM DELIVERED '78510884 '9274890326139904736161 1/25/2024 5:07 1/23/2024 18:58 1/26/2024 6:55:00 AM DELIVERED '78541001 '9261290326139904737940 1/25/2024 1:08 1/23/2024 18:59 1/26/2024 6:10:00 AM DELIVERED - Ashish_Mathur2 years ago
Super User
Hi,
This M code works
let Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content], #"Grouped Rows" = Table.Group(Source, {"Customer Confirmation Number", "Delivery Confirmation Number"}, {{"Count", each Table.Max(_,{"Last Event Date","Last Event Time"})}}), #"Expanded Count" = Table.ExpandRecordColumn(#"Grouped Rows", "Count", {"Manifest Date", "Receive Date", "Last Event Date", "Last Event Time", "Last Event Description"}, {"Manifest Date", "Receive Date", "Last Event Date", "Last Event Time", "Last Event Description"}), #"Changed Type" = Table.TransformColumnTypes(#"Expanded Count",{{"Last Event Date", type date}, {"Last Event Time", type time}}) in #"Changed Type"Hope this helps.