Help

Formula to return multiple values

Topic Labels: Base design Formulas
Solved
Jump to Solution
2108 4
cancel
Showing results for 
Search instead for 
Did you mean: 
lcar
5 - Automation Enthusiast
5 - Automation Enthusiast

I have data that essentially looks like this:

Screen Shot 2023-06-21 at 11.37.20 AM.png

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

Here you go 🙂

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

See Solution in Thread

4 Replies 4

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

lcar
5 - Automation Enthusiast
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?

Here you go 🙂

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

Yes that's perfect, thank you @Stephen_Orr1 !