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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
schoden
Post Partisan
Post Partisan

IF with text value & AND OPERATOR

Hi All, 

 

Has anyone faced same problem like mine.  I am making new column with IF statement for text value column with condition of AND OPERATOR. 

Although there exist data in dataset , the IF column returns only false or 0 as I have put it. 

 

new column :

IF2 = IF( AND(table[column] = "Mobile Accessories", table[column] = "Mobile Devices"), 1, 0)

 

Data.JPG

Here the dataset has same opportunity with category Mobile devices and Accessories.  

Filter.JPG

 

The column of IF returns only false value as shown above, I am thoroughly confused what could be the reason ?

 

Please share your knowledge.

 

Cheers, 

 

 

1 ACCEPTED SOLUTION

Hi All,

I am posting for others reference as the issue with AND operator is if it is to compare two different columns it works fine but when is to compare two values from same column the AND operator or IN operator doesnt work.

In such case you have to use nested IF.

Cheers.

View solution in original post

7 REPLIES 7
amitchandak
Super User
Super User

@schoden , Or or In is needed

 

IF2 = IF( table[column] in { "Mobile Accessories", "Mobile Devices" }, 1, 0)

 

IF2 = IF( OR(table[column] = "Mobile Accessories", table[column] = "Mobile Devices"), 1, 0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak  Thank you again , the first formula did return both 0 and 1 in the field option but choosing 1  it didnt seem to be fitlering as required.  

 

The filter didn't return only those oppportunities that has both Mobile device and Accessories, it but returned all opportunities either having just Devices or Accessories.

 

As shown in picture, only one opportunity has both device and accessory.

 

YES.JPGone.JPG

 

 

@schoden , if for the same set id (Device) if both are there

IF2 = if(countx(filter(Table, [device] =earlier([device]) && table[column] in { "Mobile Accessories", "Mobile Devices" }) ,[device])+0>=2, 1, 0)

 

Now if the can repeat you need to have a distinct count 

IF2 = if( calculate(distinctcount(table[column]) , filter(Table, [device] =earlier([device]) && table[column] in { "Mobile Accessories", "Mobile Devices" }))+0>=2, 1, 0)

 

Both are new columns 

 

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi @amitchandak 

 

IF2 = if(countx(filter(Table, [device] =earlier([device]) && table[column] in { "Mobile Accessories", "Mobile Devices" }) ,[device])+0>=2, 1, 0)

 

 

Would you explain why [device ]+0>=2,  at the end does ? 

@amitchandak 

 

Hi I used the first formual with opportunity ID which is same for the category of device and Accesssories, It returned the correct list but picked up some opportunity ID with  just devices also still.

 

Return.JPG

Hi All,

I am posting for others reference as the issue with AND operator is if it is to compare two different columns it works fine but when is to compare two values from same column the AND operator or IN operator doesnt work.

In such case you have to use nested IF.

Cheers.

Hi All , 

 

I thought I will share the best solution I found for my issue stated above.  It  works for any issue like one customers purchasing Product A and Product B ..Pretty much like What I was after.

 

After severel internet search, I found an article on Basket Analysis and a video tutorial : 

https://www.youtube.com/watch?v=8PUNpVAiRAE 

 

Cheers, 

Have a good day. 

 

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors