0

Could any one please help me converting the below IF conditions to a list. Each IF condition has one IF block, one 'then' (separated by comma) block and one 'else block'. Nothing really worked close so far.

single IF condition looks like this:

IF(IN(COL1, 'val'), COL2, COL3)

Real-time scenario has nested conditions like this

IF(IN(COL1, 'val1'), 'A', IF(COL2 = 'val2', IF(COL3 = 'val3', 'B', 'C'), 'D')

Looking for a nested list for every IF condition with 'then' and 'else' as separate items like these: ('then' and 'else' can be another IF statement that should follow the same listing process)

["IF(IN(COL1, 'val1')", 'A', ["IF(COL2 = 'val2'", ["IF(COL3 = 'val3'", 'B', 'C'], 'D']]

or

["IN(COL1 = 'val1'", 'A', ["COL2 = 'val2'", ["COL3 = 'val3'", 'B', 'C'], 'D']]
4
  • 2
    Can you demonstrate any effort at solving this yourself? Commented Mar 8, 2020 at 13:49
  • I would suggest having a look at the formulas library... Don't reinvent the wheel (without a good reason) Commented Mar 8, 2020 at 13:53
  • I was able to do this by replacing the braces comes with IN condition to curly braces first. Then I used this as reference to change all the IF statements into a corresponding lists. stackoverflow.com/questions/23185540/… Commented Mar 9, 2020 at 15:37
  • with this one change in the code - def parse_nested(text, left=r'IF[(]', right=r'[)]', sep=r',(?![^{]*[}])'): Commented Mar 9, 2020 at 15:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.