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
Anonymous
Not applicable

IF Statement does not work the way I want

Hello Guys,

 

I want to name category by following way,

 

IF reason code = Unexplained Shrinkage or Unexplained Overage or Previous Adjustment Error or Label/Point of Sale Error and “Tracking #” = Black then it is ACC

 

IF reason code = “Unexplained Shrinkage” or “Unexplained Overage” or “Previous Adjustment Error” or “Label/Point of Sale Error” and “Tracking” # <> Black then it is Hero

 

Please see below, it not working the way I want it. Can any please tell me why is that?

 

Reason = IF(AdjustmentHistory[Reason Code]="Unexplained Shrinkage" || AdjustmentHistory[Reason Code]="Previous Adjustment Error" || AdjustmentHistory[Reason Code]="Label/Point of Sale Error" && AdjustmentHistory[Tracking #] = BLANK(), "ACC", IF(AdjustmentHistory[Reason Code]="Unexplained Shrinkage" || AdjustmentHistory[Reason Code]="Previous Adjustment Error" || AdjustmentHistory[Reason Code]="Label/Point of Sale Error" && AdjustmentHistory[Tracking #] <> BLANK(),"Hero","Others"))

 

Reason column is not correct.Reason column is not correct.

 

Thank you

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

HI @Anonymous

 

You often get unexpected results when you mix OR and AND operators in the same expression.  e.g.

 

A=1 or B=2 or C=3 and D=4

 

is not the same as 

 

A=1 or B=2 or (C=3 and D=4)

 

Note the use of the parenthesis to control the boolean logic.  I suspect some well placed brackets may help you.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

2 REPLIES 2
Phil_Seamark
Employee
Employee

HI @Anonymous

 

You often get unexpected results when you mix OR and AND operators in the same expression.  e.g.

 

A=1 or B=2 or C=3 and D=4

 

is not the same as 

 

A=1 or B=2 or (C=3 and D=4)

 

Note the use of the parenthesis to control the boolean logic.  I suspect some well placed brackets may help you.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

@Phil_Seamark

 

Thank you so much. Brackets did the work. 

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.