Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Multiple IF Statement with Multiple AND Statement

quims
8 - Asteroid

HI Alteryx Community,

 

I'm having difficulty when combining IF statement with multiple AND. 

 

Here is my current statements with the incorrect results:

 

IF [Brand] = "EDU" AND
[Brand] = "LOG" AND
[Brand] = "PSW" AND
[Brand] = "PSMW" AND
[Brand] = "PSMC" AND

[COS] =0
THEN [Sales] + [COS]
ELSE ([Total Sales]*[COS])/[Total COS] ENDIF

 

The default is correctly calculated.

 

SO No.SO Line#ItemBrandClassRevenueExpenseTotal RevenueTotal ExpenseAllocationShould beRemarks
111111220AAAPSWVSMW-791678-15821356-791-113Correct
111111410CCCAPPHW-121.2113.71-121.2113.71-121.2-121.2Correct
111111510DDDEDUSVC-4528.673816.44-4528.673816.44-4528.67-712.23Error
111111690EEEEDUSVC-3200-15645156450-320Error
111111710FFFEDUSVC0-1562.40-1562.40-1562.4Error
111111810GGGPSMWSVC-135256.33120000-135256.33120000-135256.33-15256.33Error
111111910HHHPSMWSVC-441.540-441.5400-441.54Error
111112010IIIPSMWVSMW-294762970-294762970-29476-26506Error
111112120JJJPSMWVSMW-8093.820-64714.2200-8093.82Error
111112290KKKPSMCVSMW-2586.290-100303.5400-2586.29Error
1111123100LLLPSMCVSMW-294762970-294762970-29476-26506Error
4 REPLIES 4
danespoors
8 - Asteroid

Hi @quims ,

 

As you have a column containing multiple values that you're looking to test, I would suggest that you use the 'IN' function like so:

 

IF [BRAND] in ("EDU", "LOG", "PSW", "PSMW", "PSMC") AND [cos] = 0 THEN ... 

 

This way it is one column with multiple checks for values.

 

Hope this helps,

 

Dane.

quims
8 - Asteroid

@danespoors 

 

Sorry but the [cos] = 0 is only taking effect for the formula [Revenue] + [Expense]

 

quims

RolandSchubert
16 - Nebula
16 - Nebula

Hi @quims ,

 

I think the problem is connecting the conditions using "AND" - currently the IF-clause is only true, if [Brand] is e.g. both "EDU" and "LOG" - and one of the conditions will not be true (it's "EDU" or "LOG" or ...). 

IF [Brand] = "EDU" OR [Brand] = "LOG" OR [Brand] = "PSW" OR [Brand] = "PSMW" OR [Brand] = "PSMC" OR [COS] = 0 THEN
[Sales] + [COS]
ELSE

([Total Sales]*[COS])/[Total COS]

ENDIF

 

A shorter version would be:

IF [Brand] IN ("EDU", "LOG", "PSW", "PSMW", "PSMC")  OR [COS] = 0 THEN
[Sales] + [COS]
ELSE

([Total Sales]*[COS])/[Total COS]

ENDIF

 

Hope this is helpful.

 

Best,

 

Roland

quims
8 - Asteroid

Wow! Thank you @RolandSchubert,

 

It is now working perfectly!

 

Thank you for the help!

 

Thanks too, @danespoors.

 

quims

Labels
Top Solution Authors