Save the date! Join us on October 16 for our Product Ops launch event. Register here.
Jun 21, 2023 10:43 AM
I have data that essentially looks like this:
I want to use a formula to populate the last column with the type (in my example, food) based on whether or not other cells in the row are greater than 0. So IF (column A, B or C is >0, return "Fruit") AND IF (Column D>0, return "Fungus" and so on). I can get it to return one of the types but not all. Ideally they would be separated by a comma.
I also sometimes have a blank cell and sometimes I have a 0. I know I can do a simple IF statement and have columns for each type, but is there a way to do this in one column?
Thank you for your patience, I am new to airtable and airtable formulas!
Solved! Go to Solution.
Jun 21, 2023 11:26 AM
Here you go 🙂
REGEX_REPLACE(
IF(OR({Apples}, {Bananas}, {Limes}), 'Fruit, ', '') &
IF(OR({Mushrooms}, {Carrots}, {Squash}, {Ginger}), 'Vegetables, ', '') &
IF(OR({Rosemary}, {Thyme}), 'Herbs, ', '')
,
'[, ]*$',
''
)
Jun 21, 2023 11:10 AM
Hi @lcar,
Try this
REGEX_REPLACE(
IF({Apples}, 'Apples, ', '') &
IF({Bananas}, 'Bananas, ', '') &
IF({Limes}, 'Limes, ', '') &
IF({Mushrooms}, 'Mushrooms, ', '') &
IF({Carrots}, 'Carrots, ', '') &
IF({Squash}, 'Squash, ', '') &
IF({Ginger}, 'Ginger, ', '') &
IF({Rosemary}, 'Rosemary, ', '') &
IF({Thyme}, 'Thyme, ', '')
,
'[, ]*$',
''
)
-Stephen
Jun 21, 2023 11:21 AM
Thank you @Stephen_Orr1 ! That is close. I slightly changed your formula to give me "fruit" rather than "apples" and "vegetables" rather than "carrots" and so on. So consequently if I have 4 applies and 2 bananas say, the output gives me: "Fruit, Fruit" and I only need it written once. Any way to get around that?
Jun 21, 2023 11:26 AM
Here you go 🙂
REGEX_REPLACE(
IF(OR({Apples}, {Bananas}, {Limes}), 'Fruit, ', '') &
IF(OR({Mushrooms}, {Carrots}, {Squash}, {Ginger}), 'Vegetables, ', '') &
IF(OR({Rosemary}, {Thyme}), 'Herbs, ', '')
,
'[, ]*$',
''
)
Jun 21, 2023 11:32 AM
Yes that's perfect, thank you @Stephen_Orr1 !