Forum Discussion
Switch -Containsstring
- 3 months ago
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:
Please find attached .pbix for reference.
Hope this helps. Please reach out for further assistance.
Thank you.
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:
Please find attached .pbix for reference.
Hope this helps. Please reach out for further assistance.
Thank you.
- AllanBerces3 months ago
Post Prodigy
Hi v-veshwara-msft Kedar_Pande danextian Hans-Georg_Puls thank you very much or highligthing and explanation. Work perfectly