This site uses different types of cookies, including analytics and functional cookies (its own and from other sites). To change your cookie settings or find out more, click here. If you continue browsing our website, you accept these cookies.
Hi, I'm interested in slimming down my formulas. Is there any OOP approach to storing column names into a variable? Something like storing [SPOUSE_AGE] into variable x and calling if-statements on that x (which would be simply calling [SPOUSE_AGE]. This would allow me to use x interchangeably for multiple fields.
An example of the snip-it of code I'm trying to slim down is below. I could reduce the amount of lines in this code by half if I can have a conditional if-statement to store [SPOUSE_AGE] or [SELF_AGE] into variable x, and just running x against the conditional statements rather than repeating such statements twice for both fields.
To my knowledge the closest thing you can do to storing a column name as a variable would be to create a new column [X] as the first formula in a formula tool, and setting it as the appropriate data type, with a formula of [SPOUSE_AGE], or whatever your field would be.
Then you could use that field in future formulas. You would want to use a Select tool after this point to clean up that variable by deselecting [X].
A little more specifically to your use case, a formula for field X with the following expression:
IF ISNULL([SPOUSE_AGE]) THEN [SELF_AGE] ELSE [SPOUSE_AGE] ENDIF
And then writing your IF categorization statement against column [X] instead of SPOUSE_AGE and SELF_AGE
Then you can deselect [X] in the next step.
This is potentially less efficient than the programmatic aliasing you reference here (I can't speak to the inner workings and optimization of the Alteryx engine in cases like this), but especially if the data is only used for this one step I doubt it would impact performance in a significant way.