Using beast mode to compare strings
Hi,
I am trying to compare the values of 2 fields using a CASE WHEN statement.
"field1" contains an email address e.g. "bob@test.com"
"field2" may contain a name and email, e.g. "Bob Smith, bob@test.com"
The outcome I would like from my beast mode is to check if the value in field1 is contained within the value of field2. I cannot guarantee the layout of field2 as it has been manually input so the email may be missing or not be in the last part of the string (just to rule out anything that might work by evaluating the last x characters of the string, it needs to look through the whole string somehow)
What I have been toying with is like this:
CASE WHEN 'field1' LIKE '%'field2'%' THEN 'Looks good'
ELSE 'Looks bad'
END
Any suggestions please?
Best Answers
-
@Mark Puddephatt You can use the INSTR function to return the starting position of the email address within field2. If field1 is contained within field2 it will return a number greater than 0.
case when INSTR(field2,field1) > 0 then 'Looks good' else 'Looks bad' end
2 -
The upper function just helps standardize the strings so that they'll match even if they have different cases within the data.
For "matches field 3" you would just add another line to identify them:
case when instr(upper(`field2`), upper(`field1`)) > 0 then 'matches field 2'
when instr(upper(`field3`), upper(`field1`)) > 0 then 'matches field 3'
else 'Looks bad'
2
Answers
-
I'd probably do something like
case when instr(upper(`field2`), upper(`field1`)) > 0 then 'Looks good'
else 'Looks bad'
end
2 -
@Mark Puddephatt You can use the INSTR function to return the starting position of the email address within field2. If field1 is contained within field2 it will return a number greater than 0.
case when INSTR(field2,field1) > 0 then 'Looks good' else 'Looks bad' end
2 -
Thank you both. I went with the slightly simpler option from @MichelleH and it does the job. Not sure if adding "upper" to enforce case sensitivity would be more accurate but I will see how the data looks once I analyse it in more details.
If I wanted to add an extra comparison with "field3" into the mix, can I throw an "OR" in there somewhere? So the outcomes would be "matches field2" "matches field 3" or "looks bad"?
0 -
The upper function just helps standardize the strings so that they'll match even if they have different cases within the data.
For "matches field 3" you would just add another line to identify them:
case when instr(upper(`field2`), upper(`field1`)) > 0 then 'matches field 2'
when instr(upper(`field3`), upper(`field1`)) > 0 then 'matches field 3'
else 'Looks bad'
2 -
@Mark Puddephatt - just to second what @Sean_Tully is saying, it's part of my standard practice to wrap text strings in UPPER() before comparing. It just helps to minimize any chance of variability.
String != string != STRING
David Cunningham
** Was this post helpful? Click Agree 😀, Like 👍️, or Awesome ❤️ below **
** Did this solve your problem? Accept it as a solution! ✔️**2
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 738 Beast Mode
- 57 App Studio
- 40 Variables
- 685 Automate
- 176 Apps
- 452 APIs & Domo Developer
- 47 Workflows
- 10 DomoAI
- 36 Predict
- 15 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 124 Manage
- 121 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive