Forum Discussion

Tjordaske85's avatar
Tjordaske85
Frequent Visitor
3 years ago
Solved

How to remove old revisions

Hi,

 

I'm having this table:

 

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?

 

  • 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:

    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.

2 Replies

  • 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:

    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.