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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors