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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.