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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Jeffrey2
Frequent Visitor

"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. 

1 ACCEPTED SOLUTION
BA_Pete
Super User
Super User

Hi @Jeffrey2 ,

 

Try this instead:

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

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




View solution in original post

8 REPLIES 8
mussaenda
Super User
Super User

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.

BA_Pete
Super User
Super User

Hi @Jeffrey2 ,

 

Try this instead:

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

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




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

 

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



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




I just want to get rid of rows that have the word "Duplicate" in the Comments field. Keep all other rows. If the row had "a;dlkfja;lkdfj;ladkjf;alkjfd;lakfj" I want to keep it. If a row had "adsf;lkaj;lsfkja;lkjfadsf Duplicate" , I want it removed. If a row had null, I want to keep it. 

 

I just think Table.SelectRows(#"Filtered Rows1", each not Text.Contains([Comments], "Duplicate")) should have been enough. To me this is a program error. 

 

@BA_Pete to use your wording, 

 

Table.SelectRows(#"Filtered Rows1", each not Text.Contains([Comments], "Duplicate")) should mean:

SelectRows function: give me something that doesn't contain "Duplicate".

 

If the comment only contains null, then it doesn't contain "Duplicate". Therefore it should be kept.

 

Ah, yes, I see what you mean.

However, a null doesn't contain any text either, so Text.Contains can't resolve to true or false.

As there's no text to evaluate, it has to resolve to null.

 

For example:

BA_Pete_0-1651847241922.png

 

Pete



Now accepting Kudos! If my post helped you, why not give it a thumbs-up?

Proud to be a Datanaut!




Thank you for the explanation. That makes total sense. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors