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
Anonymous
Not applicable

Calculated Column - Product Categories

Good evening All,

 

I am trying to create a calculated column that puts product codes into categories. A sample list of product codes are as per below.

 

The rules are as follows:

 

If the code contains the letter L and either an L or an E, then the category is LL. 

If the code contains the letter L and either an O or an R, then the category is LO.

Otherwise "No Category"

 

Can someone assist with a formula suggestion or recommend a solution. I thought this was quite tough as powerbi has to look for certain text within a string.

 

Product codes are anywhere between 3 characters to 5 characters long

 

Many thanks

 

Herb

 

Product Codes.png

1 ACCEPTED SOLUTION

HI @Anonymous

 

Try this

 

=
IF (
    OR (
        SEARCH ( "L", TableName[Product Codes], 2, 0 ) > 0,
        SEARCH ( "E", TableName[Product Codes], 2, 0 ) > 0
    ),
    "LL",
    IF (
        OR (
            SEARCH ( "O", TableName[Product Codes], 2, 0 ) > 0,
            SEARCH ( "R", TableName[Product Codes], 2, 0 ) > 0
        ),
        "LO",
        "No Category"
    )
)

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

HI @Anonymous

 

Try this

 

=
IF (
    OR (
        SEARCH ( "L", TableName[Product Codes], 2, 0 ) > 0,
        SEARCH ( "E", TableName[Product Codes], 2, 0 ) > 0
    ),
    "LL",
    IF (
        OR (
            SEARCH ( "O", TableName[Product Codes], 2, 0 ) > 0,
            SEARCH ( "R", TableName[Product Codes], 2, 0 ) > 0
        ),
        "LO",
        "No Category"
    )
)
Anonymous
Not applicable

Absolutely brilliant.

 

Many thanks

 

Herbz09

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