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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
monojchakrab
Resolver III
Resolver III

Switch and Containsstring not replacing all values as required

Hiya All,

 

I am coming across a strange problem while using the SWITCH function with CONTAINSSTRING and the code is as below :

 

Size = 

SWITCH(TRUE(),
    CONTAINSSTRING('summary table'[Title],"100")||CONTAINSSTRING('summary table'[Title],"110"),
    "100",
    CONTAINSSTRING('summary table'[Title],"300"),
    "300",
    CONTAINSSTRING('summary table'[Title],"50"),
    "50",
    CONTAINSSTRING('summary table'[Title],"Jar"),
    "80g",
    CONTAINSSTRING('summary table'[Title],"Pouch"),
    "500g",
blank()
)

 

While it is doing all replacements as per the requirement, its just the lines which have "pouch" in the title, it is just not returning the target value I want in the column[size]. I have tried with all possible unique key word searches in the [Title] for this particular product/value.

Screengrab below :

not returning the target valuenot returning the target value

 

Here's the title :

monojchakrab_0-1652098600923.png

The target is to return the [size] as 500 gm if the [title] contains "Pouch"...

 

Am I missing something in my code?

 

Appreciate the help.

 

Best

 

 

2 ACCEPTED SOLUTIONS
AntonioM
Solution Sage
Solution Sage

Hi, 

 

The titles with 'pouch' also have '50' in them (because of the 500g), so your SWITCH statement is picking that up first, then putting '50' in the size column. 

 

SWITCH always goes through each of the statements until it finds a match, so if you put the 'pouch' option first, then you shouldn't have this problem (As long as none of the other titles just so happen to have 'pouch' in).

 

Alternatively, you could also try changing the 50 to '50g', as this wouldn't pick up the 500.

View solution in original post

2 REPLIES 2
AntonioM
Solution Sage
Solution Sage

Hi, 

 

The titles with 'pouch' also have '50' in them (because of the 500g), so your SWITCH statement is picking that up first, then putting '50' in the size column. 

 

SWITCH always goes through each of the statements until it finds a match, so if you put the 'pouch' option first, then you shouldn't have this problem (As long as none of the other titles just so happen to have 'pouch' in).

 

Alternatively, you could also try changing the 50 to '50g', as this wouldn't pick up the 500.

Thanks @AntonioM ...gotcha!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors