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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply

Search Query Syntax error

Hi all,

I am an occasional user of Power BI so I tend to forget fundamentals sometimes,I am trying to create "measure" using DAX Search and Switch function, Basically, I am looking at sentences created as cells for keywords.

I used following formula but its showing error w.r.t table values.

Category = SWITCH(TRUE(),
SEARCH("CANCEL",'Final'[Note-0],1,0)>0,"CANCEL",
SEARCH("DELETE",'Final'[Note-0],1,0)>0,"CANCEL",
SEARCH("REJECT",'Final'[Note-0],1,0)>0,"CANCEL",)
Final'[Note-0] is the column from which i am trying to find the strings cancel, delet and reject
1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @ramhariessentia ,

 

Since you are creating a Measure, it is needed to use MAX, MIN, SELECTEDVALUE, etc. to specify the current row. Try this:

Category =
SWITCH (
    TRUE (),
    SEARCH ( "CANCEL", MAX ( 'Final'[Note-0] ), 1, 0 ) > 0, "CANCEL",
    SEARCH ( "DELETE", MAX ( 'Final'[Note-0] ), 1, 0 ) > 0, "CANCEL",
    SEARCH ( "REJECT", MAX ( 'Final'[Note-0] ), 1, 0 ) > 0, "CANCEL"
)

 

Or, you can also use CONTAINSSTRING function:

Category 2 =
SWITCH (
    TRUE (),
    CONTAINSSTRING ( "CANCEL", MAX ( Final[Note-0] ) ), "CANCEL",
    CONTAINSSTRING ( "DELETE", MAX ( 'Final'[Note-0] ) ), "CANCEL",
    CONTAINSSTRING ( "REJECT", MAX ( 'Final'[Note-0] ) ), "CANCEL"
)

cancel.JPG

 

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

2 REPLIES 2
Icey
Community Support
Community Support

Hi @ramhariessentia ,

 

Since you are creating a Measure, it is needed to use MAX, MIN, SELECTEDVALUE, etc. to specify the current row. Try this:

Category =
SWITCH (
    TRUE (),
    SEARCH ( "CANCEL", MAX ( 'Final'[Note-0] ), 1, 0 ) > 0, "CANCEL",
    SEARCH ( "DELETE", MAX ( 'Final'[Note-0] ), 1, 0 ) > 0, "CANCEL",
    SEARCH ( "REJECT", MAX ( 'Final'[Note-0] ), 1, 0 ) > 0, "CANCEL"
)

 

Or, you can also use CONTAINSSTRING function:

Category 2 =
SWITCH (
    TRUE (),
    CONTAINSSTRING ( "CANCEL", MAX ( Final[Note-0] ) ), "CANCEL",
    CONTAINSSTRING ( "DELETE", MAX ( 'Final'[Note-0] ) ), "CANCEL",
    CONTAINSSTRING ( "REJECT", MAX ( 'Final'[Note-0] ) ), "CANCEL"
)

cancel.JPG

 

Best Regards,

Icey

 

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

 

 

mahoneypat
Microsoft Employee
Microsoft Employee

Looks like you just had an extra comma at the end.

 

Category =
SWITCH (
    TRUE (),
    SEARCH (
        "CANCEL",
        'Final'[Note-0],
        1,
        0
    ) > 0"CANCEL",
    SEARCH (
        "DELETE",
        'Final'[Note-0],
        1,
        0
    ) > 0"CANCEL",
    SEARCH (
        "REJECT",
        'Final'[Note-0],
        1,
        0
    ) > 0"CANCEL"
)

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.