cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
shilpikumari_11 Regular Visitor
Regular Visitor

using Contains and multiple conditions with OR

I have below formula and I have tried DAX contains and search functions, nothing is giving desired output, please suggest.

 

Job Category = 

IF
contains([Job Group],'Materials Management')
OR contains([Job Group],'Logistics')
OR contains([Job Group],'Distribution')
then 'Distribution'
ELSEIF
contains([Job Group],'Procurement')
OR contains([Job Group],'Categories')
OR contains([Job Group],'Geographic')
OR contains([Job Group],'Processes')
then
'Procurement and Sourcing'
ELSEIF
contains([Job Group],'Engineering & Construction')
then
'Facilities'
ELSE 'N/A'
END

1 ACCEPTED SOLUTION

Accepted Solutions
zuheirashraf17 New Member
New Member

Re: using Contains and multiple conditions with OR

Hi Shilpi,

 

I tested it and this should be working fine.

Do let me know if you need further explanation for this;

 

Category = SWITCH(TRUE(),
                    IF(SEARCH("Materials Management", [Job Group], 1, 0) > 0 || SEARCH("Distribution", [Job Group], 1, 0) > 0 || SEARCH("Distribution", [Job Group], 1, 0) > 0
                        ,TRUE()
                        ,FALSE()
                        ),"Distribution",
                    IF(SEARCH("Procurement", [Job Group], 1, 0) > 0 || SEARCH("Categories", [Job Group], 1, 0) > 0 || SEARCH("Geographic", [Job Group], 1, 0) > 0 || SEARCH("Processes", [Job Group], 1, 0) > 0
                        ,TRUE()
                        ,FALSE()
                        ),"Procurement and Sourcing",
                    IF(SEARCH("Engineering & Construction", [Job Group], 1, 0) > 0 
                        ,TRUE()
                        ,FALSE()
                        ),"Facilities",
                    "N/A"                  
)
    
5 REPLIES 5
Super User
Super User

Re: using Contains and multiple conditions with OR

That looks like a mix of DAX and M. And CONTAINS takes 3 parameters, Table, Column, Value. I would use a SWITCH though like:

 

Job Category = 
SWITCH(TRUE(),
  CONTAINS('Table',[Job Group],'Materials Management') 
|| CONTAINS('Table',[Job Group],'Logistics')
|| CONTAINS('Table',[Job Group],'Distribution')
,'Distribution',
CONTAINS('Table',[Job Group],'Procurement')
|| CONTAINS('Table',[Job Group],'Categories')
|| CONTAINS('Table',[Job Group],'Geographic')
|| CONTAINS('Table',[Job Group],'Processes')
,'Procurement and Sourcing',
CONTAINS('Table',[Job Group],'Engineering & Construction')
,'Facilities',
'NA'
)

Did I answer your question? Mark my post as a solution!

Proud to be a Datanaut!


shilpikumari_11 Regular Visitor
Regular Visitor

Re: using Contains and multiple conditions with OR

Thanks Greg, unfortunately, this is not giving the desired output, its only passing the last condition, below is the snapshot. when I used it the if and contains, it gave me almost the same result, it only passes the last condition.

 

Power BI error Job category.PNG

v-danhe-msft Super Contributor
Super Contributor

Re: using Contains and multiple conditions with OR

Hi @shilpikumari_11,

Could you please offer some sample file to have a test and post your desired result if possible?

 

Regards,

Daniel He

Community Support Team _ Daniel He
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
zuheirashraf17 New Member
New Member

Re: using Contains and multiple conditions with OR

Hi Shilpi,

 

I tested it and this should be working fine.

Do let me know if you need further explanation for this;

 

Category = SWITCH(TRUE(),
                    IF(SEARCH("Materials Management", [Job Group], 1, 0) > 0 || SEARCH("Distribution", [Job Group], 1, 0) > 0 || SEARCH("Distribution", [Job Group], 1, 0) > 0
                        ,TRUE()
                        ,FALSE()
                        ),"Distribution",
                    IF(SEARCH("Procurement", [Job Group], 1, 0) > 0 || SEARCH("Categories", [Job Group], 1, 0) > 0 || SEARCH("Geographic", [Job Group], 1, 0) > 0 || SEARCH("Processes", [Job Group], 1, 0) > 0
                        ,TRUE()
                        ,FALSE()
                        ),"Procurement and Sourcing",
                    IF(SEARCH("Engineering & Construction", [Job Group], 1, 0) > 0 
                        ,TRUE()
                        ,FALSE()
                        ),"Facilities",
                    "N/A"                  
)
    
Highlighted
shilpikumari_11 Regular Visitor
Regular Visitor

Re: using Contains and multiple conditions with OR

Thanks, this worked!

Helpful resources

Announcements
Back to School Contest

Back to School Contest

Engage and empower students with Power BI!

MBAS Gallery

Watch Sessions On Demand!

Continue your learning in our online communities.

Summit Australia 2019

Summit Australia 2019

Travel to Melbourne and network with thousands of peers!

PBI Community Highlights

PBI Community Highlights

Check out what's new in the Power BI Community!

Top Ideas
Users Online
Currently online: 125 members 1,362 guests
Please welcome our newest community members: