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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
RodFinetti
New Member

Calculated column with multiple text string conditions

Hi there,

 

After much searching and attemps, I can't seem to get this to work. I'm trying to create a calculated field where if the Program Type column contains either "NAPIS" "Meals (AWD)" or "Meals AWD" AND the Received Unit(s) column is "No" then it is marked "Exclude", else "Include". I've tried to use "IN" but it doesn't like that. The problem with the below seems to be that there's a space in some of the terms, but I thought the point of parentheses is to show it's a text string and therefore can contain spaces. Thank you so much in advance!! I really have tried many different ways of acheiving the desired result, to no avail. 

 

*Program Type = switch(true(),

Containsstring('CAGC Export FY 2021 - RF'[Program Type], "napis*")

|| Containsstring('CAGC Export FY 2021 - RF'[Program Type], “*Meals (AWD)”)

|| Containsstring('CAGC Export FY 2021 - RF'[Program Type], “*Meals AWD”)

AND Containsstring('CAGC Export FY 2021 - RF'[Received Unit(s)], “No”),

“Exclude”,

“Include”

1 ACCEPTED SOLUTION
VahidDM
Super User
Super User

Hi @RodFinetti 

 

Try this code to add a new column to your table:

IN or Out =
SWITCH (
    TRUE (),
    CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Program Type], "napis" )
        && CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Received Unit(s)], "NO" ), "Exclude",
    CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Program Type], "Meals (AWD)" )
        && CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Received Unit(s)], "NO" ), "Exclude",
    CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Program Type], "Meals AWD" )
        && CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Received Unit(s)], "NO" ), "Exclude",
    "Include"
)

Output:

VahidDM_0-1631345446917.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos🙏!!

View solution in original post

1 REPLY 1
VahidDM
Super User
Super User

Hi @RodFinetti 

 

Try this code to add a new column to your table:

IN or Out =
SWITCH (
    TRUE (),
    CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Program Type], "napis" )
        && CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Received Unit(s)], "NO" ), "Exclude",
    CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Program Type], "Meals (AWD)" )
        && CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Received Unit(s)], "NO" ), "Exclude",
    CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Program Type], "Meals AWD" )
        && CONTAINSSTRING ( 'CAGC Export FY 2021 - RF'[Received Unit(s)], "NO" ), "Exclude",
    "Include"
)

Output:

VahidDM_0-1631345446917.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos🙏!!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.