Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

How do I write a calculation?

Featured Replies

How do I write a calculation?

I am new on write calculation.

I have a database where I keep record of the registration and workshop,

The registration fields are F1, F2, and F3 and the workshop fields are

W1, W2, W3, and W4

How do I write a calculation

If I am register to any of (F1, F2, or F3) and NONE of the W1, W2, W3, or W4

I would check the radio button as “Registration Only”

If I a register to any of (F1, F2, or F3) and any of W1, W2, W3, or W4

I would check the radio button as “Registration and workshop

If I am not register and only attend any of the workshop

I would check the radio button as “Workshop Only”

Any help will be appreciated!

php2005,

Well there are a lot of ways to do this. How 'bout a Let statement because it will allow us to break this into smaller chunks and make it a little easier to understand.

Let ( [

reg = case( (F1 & F2 & F3) = "" ; 0 ; 1 );

wks = case( (W1 & W2 & W3 & W4) = "" ; 0 ; 2 )

] ;

choose( reg + wks ; "None"; "Registration Only";"Workshop Only";"Registration and Workshop")

)

In a nutshell, I concatenate the two sets of fields and check to see if they have any value. Based on the result, I set a variable to a number so can later add the variables and come up with a unique sum for each possible which I can then use to pick the text I want using a choose function.

Regards, Don

  • Author

Hi Don,

Thank you for your help.

I have the following calculation:

Case ( not IsEmpty (Registration) and IsEmpty ( Workshop ); "Conference Only")&

Case ( not IsEmpty (Registration) and not IsEmpty (Workshop); "Conference and Workshop")&

Case ( IsEmpty (Registration) and not IsEmpty (Workshop); "Workshop Only")&

And my problem now is how do I add a case statement if in case the value of Registration be equal to “Pre-Conference” and not IsEmpty(Workshop); “Pre-Conference Only”)

it will show up Pre-Conference only at the field.

Thank you.

I think that Case evaluates until it encounters the first condition only so "and" statement does not make much sense in it - I learned that here on the forums so an If statement would be much better in this case OR I got it wrong.

I might be wrong, get a second opinion before taking any of my advice.

If ( not IsEmpty (Registration) and IsEmpty ( Workshop ); "Conference Only" ; "")

Anuviel - you're right in terms of the case only evaluating until it matches a condition but maybe not in the way you think:

Case( Condition1 ; Result1 ;

Condition2 ; Result2 ;

ConditionN ; ResultN ;

Default If No Conditions Met )

If condition1 is met, then the case function short circuits and throws out Result1 - Condtions2 to n aren't checked because Condition1 evaluated to true.

Conditions can be anything however - the primary thing that is evaluated is whether the expression produces a true or false result:

IsEmpty("") and IsEmpty("") would for example produce true and so Result1 would be thrown out.

The If statement can really be replaced by a single case statement if you really wanted, though it may become less clear:

Case( condition ; true ; false )

If( condition ; true ; false )

PHP 2005 - A case statement evaluates multiple conditions, not one set at a time, so you're statement could be written as:

Case ( IsEmpty (Registration & Workshop); "" ;

IsEmpty ( Workshop ) ; "Conference Only";

IsEmpty (Registration); "Workshop Only";

"Conference and Workshop")

Don - the function's great, but don't use = "" to try and work out if a string is empty:

Let ( [

reg = case( IsEmpty(F1 & F2 & F3) ; 0 ; 1 );

wks = case( IsEmpty(W1 & W2 & W3 & W4) ; 0 ; 2 )

] ;

choose( reg + wks ; "None"; "Registration Only";"Workshop Only";"Registration and Workshop")

)

End random reply :

Edited by Guest

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.