Alteryx Designer Desktop Discussions

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

IF Function

carterfleming
8 - Asteroid

Trying to write an IF function that will say "if [transaction type] = "Void" or if [transaction type] = "Refund" then [Purchase Amount] *-1

 

Basically trying to say if Transaction Type column is Void or Refund then I need the Purchase Amount column to be multiplied by -1. Any tips?

5 REPLIES 5
Matthew
11 - Bolide

you've already got it, you just need to finish the statement with "endif"

 

you also need and "else" statement to cover cases where the if statement is false

 

if [Txn Type] = 'Void' or [Txn Type] = 'Refund' then

[Purchase Amt] * -1

else

[Purchase Amt]

Endif

DataNath
17 - Castor

You need to provide an 'ELSE' clause i.e. what to do if the txn type isn't void or refund, and then end your statement with 'ENDIF' to finish. Something like this for example:

 

IF [Txn Type] IN ('Void','Refund') THEN -[Purchase Amt] ELSE [Purchase Amt] ENDIF

 

The above will just return the Purchase Amount as normal (not multiplied by -1) if the Txn Type isn't void or refund. I've also used the 'IN' function so you can just provide a list of possibilities instead of constantly having to type out 'or Field Name = Value'.

Robin_McIntosh
11 - Bolide

**Edit - Sorry, didn't realize @DataNath already provided the suggestion of IN(....)

 

In addition to @Matthew and @DataNath, you can simplify by saying If [Txn Type] in('Void','Refund') Then...

carterfleming
8 - Asteroid

carterfleming_0-1658324548329.png

Still getting errors

Robin_McIntosh
11 - Bolide

You need to name the new column.

 

Robin_McIntosh_0-1658324632255.png

 

Labels