Get column name based on the choice and use it for reference

Hi guys!
Have you ever needed to choose different reference column names for formula?
I will try to desribe what I want to achieve.

I have table for products and prices, but I need more than just 1 price for each product and then I have a choice column which could switch what column to choose for the formula.
Each price column depends on which date it was published, so I don´t want to have all prizes actual, because I want to compare old prize and new one.

formula is something like: products.price * number
I need my formula to dynamicaly change “.price” to “.price5” or whatever I choose from choice column.

Is it possible? I can´t get it to work :slight_smile:

You should be able to use the following Python to grab a dynamic column name: getattr(rec, 'price'+$choice) * $number

rec is a special variable for the current row (“record”)

getattr lets you do rec.price5 with price5 as a string instead of as a literal property of the record: getattr(rec, "price5") == rec.price5

You can combine a base string with a column value (or just use a column value) as the second attribute of getattr: getattr(rec, "price"+$choice)

Then, once you have the dynamic column’s value, you can do anything else with it, like multiplying it by $number