Forum Discussion

Jeffrey2's avatar
Jeffrey2
Helper I
4 years ago
Solved

"Does Not Contain" is picking up null values

I have a power query table that I have narrowed down to two records, one the original and one that is close to being a duplicate (the Comments column).

 

In record one, the Comments field is null. In record two, the field says "Duplicate Initiation". 

 

I added a step that says Table.SelectRows(#"Filtered Rows1", each not Text.Contains([Comments], "Duplicate")).

 

However, it's removing both records instead of just keeping the record with the null in comments. How do I keep the record with the null value and remove the record with the "Duplicate" word. 

  • Hi Jeffrey2 ,

     

    Try this instead:

    Table.SelectRows(#"Filtered Rows1", each not Text.Contains([Comments], "Duplicate") or [Comments] = null)

     

    Pete

8 Replies

  • Hi Jeffrey2 ,

     

    Try this instead:

    Table.SelectRows(#"Filtered Rows1", each not Text.Contains([Comments], "Duplicate") or [Comments] = null)

     

    Pete

    • Jeffrey2's avatar
      Jeffrey2
      Helper I

      Thanks BA_Pete . The logic doesn't really make sense to me, but it fixed the problem. 

      • BA_Pete's avatar
        BA_Pete
        Super User

         

        You're giving the the SelectRows function a choice: either give me something that doesn't contain "Duplicate", or give me a null.

        However, this is a very narrow example-case, so the logic may fall over with a broader sampleset.

        For example, what happens when you have rows that otherwise match, but one has "Whatever" in [comments], and the other has null. Both of these rows will be retained using this logic - is this what you want/need?

         

        Pete

  • mussaenda's avatar
    mussaenda
    Community Champion

    Hi Jeffrey2 ,

     

    Can you try to exclude the null on your filter like below?

    Table.SelectRows(#"Filtered Rows1", each not Text.Contains([Comments], "Duplicate") and [Comments] <> null)

     

    Hope this helps.