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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Tjordaske85
Frequent Visitor

How to remove old revisions

Hi,

 

I'm having this table:

Tjordaske85_0-1669129562978.png

 

As you can see a document with a certain name (column 'Naam') is several times in the table and has sometimes several revisions (column 'Revisie).

I want to keep only ALL rows with the latest revisions (which is sometimes 0, but can also be a 1, 2, 3, ...).

So all the rows in the green frames needs to remain, all other rows needs to be hided or deleted.

 

Any ideas or suggestions?

 

1 ACCEPTED SOLUTION
v-yanjiang-msft
Community Support
Community Support

Hi @Tjordaske85 ,

According to your description, here's my solution.

1.Add a custom column.

Table.SelectRows(#"Changed Type",(x)=>x[Map]=[Map] and x[Naam]=[Naam])[Revisie]{0}

2.Add a step in Advanced editor.

#"Filter"=Table.SelectRows(#"Added Custom",each [Revisie]=[Custom])

Result:

vkalyjmsft_0-1669778876579.png

Here's the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7ZKxCsIwEIZf5chcYi50cpU6OtiKQulw2qsEai8kseLbW30FQVE63D/8w/fBz9W1ymHn0igc3HCOrcToOCyhOFTFdrPINeocShpcIhdUpkqDBNEL94k67rVvu6m1qslm0idJ+Nck81VStTaWwKA2Vj8ToUxEQwunXiInuEwn/ijX20sXOHIYxQVId8+wXyG+Mcgs/2359HDNAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Map = _t, Naam = _t, Revisie = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Map", type text}, {"Naam", type text}, {"Revisie", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.SelectRows(#"Changed Type",(x)=>x[Map]=[Map] and x[Naam]=[Naam])[Revisie]{0}),
    #"Filter"=Table.SelectRows(#"Added Custom",each [Revisie]=[Custom]),
    #"Removed Columns" = Table.RemoveColumns(Filter,{"Custom"})
in
    #"Removed Columns"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @Tjordaske85 ,

According to your description, here's my solution.

1.Add a custom column.

Table.SelectRows(#"Changed Type",(x)=>x[Map]=[Map] and x[Naam]=[Naam])[Revisie]{0}

2.Add a step in Advanced editor.

#"Filter"=Table.SelectRows(#"Added Custom",each [Revisie]=[Custom])

Result:

vkalyjmsft_0-1669778876579.png

Here's the whole M syntax:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("7ZKxCsIwEIZf5chcYi50cpU6OtiKQulw2qsEai8kseLbW30FQVE63D/8w/fBz9W1ymHn0igc3HCOrcToOCyhOFTFdrPINeocShpcIhdUpkqDBNEL94k67rVvu6m1qslm0idJ+Nck81VStTaWwKA2Vj8ToUxEQwunXiInuEwn/ijX20sXOHIYxQVId8+wXyG+Mcgs/2359HDNAw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Map = _t, Naam = _t, Revisie = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Map", type text}, {"Naam", type text}, {"Revisie", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Table.SelectRows(#"Changed Type",(x)=>x[Map]=[Map] and x[Naam]=[Naam])[Revisie]{0}),
    #"Filter"=Table.SelectRows(#"Added Custom",each [Revisie]=[Custom]),
    #"Removed Columns" = Table.RemoveColumns(Filter,{"Custom"})
in
    #"Removed Columns"

I attach my sample below for your reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ImkeF
Super User
Super User

Hi @Tjordaske85 ,
you should sort your table by "Revisie" in descending order and buffer that step:
https://community.powerbi.com/t5/Community-Blog/Bug-warning-for-Table-Sort-and-removing-duplicates-i...

Then check the first 2 columns and remove duplicates.
That will keep only the latest from them.

 

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
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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

Top Solution Authors
Top Kudoed Authors