Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Using conditional statement with regex

Hello,

 

I am using powerbi desktop to process my monthly bank transactions, and i am trying to categorise transactions.

 

I can do this with a conditional matching a single value, eg.

 

= Table.AddColumn(#"Lowercased Text", "Category", each if Text.Contains([Description], "marini") then "food" else null )

This is nice, but i am looking for a more robust way to do this, along the lines of 

= Table.AddColumn(#"Lowercased Text", "Category", each if Text.Contains([Description], ("marini" OR "zeebra" OR "baker" OR "mcdonalds")) then "food" else null )

eg, i want to look for multiple strings, and if matches any, then update the field..?

  • You can use Splitter.SplitTextByAnyDelimiter to split texts on any delimiter with multiple characters (unlike Text.SplitAny).

     

    = Table.AddColumn(#"Lowercased Text", "Category", each if List.Count(Splitter.SplitTextByAnyDelimiter({"marini","zeebra","baker","mcdonalds"})([Description])) > 1 then "food" else null)

3 Replies