Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
phaering
Helper I
Helper I

Using DAX Search to find separate partial values in multiple columns

I am trying to create a new column that provides a simplified naming for an operating system (OS) running on a server.  I have two columns from my source data that provide the OS version and name.  I need to search those two columns, find partial values, and create the new naming for my new column.  I am able to do this if I only need to search one source column but adding in the second search has proven difficult.  I was able to figure this out in less than one minute in Tableau and I am on day 3 trying to figure this out in Power BI.  Here are the particulars (samples of my data):

 

ServerNameOSOS_Full_NameOS Best (my new value)
jerryWin2008R2 6.1.7601Microsoft WIndows Server 2008 R2 Enterprise x64Win 2008 R2 Ent (this is the value I want)
elaineWin2008 6.0.6003Microsoft Windows Server 20008 StandardWin 2008 Std
georgeLinux Red Hat Enterprise Server 7.8 (3.10.0-1127.el7.x86_64)Linux Red Hat Enterprise Server 7.8 (3.10.0-1127.el7.x86_64)Red Hat 7.8
kramerSunOS 5.10 (Generic_a47148-26)SunOS 5.10 (Generic_a47148-26)SunOS 5.10
    

 

For "george" and "kramer" I can run a single search line to create my new OS value (OS Best):

 

SEARCH("SunOS 5.10",[OS],,-1) <> -1,"SunOS 5.10"...as an example...this works just fine

 

But for "jerry" and "elaine" I need to search both the "OS" and the "OS_Full_Name" columns to create the new value for "OS Best" because the "OS" column cannot tell me if the version is "standard" or "enterprise".  How do I create the 'SEARCH' command structure to look in both, find the partial values, and provide the new value for "OS Best"?  My attempts look something like this but it fails to correctly differentiate between the '2008' and '2008 R2' versions in "OS"...

 

SEARCH("Win2008 ",[OS],,-1) && SEARCH("Standard",[OS_Full_Name],,-1) <>-1,"Win 2008 Std"

 

Please don't refer me to the documenation because I have already reviewed that and cannot find anything referencing multiple searchs in the same command.

 

Thank you!

Paul

 

2 ACCEPTED SOLUTIONS
Icey
Community Support
Community Support

Hi @phaering ,

 

Try this:

Column =
SWITCH (
    TRUE (),
    SEARCH ( "Win2008R2", [OS],, -1 ) <> -1                           ----------------------"<> -1" is missing in your expression.
        && SEARCH ( "Enterprise", [OS_Full_Name],, -1 ) <> -1, "Win 2008 R2 Ent",
    SEARCH ( "Win2008", [OS],, -1 ) <> -1                             ----------------------"<> -1" is missing in your expression.
        && SEARCH ( "Standard", [OS_Full_Name],, -1 ) <> -1, "Win 2008 Std",
    SEARCH ( "Linux Red Hat Enterprise Server 7.8", [OS],, -1 ) <> -1, "Red Hat 7.8",
    SEARCH ( "SunOS 5.10", [OS],, -1 ) <> -1, "SunOS 5.10"
)

column.PNG

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Thank you very much!  I never thought to include the "<> -1" in both parts.  Much appreciated, this worked.

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

In its statement SWITCH would like to:

SWITCH(TRUE(),

SEARCH("Win2008 RT",[OS],,-1) && SEARCH("Standard",[OS_Full_Name],,-1) <>-1,"Win 2008 RT Std",

SEARCH("Win2008 ",[OS],,-1) && SEARCH("Standard",[OS_Full_Name],,-1) <>-1,"Win 2008 Std"


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

In your SWITCH statement you would want:

 

SWITCH(TRUE(),

  SEARCH("Win2008 RT",[OS],,-1) && SEARCH("Standard",[OS_Full_Name],,-1) <>-1,"Win 2008 RT Std",

  SEARCH("Win2008 ",[OS],,-1) && SEARCH("Standard",[OS_Full_Name],,-1) <>-1,"Win 2008 Std"


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

This is still not working as the "&&" needs to be both and it appears that it is finding either and applying the value incorrectly.

Here is the output I'm getting and you'll see the formula is not working quite right.  I've just done a few lines and you'll see it is applying a windows name to the Red Hat OS.  These should have been assigned the "(unknown)" value per the SWITCH formula.  It is also not applying the value correctly to the different Windows 2008 and Windows 2008R2 versions.

 

powerbi-screencapture.jpg

 

 
Icey
Community Support
Community Support

Hi @phaering ,

 

Try this:

Column =
SWITCH (
    TRUE (),
    SEARCH ( "Win2008R2", [OS],, -1 ) <> -1                           ----------------------"<> -1" is missing in your expression.
        && SEARCH ( "Enterprise", [OS_Full_Name],, -1 ) <> -1, "Win 2008 R2 Ent",
    SEARCH ( "Win2008", [OS],, -1 ) <> -1                             ----------------------"<> -1" is missing in your expression.
        && SEARCH ( "Standard", [OS_Full_Name],, -1 ) <> -1, "Win 2008 Std",
    SEARCH ( "Linux Red Hat Enterprise Server 7.8", [OS],, -1 ) <> -1, "Red Hat 7.8",
    SEARCH ( "SunOS 5.10", [OS],, -1 ) <> -1, "SunOS 5.10"
)

column.PNG

BTW, .pbix file attached.

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much!  I never thought to include the "<> -1" in both parts.  Much appreciated, this worked.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.