Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use the condition of an If statement as its value?

This could be a simple question, but it's one I've never seen answered before. Is there a way to use an if statement's condition as its value? This would be really useful in cases where lots of calculation is done to determine if a certain condition is met and if it is, that calculation is the result.

As an example:

if ( [intense calculation] > 0, [same intense calculation], 0)

I'm interested particularly with regards to SQL, as I'm working on a report in Access right now and so can't store the result of the intense calculation in a variable.

like image 662
Will Avatar asked Dec 16 '11 15:12

Will


People also ask

How do you write an IF THEN formula in Excel?

Use the IF function, one of the logical functions, to return one value if a condition is true and another value if it's false. For example: =IF(A2>B2,"Over Budget","OK") =IF(A2=B2,B4-A4,"")

How do you write an if statement with condition?

OR – =IF(OR(Something is True, Something else is True), Value if True, Value if False) NOT – =IF(NOT(Something is True), Value if True, Value if False)

How do you write an IF THEN formula in Excel with multiple criteria?

Another way to get an Excel IF to test multiple conditions is by using an array formula. To complete an array formula correctly, press the Ctrl + Shift + Enter keys together. In Excel 365 and Excel 2021, this also works as a regular formula due to support for dynamic arrays.

Can you put a formula in an IF function?

As a worksheet function, the IF function can be entered as part of a formula in a cell of a worksheet. It is possible to nest multiple IF functions within one Excel formula. You can nest up to 7 IF functions to create a complex IF THEN ELSE statement.


1 Answers

Not sure if such a concept exists in the MS Access report world, but how about:

MAX([intense calculation], 0)

The obvious benefit of such an approach is that the calculation would only need to be done once.

like image 189
Ben Hoffstein Avatar answered Oct 13 '22 00:10

Ben Hoffstein