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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
adam_mac
Helper I
Helper I

DAX Measure: If contains text and does not contain

Hi, i am trying to write a dax measure that returns a 1 or 0 (true, false) when the Subject column contains a bunch of options (apple, microsoft, amazon etc.) and when the Category column does not contain Active. Im getting a bit out of my depth in terms of Dax skills however.

 

The OR section seems to be running fine, however when i try to include the AND not contains part, it isnt returning accurate results. Is there something im missing? Also is there a more efficient way of me writing this?

 

Missalocated Activities =
SUMX(
MergedActivities,
IF(
CONTAINSSTRING( MergedActivities[Subject], "Apple" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Microsoft" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Amazon" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Google" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Acer" ) ||
CONTAINSSTRING( MergedActivities[Subject], "HP" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Lenovo" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Samsung" ) &&
NOT(CONTAINSSTRING( MergedActivities[Category], "Active" )
),1,0))
1 ACCEPTED SOLUTION
Fowmy
Super User
Super User

@adam_mac 

You can add a bracket to separate two sets of conditions, ( Check brands ) && (Check Active ) or Use the following meaure


Measure = 
SUMX(
    MergedActivities,
    INT(
        MAXX({"Apple","Microsoft","Amazon","Google","Acer","HP","Lenovo","Samsung"}, SEARCH([Value], MergedActivities[Subject],,0)) > 0 &&
        SEARCH("Active", MergedActivities[Subject],,0) = 0
    ) 
) 
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@adam_mac 

You can add a bracket to separate two sets of conditions, ( Check brands ) && (Check Active ) or Use the following meaure


Measure = 
SUMX(
    MergedActivities,
    INT(
        MAXX({"Apple","Microsoft","Amazon","Google","Acer","HP","Lenovo","Samsung"}, SEARCH([Value], MergedActivities[Subject],,0)) > 0 &&
        SEARCH("Active", MergedActivities[Subject],,0) = 0
    ) 
) 
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Samarth_18
Community Champion
Community Champion

Hi @adam_mac 

 

You can try below code:-

 

Missalocated Activities =
SUMX(
MergedActivities,
IF(
   AND(
     (CONTAINSSTRING( MergedActivities[Subject], "Apple" ) ||
     CONTAINSSTRING( MergedActivities[Subject], "Microsoft" ) ||
     CONTAINSSTRING( MergedActivities[Subject], "Amazon" ) ||
     CONTAINSSTRING( MergedActivities[Subject], "Google" ) ||
     CONTAINSSTRING( MergedActivities[Subject], "Acer" ) ||
     CONTAINSSTRING( MergedActivities[Subject], "HP" ) ||
     CONTAINSSTRING( MergedActivities[Subject], "Lenovo" ) ||
     CONTAINSSTRING( MergedActivities[Subject], "Samsung" )),
     NOT(CONTAINSSTRING( MergedActivities[Category], "Active" )
    )
   ),1,0))

 

Thanks

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

ERD
Community Champion
Community Champion

Hi @adam_mac ,

You need one more pair of brackets:

Missalocated Activities =
SUMX(
MergedActivities,
IF(
(CONTAINSSTRING( MergedActivities[Subject], "Apple" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Microsoft" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Amazon" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Google" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Acer" ) ||
CONTAINSSTRING( MergedActivities[Subject], "HP" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Lenovo" ) ||
CONTAINSSTRING( MergedActivities[Subject], "Samsung" ) ) &&
NOT(CONTAINSSTRING( MergedActivities[Category], "Active" )
),1,0))

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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