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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

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
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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