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.
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))
Solved! Go to Solution.
@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
)
)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
@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
)
)
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
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
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!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
46 | |
28 | |
22 | |
12 | |
8 |
User | Count |
---|---|
75 | |
53 | |
46 | |
15 | |
12 |