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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
AllanBerces
Post Prodigy
Post Prodigy

Switch -Containsstring

Hi good day can anyone correct my calculated column. basically what i required is if the column A contain "DISC" and "SILICON" should be equal to 0, and if contain "DISCHARGE DISC" should be equal to 1

Subtable =
SWITCH (
TRUE (),
CONTAINSSTRING ( 'Table01'[ColumnA], "DISC" ) || 'Table01'[ColumnA] = "0", "0",
CONTAINSSTRING ( 'Table01'[ColumnA], "SILICON" ) || 'Table01'[ColumnA] = "0", "0",
CONTAINSSTRING ( 'Table01'[ColumnA], "DISCHARGE HOSE" ) || 'Table01'[ColumnA] = "1", "1"
)

 

Thnak you

1 ACCEPTED SOLUTION
v-veshwara-msft
Community Support
Community Support

Hi @AllanBerces ,

Thanks for reaching out to the Microsoft Fabric Community.

The behavior occurs because CONTAINSSTRING() performs partial matching, so "DISC" can also match text within another word such as "DISCHARGE". If the requirement is to match "DISC" as a standalone word only, you can try the following calculated column:

Subtable = 
VAR _Text = " " & UPPER('Table01'[ColumnA]) & " "
RETURN
SWITCH(
    TRUE(),
    CONTAINSSTRING(_Text, " DISCHARGE DISC "), 1,
    CONTAINSSTRING(_Text, " DISC ")
        || CONTAINSSTRING(_Text, " SILICON "), 0,
    BLANK()
)

 

I tested this with sample data and got the expected results below:

vveshwaramsft_0-1779878082392.png

 

Please find attached .pbix for reference.

Hope this helps. Please reach out for further assistance.
Thank you.

 

View solution in original post

5 REPLIES 5
Kedar_Pande
Super User
Super User

 Subtable =
SWITCH(
TRUE(),
CONTAINSSTRING('Table01'[ColumnA], "DISCHARGE HOSE"), "1",
CONTAINSSTRING('Table01'[ColumnA], "DISC"), "0",
CONTAINSSTRING('Table01'[ColumnA], "SILICON"), "0"
)

SWITCH evaluates top to bottom and stops at the first match. Order matters here.

@AllanBerces

danextian
Super User
Super User

I'm confused. What is the purpose of Table01'[ColumnA] = "0" which is not in your explanation? Also should it contain either DISC and SILICON or DISC or SILICON as the first and second conditions in your DAX point to an OR logic?





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Hans-Georg_Puls
Super User
Super User

Hi @AllanBerces ,

I'm not completely sure what your requirements are but there are definitely a few points in your definition that are probably incorrect:

  1. Part of the first switch entry is 'Table01'[ColumnA] = "0" and it is "or" linked to the first condition. The second part of the condition for your second switch entry is exactly the same. But it will be never relevant, because every 'Table01'[ColumnA] = "0" match will be caught by the first entry. You should think about the second condition of every entry.
  2. DISC is a substring of DISCHARGE. The leads to the same situation for your first condition.  'Table01'[ColumnA], "DISCHARGE HOSE" ) will never be relevant. Every columnA containing a substring "DISC" will be caught by the first condition of the first entry.

Hope that helps already. If not, please provide some more details about what is the expected result and what is the current result.

v-veshwara-msft
Community Support
Community Support

Hi @AllanBerces ,

Thanks for reaching out to the Microsoft Fabric Community.

The behavior occurs because CONTAINSSTRING() performs partial matching, so "DISC" can also match text within another word such as "DISCHARGE". If the requirement is to match "DISC" as a standalone word only, you can try the following calculated column:

Subtable = 
VAR _Text = " " & UPPER('Table01'[ColumnA]) & " "
RETURN
SWITCH(
    TRUE(),
    CONTAINSSTRING(_Text, " DISCHARGE DISC "), 1,
    CONTAINSSTRING(_Text, " DISC ")
        || CONTAINSSTRING(_Text, " SILICON "), 0,
    BLANK()
)

 

I tested this with sample data and got the expected results below:

vveshwaramsft_0-1779878082392.png

 

Please find attached .pbix for reference.

Hope this helps. Please reach out for further assistance.
Thank you.

 

Hi @v-veshwara-msft @Kedar_Pande @danextian @Hans-Georg_Puls thank you very much or highligthing and explanation. Work perfectly 

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.