We are celebrating the 10-year anniversary of the Alteryx Community! Learn more and join in on the fun here.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Malformed IF Statement

Happylife2025
7 - Meteor

May I know what is wrong in the below nested else if statement and how to correct it? it gives me error of malformed if statement

IF [RecordID] = 7 THEN
[Row-1:wgt_AUD] + [Row-2:wgt_AUD] + [Row-3:wgt_AUD] + [Row-4:wgt_AUD] + [Row-5:wgt_AUD]
ELSEIF [RecordID] = 12 THEN
[Row-1:wgt_AUD] + [Row-2:wgt_AUD] + [Row-3:wgt_AUD]
ELSEIF [RecordID] = 17 THEN
[Row-1:wgt_AUD] + [Row-2:wgt_AUD] + [Row-3:wgt_AUD]
ELSEIF [RecordID] = 18 THEN
[Row-1:wgt_AUD] + [Row-6:wgt_AUD] + [Row-11:wgt_AUD]
ELSEIF [RecordID] = 39 THEN
[Row-32:wgt_AUD]
ELSEIF [RecordID] = 40 THEN
[Row-28:wgt_AUD]
ELSEIF [RecordID] IN (41, 42) THEN
[Row-24:wgt_AUD]
ELSEIF [RecordID] = 43 THEN
[Row+94:wgt_AUD]
ELSEIF [RecordID] = 44 THEN
[Row+202:wgt_AUD]
ELSEIF [RecordID] = 45 THEN
MAX(([Row-2:wgt_AUD] - [Row-1:wgt_AUD]) * [Row+9:wgt_AUD] - [Row-3:wgt_AUD], 0)
ELSEIF [RecordID] = 46 THEN
MAX(
IF([Row-1:wgt_AUD] = 0,
0,
[Row-1:wgt_AUD] - MAX([Row-3:wgt_AUD] - [Row-2:wgt_AUD], 0) * MAX(0, 0.25 - (1 - [Row-7:wgt_AUD]))
),
0)
ELSE
[wgt_AUD]
ENDIF

9 REPLIES 9
Mathias_Nielsen
9 - Comet

Hi,

 

Usually it  will say at what character it encountered the error, see attached.

I know your formula is quite long, so counting towards the error can take some time perhaps. This has helped me in the past atleast :)

Happylife2025
7 - Meteor

@Mathias_Nielsen  thanks for replying. I know where the error is but dont know how to correct it. The error comes from the below statement.

 

ELSEIF [RecordID] = 46 THEN 
    MAX(
        IF([Row-1:wgt_AUD] = 0, 
            0, 
            [Row-1:wgt_AUD] - MAX([Row-3:wgt_AUD] - [Row-2:wgt_AUD], 0) * MAX(0, 0.25 - (1 - [Row+7:wgt_AUD]))
        ), 
        0
    )
Gaurav_Dhama_
12 - Quasar

I am surprised that you are getting malformed "if function" rather than "unknow variable" error.

Since you are referring to rows before, this must be in Multi Row formula, but multi row formula allows reference to only 1 row above or before. So, it might be this that is causing the error. But a little bit of more context will help.

 

Which version of Alteryx are you using?

Happylife2025
7 - Meteor

@Gaurav_Dhama_ , I have successfully ran all the codes before using multirow formula the above statement and it runs find and working as expected. only when I use else if and nested if within that it gives me this error. I think mostly it is some syntax error .

Gaurav_Dhama_
12 - Quasar

That's surprising, because the moment I put this formula in my designer, I get unknown variable 

[Row-2:wgt_AUD]

However,

The error is really in syntax. try using the one below:

IF [RecordID] = 7 
THEN
[Row-1:wgt_AUD] + [Row-2:wgt_AUD] + [Row-3:wgt_AUD] + [Row-4:wgt_AUD] + [Row-5:wgt_AUD]

ELSEIF [RecordID] = 12 THEN
[Row-1:wgt_AUD] + [Row-2:wgt_AUD] + [Row-3:wgt_AUD]

ELSEIF [RecordID] = 17 THEN
[Row-1:wgt_AUD] + [Row-2:wgt_AUD] + [Row-3:wgt_AUD]

ELSEIF [RecordID] = 18 THEN
[Row-1:wgt_AUD] + [Row-6:wgt_AUD] + [Row-11:wgt_AUD]

ELSEIF [RecordID] = 39 THEN
[Row-32:wgt_AUD]

ELSEIF [RecordID] = 40 THEN
[Row-28:wgt_AUD]

ELSEIF [RecordID] IN (41, 42) THEN
[Row-24:wgt_AUD]

ELSEIF [RecordID] = 43 THEN
[Row+94:wgt_AUD]

ELSEIF [RecordID] = 44 THEN
[Row+202:wgt_AUD]

ELSEIF [RecordID] = 45 THEN
MAX(([Row-2:wgt_AUD] - [Row-1:wgt_AUD]) * [Row+9:wgt_AUD] - [Row-3:wgt_AUD], 0)

ELSEIF [RecordID] = 46 THEN
MAX(
    IF [Row-1:wgt_AUD] = 0 THEN
    0 
    else 
        [Row-1:wgt_AUD] - MAX([Row-3:wgt_AUD] - [Row-2:wgt_AUD], 0) * MAX(0, 0.25 - (1 - [Row-7:wgt_AUD]))
    ENDIF
)
ELSE
[wgt_AUD]
ENDIF

 

Gaurav_Dhama_
12 - Quasar

For reference,

The formula inside Max was following the syntax of a programming language 

if(condition, "then do this", "else do this")

however, Alteryx would need 

If condition then "Do this" else "Do that" endif

 

alexnajm
18 - Pollux
18 - Pollux

@Gaurav_Dhama_ you can increase the number of rows to look up and down in the Multi-Row Formula tool! Right next to "Value for Rows that Don't Exist" 😊

Happylife2025
7 - Meteor

Thanks @Gaurav_Dhama_  I made a slight change in the outer max condition and it works.

 

ELSEIF [RecordID] = 46 THEN
MAX(
(IF [Row-1:wgt_AUD] = 0 THEN
0
else

[Row-1:wgt_AUD] - MAX([Row-3:wgt_AUD] - [Row-2:wgt_AUD], 0) * MAX(0, 0.25 - (1 - [Row-7:wgt_AUD]))

ENDIF),0
)

Gaurav_Dhama_
12 - Quasar

Glad it helped @Happylife2025 , you can mark it as solved, to close the thread.

Labels
Top Solution Authors