# Creating a formula (simple text output) according to a single-select option selected?

@frederikdc (or anyone else from the team - @bram or @olgatrykush) would you help me to configure one extra formula?

I have a singe-select field with just two items to select - “male” and “female”.
I need to create the formula that will generate the proper text according to a single-select item.
F.e. if there is “male” selected, then the formula field should output the text “Dear sir,” and if “female” is selected, then the output text should be “Dear madam,”.

This is probably a very simple thing for you, but I need to gain some more experience.

Btw. is there any web section on the internet (or at baserow website), where the principles for creating formulas, working with them, how to work with syntax, including some examples for a real beginner, like me? I feel I really need and want to learn, how to work with it.

Hey @marcus ,

One of the possible ways to achieve this is by using the `if()` formula where the first parameter is chek the select for one of the possible option:

``````if(totext(field('Single select')) = 'male', 'Dear sir,', 'Dear madam,')
``````
1 Like

The formula above is indeed the one you are looking for.

I can recommend the following to gain a deeper understanding of how formula’s work: Understanding Baserow Formulas // Baserow.

Furthermore, my advice is always to start small. Write a single if() function and check the result before you start nesting elements.

Also, check the documentation of each function. For example: when writing the if() function

You notice it requires 3 parameters:

1. a bool expression that results to true or false
2. what needs to be done if true
3. what needs to be done if false
1 Like

Hey, thanks. It works well.
What if I would like to do one enhancement like this: if there is (for some reason) no single select item selected (I mean, I keep it to be empty), I would like or 1) to add the text “Dear sir, dear madam,” or 2) to keep it empty, so no text. Right now if there is no single-select item, then always “Dear madam,” is used.

To achieve this you can use a nested `if()` clause.
Firstly, you check if a field is empty, if not – you use nested `if` from the example above to check which exact option is selected:

``````if(isblank(field('Single select')), 'Dear sir, dear madam,', if(totext(field('Single select')) = 'male', 'Dear sir,', 'Dear madam,'))
``````
2 Likes

Thank you @AlexP - this is it!

You are welcome, @marcus!