Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

Deleting/Removing specific rows in Power BI Query

Hi Power BI Team,

I need your help! 

I got a column with actions like refurbisment, Load and Credit(Gutschrift). 

The action Credit shows wrong and unneeded data. I want to delete the wrong rows but How can I do this with only the PB Option delet first and last rows...
I also need the other actions. I can not just only select Credit.


I want everything delet in Action(Maßnahme) Credit(Gutschrift) which has not these numbers:


The big problem is that I only want to affect a part of a column and Query not the entire thing...

 

 

  • Hello Anonymous 

     

    to delete some rows you can use Table.SelectRows and filter them out. If you need to keep some of this deleted rows, you can use a list and add in the Table.SelectRows a List.Contains-function. Here a practical example how this could work for you

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUQosTczJLDm8pEQpVidaKQlDJBko4l5aUpycUZSZBhHCrg1NEdH68FsXCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Maßnahme = _t, IDS = _t]),
        ChangedType = Table.TransformColumnTypes(Source,{{"Maßnahme", type text}, {"IDS", type text}}),
        YourListWithNumbersToKeep = {"a","b","c"},
        SelectYourRows = Table.SelectRows
        (
            ChangedType,
            (row)=> not(row[IDS]="Gutschrift" and List.Contains(YourListWithNumbersToKeep, row[Maßnahme]))
        )
    
    in
        SelectYourRows

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy

2 Replies

  • Jimmy801's avatar
    Jimmy801
    Community Champion

    Hello Anonymous 

     

    to delete some rows you can use Table.SelectRows and filter them out. If you need to keep some of this deleted rows, you can use a list and add in the Table.SelectRows a List.Contains-function. Here a practical example how this could work for you

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlTSUQosTczJLDm8pEQpVidaKQlDJBko4l5aUpycUZSZBhHCrg1NEdH68FsXCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Maßnahme = _t, IDS = _t]),
        ChangedType = Table.TransformColumnTypes(Source,{{"Maßnahme", type text}, {"IDS", type text}}),
        YourListWithNumbersToKeep = {"a","b","c"},
        SelectYourRows = Table.SelectRows
        (
            ChangedType,
            (row)=> not(row[IDS]="Gutschrift" and List.Contains(YourListWithNumbersToKeep, row[Maßnahme]))
        )
    
    in
        SelectYourRows

    Copy paste this code to the advanced editor in a new blank query to see how the solution works.

    If this post helps or solves your problem, please mark it as solution (to help other users find useful content and to acknowledge the work of users that helped you)
    Kudoes are nice too

    Have fun

    Jimmy