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
Thomas_MedOne
Helper II
Helper II

Trying to search a bracketed list

I have this table with a field that contains data like this:

 

[9]

[9,19]

[19]

[4,9]

[9,17]

(and other values) Essentially it's square brackets [] with numbers in between them.

 

I need to find all the ones that have just 9. And I originally created the new column in Power BI like this:

 

COPC = If (ISERROR(SEARCH(9, Admissions[TypeIds])),"No","Yes")
 
But that is matching on 9 and 19 which is not good. I have searched all over and can't figure out how to re-write the dax code to find only 9's.
2 ACCEPTED SOLUTIONS

@Thomas_MedOne 

Please try

COPC =
VAR String =
SUBSTITUTE ( SUBSTITUTE ( Admissions[TypeIds], "[", "" ), "]", "" )
VAR Items =
SUBSTITUTE ( String, ",", "|" )
VAR Length =
COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T =
GENERATESERIES ( 1, Length, 1 )
RETURN
IF (
"9" IN SELECTCOLUMNS ( T, "@Item", PATHITEM ( Items, [Value] ) ),
"Yes",
"No"
)

View solution in original post

tamerj1
Super User
Super User

@Thomas_MedOne 
I've made sample file to test the proposed solution. Please refer to attached

1.png

COPC = 
VAR String =
    SUBSTITUTE ( SUBSTITUTE ( Admissions[TypeIds], "[", "" ), "]", "" )
VAR Items =
    SUBSTITUTE ( String, ",", "|" )
VAR Length =
    COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T =
    GENERATESERIES ( 1, Length, 1 )
RETURN
    IF (
        "9" IN SELECTCOLUMNS ( T, "@Item", PATHITEM ( Items, [Value] ) ),
        "Yes",
        "No"
    )

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

@Thomas_MedOne 
I've made sample file to test the proposed solution. Please refer to attached

1.png

COPC = 
VAR String =
    SUBSTITUTE ( SUBSTITUTE ( Admissions[TypeIds], "[", "" ), "]", "" )
VAR Items =
    SUBSTITUTE ( String, ",", "|" )
VAR Length =
    COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T =
    GENERATESERIES ( 1, Length, 1 )
RETURN
    IF (
        "9" IN SELECTCOLUMNS ( T, "@Item", PATHITEM ( Items, [Value] ) ),
        "Yes",
        "No"
    )

That is amazing, I would have never been able to figure that out. Thank you.

Thomas_MedOne
Helper II
Helper II

Sorry I was not clear. I need all of the 9's so It also has to match like [4,9] and [9,17] and even [9,19]

@Thomas_MedOne 

Please try

COPC =
VAR String =
SUBSTITUTE ( SUBSTITUTE ( Admissions[TypeIds], "[", "" ), "]", "" )
VAR Items =
SUBSTITUTE ( String, ",", "|" )
VAR Length =
COALESCE ( PATHLENGTH ( Items ), 1 )
VAR T =
GENERATESERIES ( 1, Length, 1 )
RETURN
IF (
"9" IN SELECTCOLUMNS ( T, "@Item", PATHITEM ( Items, [Value] ) ),
"Yes",
"No"
)

tamerj1
Super User
Super User

Hi @Thomas_MedOne 

If just 9 as you have mentioned, then please try

COPC = IFAdmissions[TypeIds] = "[9]""Yes""No" )

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.