Forum Discussion
Filter column for unique values and another column in Power Query
- 3 years ago
Hello Irwin !
You can sort in ascending order column B and then remove duplicates on column A. - 3 years ago
Hi,
It did not work. It seems this solution works in excel. However, PBI remembers the original sort and therefore cannot keep the value I want i column B once I remove duplicates.
I found a solution that work when applied to your suggestion. You need to use the table function called "Table.Buffer".https://learn.microsoft.com/en-us/powerquery-m/table-buffer
A video can be seen here.
https://www.youtube.com/watch?v=rqDdnNxSgHQ&list=PLDz00l_jz6zzttb28XH8GHZNL6vvpBlkQ&index=23
Hi Irwin ,
Plaese refer to my steps:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUYpSitVBZ0VgESOGZYSDFYgmZkwyy4QgKxBZLBYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"A", "B"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each List.Min(Table.SelectRows(#"Grouped Rows",(x)=>x[A]=[A])[Count])),
#"Added Conditional Column" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Count] = [Custom] then [B] else null),
#"Filtered Rows" = Table.SelectRows(#"Added Conditional Column", each ([Custom.1] <> null)),
#"Reordered Columns" = Table.ReorderColumns(#"Filtered Rows",{"A", "B", "Custom.1", "Count", "Custom"}),
#"Removed Columns" = Table.RemoveColumns(#"Reordered Columns",{"Custom.1", "Count", "Custom"})
in
#"Removed Columns"
If it still does not help, please provide more details with your desired output.
Best Regards
Community Support Team _ Polly
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
Thank you for your kind help. This might be a solution, but I think it is not feasible to do on a data source with millions of rows.