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
cottrera
Post Prodigy
Post Prodigy

Power Quey Issues with Conditional Column

Hi 

 

I have a table that contains a column called 'Detail' this is a free text field used when customer call into our call centre.

I have created a Conditional Column  that seaches the 'Detail' column and looks for the following words

 

KeyWordsVermin

rats
pest
pests
rat
mice
mouse
glis glis
vermin
rodent
rodents
ants
wasps
hornets
nest
bees
bedbugs
pigeons
cockroaches
carpet beetles
earwigs
silverfish

 

These are all common rodents in the UK.  

Here is an example of my conditional column,

cottrera_0-1703231128303.png

I have tried both upper and lower case text . However the output is showing far too many 'Yes'  where the free text in the 'Details' field clearly do not refer to any of the conditions I have set.

 

What am I doing wrong?

 

thanks

Richard

 

 

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

Hi @cottrera 

You can refer to the following solution.

1.Set the key word to a new table (name:Query1) and uppercase them

vxinruzhumsft_0-1703484457723.png

2.in your original table create a custom column( the detail column is uppercased) and input the following code

 

let 
_count=Table.RowCount(Table.SelectRows(Query1,(x)=>Text.Contains([Detail],x[KeyWordsVermin])))
in
if _count>0 then "Yes" else null

 

vxinruzhumsft_2-1703484633157.png

Output

vxinruzhumsft_3-1703484642735.png

Best Regards!

Yolo Zhu

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

4 REPLIES 4
v-xinruzhu-msft
Community Support
Community Support

Hi @cottrera 

You can refer to the following solution.

1.Set the key word to a new table (name:Query1) and uppercase them

vxinruzhumsft_0-1703484457723.png

2.in your original table create a custom column( the detail column is uppercased) and input the following code

 

let 
_count=Table.RowCount(Table.SelectRows(Query1,(x)=>Text.Contains([Detail],x[KeyWordsVermin])))
in
if _count>0 then "Yes" else null

 

vxinruzhumsft_2-1703484633157.png

Output

vxinruzhumsft_3-1703484642735.png

Best Regards!

Yolo Zhu

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

 

 

 

 

dufoq3
Super User
Super User

Hi @cottrera ,

I know that this is not easy to understand, but add this as Custom Column and it will do the job.

I assume that your column with text to search is called Details as you mentioned.
(If you don't want to ingore CaseSensitivity, just change Comparer.OrdinalIgnoreCase for Comparer.Ordinal or delete whole comparer as 3rd argument of Text.Contains)

 

 

 

List.AnyTrue(
        List.Accumulate(
    {"rats", "pest", "pests", "rat", "mice", "mouse", "glis glis", "vermin", "rodent", "rodents", "ants", "wasps", "hornets", "nest", "bees", "bedbugs", "pigeons", "cockroaches", "carpet beetles", "earwigs", "silverfish"},
    {},
    (s,c)=> 
           s & {Text.Contains([Details], c, Comparer.OrdinalIgnoreCase)}
	)
)

 

 

 

 You can find a lot of usefull info about List.Accumulate here.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

cottrera
Post Prodigy
Post Prodigy

Thank you for your quick reponse. The 'Details' field is all Uppercase. And the Condition is also using Upper case.
That said I have added Ordinal.IgnoreCase. This caused and error so I manually typed and the telesense would only show this function Comparer.OrdinalIgnoreCase.
The output is still showing details that do not contain any of the key words I have stated.

Regards
Richard

watkinnc
Super User
Super User

Remember that Power Query is case sensitive to the fullest. When you close that formula dialog, go up to the formula bar, and add the optional parameter Ordinal.IgnoreCase(I'm assuming that this screenshot will result in Text.Contains, so

 

each if Text.Contains(TableName, [Column], "Varmint", Ordinal.IgnoreCase) then "Yes" else "No")


Might be easier to make the Vermin list into a one column table, and then add a column to that using each Table.FindText(OtherTable, [Details], _[KeyWordVermin], Ordinal.IgnoreCase)

 

--Nate


I’m usually answering from my phone, which means the results are visualized only in my mind. You’ll need to use my answer to know that it works—but it will work!!

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
Top Kudoed Authors