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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
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.