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
sakshikaul
Helper III
Helper III

Usage of && and or operator

Newcustomer1 = var A=
(shpm_final_Ver4[TRAFFIC_DEPT]="AI" )||( shpm_final_Ver4[TRAFFIC_DEPT]="OI" ) && shpm_final_Ver4[FINAL_CUSTOMER_NAME]="Dubai" var D= if(A,shpm_final_Ver4[Consignee Name],shpm_final_Ver4[FINAL_CUSTOMER_NAME]) return D

 

above dax is not working properly. I want following output 

sakshikaul_0-1616079984813.png

I am getting following. I am not getting any value . Its blank 

sakshikaul_1-1616080083069.png

 

 

1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@sakshikaul 

For multiple if functions, you may use switch function SWITCH function (DAX) - DAX | Microsoft Docs. 

And I recommend you use || and && instead of using OR() and AND() in the expression.


For this error, you cannot compare text with numerical value in the if function. For example, you comparedA1= 1, but A1 is returning TEXT names, you cannot compare a name =1. 

V-pazhen-msft_1-1616397257315.png

 


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
V-pazhen-msft
Community Support
Community Support

@sakshikaul 

For multiple if functions, you may use switch function SWITCH function (DAX) - DAX | Microsoft Docs. 

And I recommend you use || and && instead of using OR() and AND() in the expression.


For this error, you cannot compare text with numerical value in the if function. For example, you comparedA1= 1, but A1 is returning TEXT names, you cannot compare a name =1. 

V-pazhen-msft_1-1616397257315.png

 


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

PC2790
Community Champion
Community Champion

Hello,

Try tweaking your code as:

 

Newcustomer1 = var A=
OR(shpm_final_Ver4[TRAFFIC_DEPT]="AI",shpm_final_Ver4[TRAFFIC_DEPT]="OI" ) && shpm_final_Ver4[FINAL_CUSTOMER_NAME]="Dubai"

var D= if(A,shpm_final_Ver4[Consignee Name],shpm_final_Ver4[FINAL_CUSTOMER_NAME])

return D

Still getting an error

sakshikaul_1-1616083522943.png

 

 

What error are you getting?

Firstly,The following Dax is giving result  

Newcustomer1 = var A=if(
OR(shpm_final_Ver4[TRAFFIC_DEPT]="AI",shpm_final_Ver4[TRAFFIC_DEPT]="OI" && shpm_final_Ver4[FINAL_CUSTOMER_NAME]="Sourh Africa") ,1,0)

var D= if(A=1,shpm_final_Ver4[Consignee Name],shpm_final_Ver4[FINAL_CUSTOMER_NAME])

return D

But I have multiple conditions present as given below then how to write a dax for this ?

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='Abu Dhabi') ,ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI' ) AND (FINAL_CUSTOMER_NAME='Bahrain') ,ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='Dubai') ,ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI' ) AND ( FINAL_CUSTOMER_NAME='Egypt') ,ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='Iraq') ,ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI' ) AND ( FINAL_CUSTOMER_NAME='Kenya') ,ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='Mozambique' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND ( FINAL_CUSTOMER_NAME='Oman' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI' ) AND ( FINAL_CUSTOMER_NAME='Qatar' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='Saudi Arabia' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='South Africa' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='NAMIBIA' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='SOUTH AFRICA' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND (FINAL_CUSTOMER_NAME='-' ),ConsingeeName,

if((TRAFFIC_DEPT='AI' OR TRAFFIC_DEPT='OI') AND len((FINAL_CUSTOMER_NAME ))<=1,ConsingeeName,



if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='Abu Dhabi') ,ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE' ) AND (FINAL_CUSTOMER_NAME='Bahrain') ,ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='Dubai') ,ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE' ) AND ( FINAL_CUSTOMER_NAME='Egypt') ,ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='Iraq') ,ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE' ) AND ( FINAL_CUSTOMER_NAME='Kenya') ,ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='Mozambique' ),ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND ( FINAL_CUSTOMER_NAME='Oman' ),ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE' ) AND ( FINAL_CUSTOMER_NAME='Qatar' ),ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='Saudi Arabia' ),ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='NAMIBIA' ),ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='SOUTH AFRICA' ),ActualShipperName,


if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='' ),ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='-' ),ActualShipperName,

if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND len((FINAL_CUSTOMER_NAME))<=1,ActualShipperName,


if((TRAFFIC_DEPT='AE' OR TRAFFIC_DEPT='OE') AND (FINAL_CUSTOMER_NAME='South Africa' ),ActualShipperName,FINAL_CUSTOMER_NAME)

))))))))))))))))))))))))) )))) )) AS Newcustomer1

I am getting following error on creating multiple users

sakshikaul_0-1616087658282.png

 

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.