Forum Discussion
LUCASM
Helper IV
7 years agoCASE Statement with Like
I need to replicate this SQL case statement in Power BI somehow. CASE
WHEN [PC Name] like '%ZENBUS%' THEN 'BUSINESS'
WHEN [PC Name] like '%ZENWEB%' THEN 'ONLINE'
WHEN [PC ...
themistoklis
Community Champion
7 years ago
If you want to write it with if statements it should be like this:
Business = IF (
SEARCH ( "*ZENBUS*", Table1[PC Name],, 0 ) = 0,
IF ( SEARCH ( "*AZENWEB*", Table1[PC Name],, 0 ) = 0,
IF ( SEARCH ( "*ZENUSE*", Table1[PC Name],, 0 ) = 0, [PC Name], "STORE" ),
"ONLINE"),
"BUSINESS"
)
- LUCASM7 years ago
Helper IV
Hi themistoklis
This solution has a similar problem to that of khader312
every row is the same rather than running through the IFs
could this be because every row starts with ZENUS and either has ZENBUS or ZENWEB also in the text
examples of full fields
ZENUSE AZN ZENBUS IT Needs to become "Business"
ZENUSE AZN ZENWEB IT Needs to become "Online"
ZENUSE AZN ZEN IT Needs to become "Store"
ZENBUS EU SARL Needs to become "Store"
Logic: Check the first two otherwise "Store"
Apologise if this was not clear first time around
- parry2k7 years ago
Super User
LUCASM try this
Type = SWITCH( TRUE(), SEARCH( "AZN ZENBUS", Table2[col],,0) <> 0 , "Business", SEARCH( "AZN ZENWEB", Table2[col],,0) <> 0 , "Online", "Store" )
- LUCASM7 years ago
Helper IV
Thanks parry2k
That is the answer I was expecting.
- Omega7 years ago
Impactful Individual
Try:
Column = Switch (True (), Contains (Table Name,[PC Name], "ZENBUS"), "BUSINESS", Contains (Table Name,[PC Name], "ZENWEB"),"ONLINE", Contains (Table Name,[PC Name], "ZENUSE"),"Store", [PC Name])