Forum Discussion
A-kitaev
9 years agoNew Member
Remove duplicates - keep last vs keep first
Hi, I need to remove rows in a table that have duplicate values and I need to keep last one. Power BI by default keeps first one regardless of sorting order. I tried to use buffered table in advan...
- 9 years ago
In this scenario, if you want to keep the last records associated with each group column. You can build a calculated table aggregating values with max sort within each group.
I assume you a have a table like below:
Then you can create a calculated table like below:
Table = SUMMARIZE( Table3,Table3[Name], "Last Value", CALCULATE(SUM(Table3[Value]), FILTER(Table3,Table3[Sort]=MAX(Table3[Sort])) ) )
Regards,
Ashish_Mathur
5 years agoSuper User
Hi,
Does this M Query work faster? If not, then let me know. I will share a calculated column formula in DAX with you.
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"OrderNumber", Int64.Type}, {"RunDate", type date}}),
#"Sorted Rows" = Table.Sort(#"Changed Type",{{"OrderNumber", Order.Ascending}, {"RunDate", Order.Ascending}}),
Partition = Table.Group(#"Sorted Rows", {"OrderNumber"}, {{"Partition", each Table.AddIndexColumn(_, "Index",1,1), type table}}),
#"Expanded Partition" = Table.ExpandTableColumn(Partition, "Partition", {"RunDate", "Index"}, {"RunDate", "Index"})
in
#"Expanded Partition"
hmenco
5 years agoFrequent Visitor
Trying to figure out things.. What if there are other columns to be displayed? The M query worked as well.. But maybe i'll use it on the smaller data.
How can we display other columns that were hidden in the Partition?