# Re: Formula to return multiple values

Solved
1465 1
cancel
Showing results for
Did you mean:
5 - Automation Enthusiast

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!

1 Solution

Accepted Solutions
10 - Mercury

Here you go 🙂

``````REGEX_REPLACE(
IF(OR({Apples}, {Bananas}, {Limes}), 'Fruit, ', '') &
IF(OR({Mushrooms}, {Carrots}, {Squash}, {Ginger}), 'Vegetables, ', '') &
IF(OR({Rosemary}, {Thyme}), 'Herbs, ', '')
,
'[, ]*\$',
''
)``````
4 Replies 4
10 - Mercury

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

5 - Automation Enthusiast

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?

10 - Mercury

Here you go 🙂

``````REGEX_REPLACE(
IF(OR({Apples}, {Bananas}, {Limes}), 'Fruit, ', '') &
IF(OR({Mushrooms}, {Carrots}, {Squash}, {Ginger}), 'Vegetables, ', '') &
IF(OR({Rosemary}, {Thyme}), 'Herbs, ', '')
,
'[, ]*\$',
''
)``````
5 - Automation Enthusiast

Yes that's perfect, thank you @Stephen_Orr1 !