Forum Discussion
Create a filtred table based on an agregation function
- 5 years ago
Hi,
This M code works
let Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"AlertID", Int64.Type}, {"status", type text}, {"Date", type date}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"AlertID"}, {{"Max", each List.Max([Date]), type nullable date}, {"All", each _, type table [AlertID=nullable number, status=nullable text, Date=nullable date]}}), #"Expanded All" = Table.ExpandTableColumn(#"Grouped Rows", "All", {"status", "Date"}, {"status", "Date"}), #"Added Custom" = Table.AddColumn(#"Expanded All", "Custom", each [Max]=[Date]), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = true)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Max", "Custom"}), #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"AlertID", Order.Ascending}}) in #"Sorted Rows"Hope this helps.
wahib_mouhoubi , Try like
new table = CALCULATETABLE (alerts;filter (all(alerts); [AlertID] =max([AlertID]) && [date] = LASTDATE([date]) ) )
new table = CALCULATETABLE (alerts;filter (all(alerts); [AlertID] =max([AlertID]) && [date] = calculate(LASTDATE([date]),allexcept(Table,Table[Date])) ) )
amitchandak Hello, thank you for replying.
when i tried your solutions, on the reduced dataset i wrote above i got this table :
AlertID | status | Date
3 |To analyse | 03/02/2021
3 |Closed | 05/02/2021
and that's not what i want.
Also, i tried it on my real dataset (with a huge amount of data and some additional columns that i considered useless for the treatment i want to make) i got an error :
"A date column containing duplicate dates was specified in the call to function "LASTDATE". This is not supported".
Maybe some alert arrived and was treated the same day, might be possible.
Any idea on how to fix that please?
Thank you.