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
Solved! Go to Solution.
@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 )
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?
@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 .
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
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
@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" 😊
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
)
Glad it helped @Happylife2025 , you can mark it as solved, to close the thread.
User | Count |
---|---|
63 | |
28 | |
23 | |
23 | |
22 |