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.7K Product Ideas
- 1.7K Ideas Exchange
- 1.5K Connect
- 1.2K Connectors
- 294 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.8K Transform
- 97 SQL DataFlows
- 607 Datasets
- 2.1K Magic ETL
- 3.8K Visualize
- 2.4K Charting
- 707 Beast Mode
- 49 App Studio
- 39 Variables
- 667 Automate
- 170 Apps
- 446 APIs & Domo Developer
- 44 Workflows
- 7 DomoAI
- 33 Predict
- 13 Jupyter Workspaces
- 20 R & Python Tiles
- 391 Distribute
- 111 Domo Everywhere
- 274 Scheduled Reports
- 6 Software Integrations
- 115 Manage
- 112 Governance & Security
- Domo Community Gallery
- 31 Product Releases
- 9 Domo University
- 5.3K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 103 Community Announcements
- 4.8K Archive