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
- 297 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 614 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 729 Beast Mode
- 53 App Studio
- 40 Variables
- 677 Automate
- 173 Apps
- 451 APIs & Domo Developer
- 45 Workflows
- 8 DomoAI
- 34 Predict
- 14 Jupyter Workspaces
- 20 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 121 Manage
- 118 Governance & Security
- Domo Community Gallery
- 32 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 108 Community Announcements
- 4.8K Archive