Forum Discussion
YigitOz
4 years agoNew Member
Remove Duplicate by comparing dates
Dear Community, I have a some data and I'm updating every month and comparing those data. But I have a problem because of Duplicate. I have created an example table myself below. My goal is to...
- 4 years ago
See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test (later on when you use the query on your dataset, you will have to change the source appropriately)
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtY31DcyMDJS0lFyBGL31KLcxLxKpVgdFCknIHbNS89JzEuBShnjljKBSTljGGgKk3IB4uCCxMw8sIQRbkfglTLC5Qgj3I4wwuUIQxw2xQIA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Group = _t, Country = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Group", type text}, {"Country", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "CurrentPreviousMonth", each [Date]>=Date.AddMonths(Date.StartOfMonth(Date.From(DateTime.FixedLocalNow())),-2) and [Date]<=Date.AddMonths(Date.EndOfMonth(Date.From(DateTime.FixedLocalNow())),-1)), #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([CurrentPreviousMonth] = true)), #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"CurrentPreviousMonth"}), #"Added Custom1" = Table.AddColumn(#"Removed Columns", "Month", each Date.Month([Date])), #"Grouped Rows" = Table.Group(#"Added Custom1", {"Month"}, {{"Temp", each _, type table [Date=nullable date, Group=nullable text, Country=nullable text, Month=number]}}), #"Added Custom2" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.Distinct([Temp], {"Group", "Country"})), #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom2", "Custom", {"Date", "Group", "Country"}, {"Date", "Group", "Country"}), #"Removed Columns1" = Table.RemoveColumns(#"Expanded Custom",{"Month", "Temp"}) in #"Removed Columns1"
YigitOz
4 years agoNew Member
Thank you for your help.
I need to work on this code. It is a bit complicated.