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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
franorio
Helper III
Helper III

Help, deleting repeated rows based on status of another column

Hi guys, 

just a quick question, I got a table, some of the principal columns I'am using are User ID, Date, Grade and Status.

The table collects information about determined users compleating courses. Users need more than an 80% to pass and they can be repeated in the column due they can try doing the course more than once. 

 

Tried out with the "delete duplicates" option in Query Editor, but sometimes it keeps line with Status NO OK and sometimes with OK. 

So what I need is to delete repeated user rows, if user is repeated with OK and NO OK keep only those that have status OK. 

 

User IDDateGradeStatus
6543218/8/1710NO OK
6543218/8/1720NO OK
1234568/8/1724NO OK
1234568/8/17100OK
6543218/8/1780OK
1234568/8/1730NO OK 
1234568/8/1743NO OK

 

Thanks!!

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

Try this:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjM1MTYyVNJRstC30DcyMDQHMg0NgISfv4K/t1KsDnYlRqhKDI2MTUzN0JSYEFRiaAAyBo81Fkjy2Awwhjvj0AKcikyMEQ6JBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"User ID" = _t, Date = _t, Grade = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"User ID", Int64.Type}, {"Date", type date}, {"Grade", Int64.Type}, {"Status", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Status", Order.Descending}}),
    #"Table Buffer" = Table.Buffer(#"Sorted Rows"),
    #"Removed Duplicates" = Table.Distinct(#"Table Buffer", {"User ID"})
in
    #"Removed Duplicates"

The trick is the #"Table Buffer" line, which you have to hand-type.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

1 REPLY 1
Greg_Deckler
Super User
Super User

Try this:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjM1MTYyVNJRstC30DcyMDQHMg0NgISfv4K/t1KsDnYlRqhKDI2MTUzN0JSYEFRiaAAyBo81Fkjy2Awwhjvj0AKcikyMEQ6JBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"User ID" = _t, Date = _t, Grade = _t, Status = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"User ID", Int64.Type}, {"Date", type date}, {"Grade", Int64.Type}, {"Status", type text}}),
    #"Sorted Rows" = Table.Sort(#"Changed Type",{{"Status", Order.Descending}}),
    #"Table Buffer" = Table.Buffer(#"Sorted Rows"),
    #"Removed Duplicates" = Table.Distinct(#"Table Buffer", {"User ID"})
in
    #"Removed Duplicates"

The trick is the #"Table Buffer" line, which you have to hand-type.


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.