Conditional LIKE Statements, Does not Contain, NOT LIKE: Beastmode Only
Hey guys,
To organize my blox_section column I created a beastmode formula under the Data tab in the Analyzer tool to create a new column called "Content Topic":
My Case Statement is the following:
(Case WHEN `blox_section` LIKE '%crime%' THEN 'CRIME & COURTS' WHEN `blox_section` LIKE '%sports/high-school%' THEN 'HIGH SCHOOL SPORTS' WHEN `blox_section` LIKE '%govt-and-polit%' THEN 'GOVERNMENT/POLITICS' WHEN `blox_section` LIKE '%/sports%' THEN 'OTHER SPORTS (Bills, STL, Sub required)' WHEN `blox_section` LIKE '%/sports/college%' OR `blox_section` LIKE '%/sports/husker%' OR `blox_section` LIKE '%/sports/wildcat%' THEN 'COLLEGIATE SPORTS (Standard + Husker-labeled section)' WHEN `blox_section` LIKE '%business%' THEN 'BUSINESS' WHEN `blox_section` LIKE '%lifestyles%' THEN 'LIFESTYLE' when `blox_section` like '%announcement%' OR `blox_section` LIKE '%obit%' THEN 'OBITUARIES AND ANNOUNCEMENT' WHEN `blox_section` LIKE '%opinion%' THEN 'OPINION/LETTERS TO THE EDITOR' WHEN `blox_section` LIKE '%weather%' THEN 'WEATHER' WHEN `blox_section` LIKE '%news%' AND `blox_section` LIKE '%national%' OR `blox_section` LIKE '%world%' THEN 'NATIONAL/INTL NEWS' WHEN `blox_section` LIKE '%education%' THEN 'EDUCATION' WHEN `blox_section` LIKE '%entertainment%' THEN 'ENTERTAINMENT/THINGS TO DO' WHEN `blox_section` LIKE '%health%' THEN 'HEALTH' WHEN `blox_section` LIKE '%eedition%' THEN 'EEDITION' WHEN `blox_section` IS NULL OR `blox_section`='' THEN 'EMPTY' ELSE 'OTHER' END)
My problem arises when two sections have the same string I am trying to categorize.
Example: blox_section = "lifestyles, health-and-fit"
Because lifestyles appears first in this string, Content Topic is categorized as "LIFESTYLES". The Content Topic it should be is 'HEALTH' as health exists in the string.
I want to create conditional like statements to exclude instances like this, but how do I do this when you can't use NOT LIKE in beastmode?
DISCLAIMER: This dataset is very very large, therefore performing this in Beastmode is not only more ideal, but it's easier to perform validations and preview whether or not my case statement is working as intended as this is only to create 1 card.
Best Answer
-
I may be misunderstanding your request but You can use NOT LIKE in a case statement
WHEN `blox_section` LIKE '%lifestyles%' THEN 'LIFESTYLE' AND `blox_section` NOT LIKE '%health%' THEN 'LIFESTYLE'
A simpler way would be to put your WHEN clauses in the order you wish for them to evaluate. So if any string contains health and you want it to have HEALTH as the value even though it may have lifestyles you'd put your HEALTH check before the LIFESTYLES check as case statements are evaluated on a first come, first served basis.
(Case WHEN `blox_section` LIKE '%health%' THEN 'HEALTH' ... WHEN `blox_section` LIKE '%lifestyles%' THEN 'LIFESTYLE' ... ELSE 'OTHER' END)
If you're wanting to exclude the multiple selection values and they will have a comma in them (and only if it's in a multi-selection) you could add a case to your statement to set a new value to then filter out:
(Case WHEN `blox_section` LIKE '%,%' THEN 'MULTI-SELECT' WHEN `blox_section` LIKE '%crime%' THEN 'CRIME & COURTS' WHEN `blox_section` LIKE '%sports/high-school%' THEN 'HIGH SCHOOL SPORTS' WHEN `blox_section` LIKE '%govt-and-polit%' THEN 'GOVERNMENT/POLITICS' WHEN `blox_section` LIKE '%/sports%' THEN 'OTHER SPORTS (Bills, STL, Sub required)' WHEN `blox_section` LIKE '%/sports/college%' OR `blox_section` LIKE '%/sports/husker%' OR `blox_section` LIKE '%/sports/wildcat%' THEN 'COLLEGIATE SPORTS (Standard + Husker-labeled section)' WHEN `blox_section` LIKE '%business%' THEN 'BUSINESS' WHEN `blox_section` LIKE '%lifestyles%' THEN 'LIFESTYLE' when `blox_section` like '%announcement%' OR `blox_section` LIKE '%obit%' THEN 'OBITUARIES AND ANNOUNCEMENT' WHEN `blox_section` LIKE '%opinion%' THEN 'OPINION/LETTERS TO THE EDITOR' WHEN `blox_section` LIKE '%weather%' THEN 'WEATHER' WHEN `blox_section` LIKE '%news%' AND `blox_section` LIKE '%national%' OR `blox_section` LIKE '%world%' THEN 'NATIONAL/INTL NEWS' WHEN `blox_section` LIKE '%education%' THEN 'EDUCATION' WHEN `blox_section` LIKE '%entertainment%' THEN 'ENTERTAINMENT/THINGS TO DO' WHEN `blox_section` LIKE '%health%' THEN 'HEALTH' WHEN `blox_section` LIKE '%eedition%' THEN 'EEDITION' WHEN `blox_section` IS NULL OR `blox_section`='' THEN 'EMPTY' ELSE 'OTHER' END)
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0
Answers
-
I may be misunderstanding your request but You can use NOT LIKE in a case statement
WHEN `blox_section` LIKE '%lifestyles%' THEN 'LIFESTYLE' AND `blox_section` NOT LIKE '%health%' THEN 'LIFESTYLE'
A simpler way would be to put your WHEN clauses in the order you wish for them to evaluate. So if any string contains health and you want it to have HEALTH as the value even though it may have lifestyles you'd put your HEALTH check before the LIFESTYLES check as case statements are evaluated on a first come, first served basis.
(Case WHEN `blox_section` LIKE '%health%' THEN 'HEALTH' ... WHEN `blox_section` LIKE '%lifestyles%' THEN 'LIFESTYLE' ... ELSE 'OTHER' END)
If you're wanting to exclude the multiple selection values and they will have a comma in them (and only if it's in a multi-selection) you could add a case to your statement to set a new value to then filter out:
(Case WHEN `blox_section` LIKE '%,%' THEN 'MULTI-SELECT' WHEN `blox_section` LIKE '%crime%' THEN 'CRIME & COURTS' WHEN `blox_section` LIKE '%sports/high-school%' THEN 'HIGH SCHOOL SPORTS' WHEN `blox_section` LIKE '%govt-and-polit%' THEN 'GOVERNMENT/POLITICS' WHEN `blox_section` LIKE '%/sports%' THEN 'OTHER SPORTS (Bills, STL, Sub required)' WHEN `blox_section` LIKE '%/sports/college%' OR `blox_section` LIKE '%/sports/husker%' OR `blox_section` LIKE '%/sports/wildcat%' THEN 'COLLEGIATE SPORTS (Standard + Husker-labeled section)' WHEN `blox_section` LIKE '%business%' THEN 'BUSINESS' WHEN `blox_section` LIKE '%lifestyles%' THEN 'LIFESTYLE' when `blox_section` like '%announcement%' OR `blox_section` LIKE '%obit%' THEN 'OBITUARIES AND ANNOUNCEMENT' WHEN `blox_section` LIKE '%opinion%' THEN 'OPINION/LETTERS TO THE EDITOR' WHEN `blox_section` LIKE '%weather%' THEN 'WEATHER' WHEN `blox_section` LIKE '%news%' AND `blox_section` LIKE '%national%' OR `blox_section` LIKE '%world%' THEN 'NATIONAL/INTL NEWS' WHEN `blox_section` LIKE '%education%' THEN 'EDUCATION' WHEN `blox_section` LIKE '%entertainment%' THEN 'ENTERTAINMENT/THINGS TO DO' WHEN `blox_section` LIKE '%health%' THEN 'HEALTH' WHEN `blox_section` LIKE '%eedition%' THEN 'EEDITION' WHEN `blox_section` IS NULL OR `blox_section`='' THEN 'EMPTY' ELSE 'OTHER' END)
**Was this post helpful? Click Agree or Like below**
**Did this solve your problem? Accept it as a solution!**0 -
I realized that NOT LIKE is problematic in views and was able to get the result I wanted. Unfortunately rearranging the WHEN clause wouldn't work because there's cases where the situation is reversed too.
0
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