Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Anonymous
Not applicable

Remove Duplicates - filter/unfilter - before pivot

I have looked everywhere and cannot find an answer to this.  Please Help!

We track proposals through an approval process, but sometimes a proposal gets double approved and I need to only take the latest approval for that status.

When I was in excel, I would just filter on the status, sort by date, and then remove duplicates. I could then UNfilter the table and move on with the pivot.  The pivot cannot have more than one date per status per proposal.

In Power BI Query Editor, I can't UNfilter after I remove the duplicates, so I'm stuck on how to get these outliers removed.

Below is a sample of my data. The red row is the only row in this example set that needs to be removed.

 

 

_idstatusHistory.createdAtstatusHistory.statusproposals.title
5dc33a363bafff4770b0458f10/2/2019 4:00:00 AMIT/OT TeamOperating Budget Request Application
5dc33a363bafff4770b0458f2020-01-10T15:02:13.3660000Executive ApprovalOperating Budget Request Application
5dc33a363bafff4770b0458f2021-01-28T19:28:42.0190000ApprovedOperating Budget Request Application
5dc33a363bafff4770b0458f4/3/2019 7:58:00 PMSavedOperating Budget Request Application
5dc33a363bafff4770b0458f7/10/2019 4:00:00 AMBusiness CaseOperating Budget Request Application
5dc33a363bafff4770b0448a2020-06-09T13:55:27.9050000Sponsor ApprovalOutdoor Advertising System
5dc33a363bafff4770b0448a2020-06-09T13:59:51.3850000Joint Directors ApprovalOutdoor Advertising System
5dc33a363bafff4770b0448a2020-06-09T14:00:08.7670000Business CaseOutdoor Advertising System
5dc33a363bafff4770b0448a2020-06-09T14:04:01.0320000IT/OT TeamOutdoor Advertising System
5dc33a363bafff4770b0448a2020-06-09T14:04:40.7330000Executive ApprovalOutdoor Advertising System
5dc33a363bafff4770b0448a2020-06-09T14:04:56.7810000Quarterly Release Cycle (QRC) ApprovalOutdoor Advertising System
5dc33a363bafff4770b0448a2020-06-09T14:09:01.4600000ApprovedOutdoor Advertising System
5dc33a363bafff4770b0448a2020-06-09T13:59:08.7900000Functional Coordinator ApprovalOutdoor Advertising System
5dc33a363bafff4770b0448a9/14/2018 12:08:00 PMSavedOutdoor Advertising System
5dc33a363bafff4770b045b82020-01-28T18:53:52.3750000Quarterly Release Cycle (QRC) ApprovalPAS GIS Routing Update
5dc33a363bafff4770b045b82020-02-03T17:43:59.9180000ApprovedPAS GIS Routing Update
5dc33a363bafff4770b045b85/10/2019 11:15:00 PMSavedPAS GIS Routing Update
5f98702779817e002858834d2020-11-17T21:33:59.7790000Functional Coordinator ApprovalOne Stop Permitting (OSP) Enhancements  
5f98702779817e002858834d2021-01-07T16:10:10.8000000Functional Coordinator ApprovalOne Stop Permitting (OSP) Enhancements  
5f98702779817e002858834d2020-10-27T19:08:23.6150000SavedOne Stop Permitting (OSP) Enhancements  
5f98702779817e002858834d2020-12-16T11:48:46.6690000Sponsor ApprovalOne Stop Permitting (OSP) Enhancements  
5f98702779817e002858834d2021-01-20T10:44:26.5310000Joint Directors ApprovalOne Stop Permitting (OSP) Enhancements  
5f98702779817e002858834d2021-02-17T17:57:14.6710000Business CaseOne Stop Permitting (OSP) Enhancements  
1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi @Anonymous ,

you have to tackle this a bit differntly in Power Query:

1) sort on StatusHistory descending and buffer the result

2) check the other columns and remove duplicates

 

If you paste this code into the advanced editor you should be able to follow the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xZbbTttAEIZfZZUrkMhmZs/eO0hpRaWKELtXiAtjb6ilxE7tNSpvw7PwZF2bBHFQo0BdVfKN19J8s//8M+PLy5HMM85Trvh1ulgshNZwDUKaxehohDABNmGAEQFhAcLRWTI5T0ji0lV4OV+7OvVFeUNO2vzGeTJ3P1vXeHK8Xi+LLHyqytHV0U4GAwZjwDFCgtICs8gpVwqgx53+clnri1vXhayr23Q5HBY7LDMJRpYZKxgN99xgH2EuHwgGYgL8UccAkyYcxemA4fUkVOpFmU7apihd05Bp2ri/xgiTPlVKjSFKkFspLdM0ArmRLF5XZVPVL+rU+rzqjvJbV/ui6fDxXePd6p2ooBlSbraor1VRevKpqF3mq7oZHtmJaMFQrfQG+UbPoTjhQQqcbTgv22s4iACqOd/ZVMPBpKLa4AZ20aa1d/XyLlhu6YJ6ZHqXLR05uJhPD/9JAlEnqegnyOteHs6QnTuiLeJzW2ZdB6VLMg3x86JM/VCtEE1QdL1tCLJADc4ks2/PB8gHIstr82zydiPQWBmuxSjX8r11mx3H5MtZTOZV2w+Y7+s89W4/OBsDT1Bb0WlKIzRva/ax8CCfRiLjFuUzwXYFXERGA9M6MqgdADPSGC7ybb4Y1pROGFre56t1tL8BSkdiX63JzNWrwvfkg/N4dkhOyx9pmbmVK33zcP9wv0cm/eYCnaCyCOGhvW7/I5OgCYyZ7nZo8CbjVOHTQtgadGAeG6NKEK0IO1tRpaIdC2hw0Vn4SwErhGWKSo57LKSBU2CdA0PHSG1RUKXxTwvqHdyr3w==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [_id = _t, statusHistory.createdAt = _t, statusHistory.status = _t, proposals.title = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"_id", type text}, {"statusHistory.createdAt", type text}, {"statusHistory.status", type text}, {"proposals.title", type text}}),
    #"Sorted Rows" = Table.Buffer( Table.Sort(#"Changed Type",{{"statusHistory.createdAt", Order.Descending}}) ),
    #"Removed Duplicates" = Table.Distinct(#"Sorted Rows", {"_id", "statusHistory.status", "proposals.title"})
in
    #"Removed Duplicates"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

1 REPLY 1
ImkeF
Super User
Super User

Hi @Anonymous ,

you have to tackle this a bit differntly in Power Query:

1) sort on StatusHistory descending and buffer the result

2) check the other columns and remove duplicates

 

If you paste this code into the advanced editor you should be able to follow the steps:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("xZbbTttAEIZfZZUrkMhmZs/eO0hpRaWKELtXiAtjb6ilxE7tNSpvw7PwZF2bBHFQo0BdVfKN19J8s//8M+PLy5HMM85Trvh1ulgshNZwDUKaxehohDABNmGAEQFhAcLRWTI5T0ji0lV4OV+7OvVFeUNO2vzGeTJ3P1vXeHK8Xi+LLHyqytHV0U4GAwZjwDFCgtICs8gpVwqgx53+clnri1vXhayr23Q5HBY7LDMJRpYZKxgN99xgH2EuHwgGYgL8UccAkyYcxemA4fUkVOpFmU7apihd05Bp2ri/xgiTPlVKjSFKkFspLdM0ArmRLF5XZVPVL+rU+rzqjvJbV/ui6fDxXePd6p2ooBlSbraor1VRevKpqF3mq7oZHtmJaMFQrfQG+UbPoTjhQQqcbTgv22s4iACqOd/ZVMPBpKLa4AZ20aa1d/XyLlhu6YJ6ZHqXLR05uJhPD/9JAlEnqegnyOteHs6QnTuiLeJzW2ZdB6VLMg3x86JM/VCtEE1QdL1tCLJADc4ks2/PB8gHIstr82zydiPQWBmuxSjX8r11mx3H5MtZTOZV2w+Y7+s89W4/OBsDT1Bb0WlKIzRva/ax8CCfRiLjFuUzwXYFXERGA9M6MqgdADPSGC7ybb4Y1pROGFre56t1tL8BSkdiX63JzNWrwvfkg/N4dkhOyx9pmbmVK33zcP9wv0cm/eYCnaCyCOGhvW7/I5OgCYyZ7nZo8CbjVOHTQtgadGAeG6NKEK0IO1tRpaIdC2hw0Vn4SwErhGWKSo57LKSBU2CdA0PHSG1RUKXxTwvqHdyr3w==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [_id = _t, statusHistory.createdAt = _t, statusHistory.status = _t, proposals.title = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"_id", type text}, {"statusHistory.createdAt", type text}, {"statusHistory.status", type text}, {"proposals.title", type text}}),
    #"Sorted Rows" = Table.Buffer( Table.Sort(#"Changed Type",{{"statusHistory.createdAt", Order.Descending}}) ),
    #"Removed Duplicates" = Table.Distinct(#"Sorted Rows", {"_id", "statusHistory.status", "proposals.title"})
in
    #"Removed Duplicates"

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors