Help

Re: Creating an IF statement to return values under certain conditions

Solved
Jump to Solution
5101 1
cancel
Showing results for 
Search instead for 
Did you mean: 
Christyan_Matos
5 - Automation Enthusiast
5 - Automation Enthusiast

I need to create an IF statement that works with the following logic:

If the value of column X is less than the value of column Y, it needs to return the value of column X.

If the value of column X is greater than the value of column Y, the IF statement needs to subtract the value of column Y by the value of column X.

Can someone please help?

1 Solution

Accepted Solutions
momentsgoneby80
7 - App Architect
7 - App Architect

Hi @Christyan_Matos!
First, I’ve opened this topic a few times and seeing that a) @Vivid-Squid had answered and b) seen that your response contained a quote block, I erroneously thought the question remaining the same. I’m sure a few others have done the same for the same reason. It helps when people only use the quote function when the text within the quote block remains the exact same as the quoted text. If you supply new text or info, do that outside of a quote block.

IF formulas work like this

IF({Condition},
	{condition is true},
	{condition is false}
)

Outputs of an IF formula can be text, a field value or an action.
If text you write the text within quotation marks, e.g. 'desired output'
If field value you wrap the desired field name within curly brackets, e.g. {field name}.
If action you simply type your desired formula, e.g. desired formula

You can nest IF statements, like in your case

IF({is X greater than the value of column Y},
	[True] {Y},
	[False] IF({is X equal to Y},
		[True] {X},
		[False] {X}
	)
)

[True] and [False] are there for teaching purposes and should not be there in the actual formula.

Using this; in your case the formula then ends up being

IF(X>Y,
	Y,
	IF(X=Y,
		X,
		X
	)
)

When you understand the basics you can simplify your formula. In case of comparing numbers Airtable allows us to use >= Greater than or equal to and <= Less than or equal to, like @Vivid-Squid did in his answer, which allows us to state your formula as

IF({is Y greater than or equal to X},
	 {X},
	 {Y}
)

And the done formula.

IF(Y>=X,
	X,
	Y
)

You can find all kinds of formula functions here in the formula field reference guide.
I hope that made sense and helped you.

See Solution in Thread

7 Replies 7

Hi @Christyan_Matos
I am happy to help you. One quick question, what do you want to do if X = Y?

Thank you very much for the return, in this case, if it is equal, repeat the value of column X.

Got it, try this.

IF(X<=Y, X, Y-X)

It turned out great, thank you very much.

A question, considering this scenario:

If the value of column X is greater than the value of column Y, an IF statement must return the value of column Y.

If the value of column X is less than the value of column Y, you must return the value of column X.

If X = Y, repeat the value of column X.

Thanks.

momentsgoneby80
7 - App Architect
7 - App Architect

Hi @Christyan_Matos!
First, I’ve opened this topic a few times and seeing that a) @Vivid-Squid had answered and b) seen that your response contained a quote block, I erroneously thought the question remaining the same. I’m sure a few others have done the same for the same reason. It helps when people only use the quote function when the text within the quote block remains the exact same as the quoted text. If you supply new text or info, do that outside of a quote block.

IF formulas work like this

IF({Condition},
	{condition is true},
	{condition is false}
)

Outputs of an IF formula can be text, a field value or an action.
If text you write the text within quotation marks, e.g. 'desired output'
If field value you wrap the desired field name within curly brackets, e.g. {field name}.
If action you simply type your desired formula, e.g. desired formula

You can nest IF statements, like in your case

IF({is X greater than the value of column Y},
	[True] {Y},
	[False] IF({is X equal to Y},
		[True] {X},
		[False] {X}
	)
)

[True] and [False] are there for teaching purposes and should not be there in the actual formula.

Using this; in your case the formula then ends up being

IF(X>Y,
	Y,
	IF(X=Y,
		X,
		X
	)
)

When you understand the basics you can simplify your formula. In case of comparing numbers Airtable allows us to use >= Greater than or equal to and <= Less than or equal to, like @Vivid-Squid did in his answer, which allows us to state your formula as

IF({is Y greater than or equal to X},
	 {X},
	 {Y}
)

And the done formula.

IF(Y>=X,
	X,
	Y
)

You can find all kinds of formula functions here in the formula field reference guide.
I hope that made sense and helped you.

Thank you very much, it was very provocative and made me understand once and for all the use of the function.