Search code examples
powerbipowerquery

multi conditional for conditional column power query


I need to create a new column based on multiple conditions.

I have below code works but doest no give correct values. what I want is: when status is rejected the value is return reason when status is Quality-Reject the value is Quality-Rejection Reason when status is Quality-Reject and "Quality-Rejection Reason" is blank then the value is remarks else is 0 as I dont need it.

if [Status] = "Rejected" then [Return Reason] 
else if [Status] = "Quality-Reject" then [#"Quality-Rejection Reason"] 
else if [Status] = "Quality-Reject" and [#"Quality-Rejection Reason"] = 0 then [Remarks] 
else 0

the problem is that it doesnt see the "AND" condition.


Solution

  • It's because if the status is Quality-Reject, the output will be #"Quality-Rejection Reason". It will never reach the third situation.

    maybe you can switch the second line and third line to have a try

    if [Status] = "Rejected" then [Return Reason] 
    else if [Status] = "Quality-Reject" and [#"Quality-Rejection Reason"] = 0 then 
    else if [Status] = "Quality-Reject" then [#"Quality-Rejection Reason"] 
    [Remarks] 
    else 0