Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hey all,
I have a table that looks as follows:
I want to remove the duplcate ID's but only based on the condition that it removes the old records of the survey. For example, ID 123 has been recorded twice - 7/15/2019 and 8/15/2019. I want to remove the record 7/15/2019 and only retain the latest survey details. My output should look as follows:
https://community.powerbi.com/t5/Desktop/Remove-duplicate-with-date-condition/m-p/702377#M339051
I followed the above thread for guidance, but I get an error:
What is the best way to do this? Thanks!
Solved! Go to Solution.
Hi @Anonymous ,
You just need to change your edit query somethign like this:
1. Add comma
2. And than add the code you refered in the post.
3. then remove duplicatas on the ID . You will get the results you are looking for.
My output:
Thanks,
Tejaswi
Hi @Anonymous ,
You just need to change your edit query somethign like this:
1. Add comma
2. And than add the code you refered in the post.
3. then remove duplicatas on the ID . You will get the results you are looking for.
My output:
Thanks,
Tejaswi
@Anonymous Thank u!
You can try this in Power Query:
1). Sort your data by ID (ascending or descending, doesnt matter)
2) Sort your Date Completed Descending (that does matter!)
3) GroupBy ID and Under "Operation" select All Rows
4) Need to add "GroupKind.Local" at the end of the formula that was automatically generated when you did #3
original:
= Table.Group(#"Sorted Rows", {"ID"}, {{"allrows", each _, type table [ID=number, Name=text, Date Completed=date, Q1=text, Q2=text]}})
modified:
= Table.Group(#"Sorted Rows", {"ID"}, {{"AllRows", each _, type table [ID=number, Name=text, Date Completed=date, Q1=text, Q2=text]}},GroupKind.Local)
5) Add a custom column with:
Table.FirstN([AllRows],1)
6) Remove all the other columns except for what was created in #5
7) Expand that column and Set data types
Final Table:
Full M Code (many of these steps could be combined, but that makes it harder to follow)
let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content], #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}, {"Name", type text}, {"Date Completed", type date}, {"Q1", type text}, {"Q2", type text}}), #"Sorted Rows" = Table.Sort(#"Changed Type",{ {"ID", Order.Ascending},{"Date Completed", Order.Descending}}), #"Grouped Rows" = Table.Group(#"Sorted Rows", {"ID"}, {{"AllRows", each _, type table [ID=number, Name=text, Date Completed=date, Q1=text, Q2=text]}},GroupKind.Local), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.FirstN([AllRows],1)), #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"ID", "Name", "Date Completed", "Q1", "Q2"}, {"ID", "Name", "Date Completed", "Q1", "Q2"}), #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom",{{"ID", Int64.Type}, {"Name", type text}, {"Date Completed", type date}, {"Q1", type text}, {"Q2", type text}}) in #"Changed Type1"
-Nick
@Anonymous Thank you!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
105 | |
105 | |
88 | |
73 | |
66 |
User | Count |
---|---|
124 | |
113 | |
98 | |
81 | |
72 |