ACT NOW: The Alteryx team will be retiring support for Community account recovery and Community email-change requests Early 2026. Make sure to check your account preferences in my.alteryx.com to make sure you have filled out your security questions. Learn more here
Start Free Trial

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
解決済み

AND IF Statements in Formula

henrygeorge
アステロイド

Hi Alteryx Team 

I have a file that if it meets certain criteria the number should be added by 1

 

Age IndianAmtType
1Yes28000000Match
10No36000000Match

 

So I placed the formula tool on my canvas and wrote this (for output column choosen as Age) - 

IF [Indian]="Yes"
AND IF [Type]="Match"
AND IF [Amt]>=20000000
THEN [Age]+1
ELSE [Age]+0
ENDIF

 

But I get a Data Preview as 'MAlformed If Statement'

 

The output required is - 

AgeIndianAmtType
2Yes28000000Match
10No36000000Match

 

 

5件の返信5
ScottE
Alteryx Alumni (Retired)

hi @henrygeorge 

 

You don't need the extra "IFs" in there.  It should look like this.

 

if [indian]='yes' and [type]='match' and [amt]>=20000000 then [age]+1 else [age] endif

 

Hope that helps.

Thableaus
17 - Castor
17 - Castor

Hi @henrygeorge 

 

Tip: if you remove your extra IF's and just leave the first one, it might work 🙂

 

Cheers,

henrygeorge
アステロイド

Hi @Thableaus @ScottE 

 

So I applied the formula and it worked great without the extra Ifs, but when it comes to negative number

Age IndianAmtType
1Yes-28000000Match
10No36000000Match

 

and using this in formula tool 

IF [Indian]="Yes"
AND [Type]="Match"
AND [Amt]>=20000000
THEN [Age]+1
ELSE [Age]+0
ENDIF

 

The output arrives at 

AgeIndianAmtType
1Yes-28000000Match
10No36000000Match

 

while for negative numbers above 20000000 it should add to the age. Like so -

AgeIndianAmtType
2Yes-28000000Match
10No36000000Match

 

How do I arrive at this output even with negative numbers??

henrygeorge
アステロイド
 
markcurry
クエーサー

Within your formula, convert the [Amt] field to positive and use that in your condition....

 

 (IIF([Amt] < 0 ,[Amt] * -1, [Amt] )  >= 20000000

 

So ...

 

IF [Indian]="Yes"
AND [Type]="Match"
AND (IIF([Amt]<0,[Amt]*-1,[Amt])) >= 20000000
THEN [Age]+1
ELSE [Age]
ENDIF

 

 

ラベル
トップのソリューション投稿者