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.

Need a more elegant calculation than what's planned

Featured Replies

Howdy, howdy:

 

I have this calc on the 3DBB: 

 

Truncate (

 

    (
        AdaptsToNewSituations1__lxn + 
        ControlsEmotions1__lxn + 
        DemonstratesProblemSolvingSkills1__lxn + 
        DisplaysSelfConfidence1__lxn +
        SharesTakesTurnAndCooperatesWithPeers1__lxn + 
        TakesCareOfPersonalProperty1__lxn ) / 6 ; 1
     )
 
 
The calc works, but it has a serious flaw: it assumes that all six fields will have data in them before an average is calculated. But what if one of them is empty? I don't want to "hard code" the number, 6, in the calc because then the average will be thrown off if one or more fields are empty. Rats.
 
What's a more elegant/functional way of coding this? I thought of using/creating a summary field and working off that, but with over 100 fields it's going to get ugly really fast...unless, of course, that's the best way of getting the job done; ugly I can live with, but unwieldy, no. :)
 
TIA for your suggestions!
 
 

The Count() function counts only non-empty fields in its field list, so

 

Let(

[divisor = count(AdaptsToNewSituations1__lxn; ControlsEmotions1__lxn; DemonstratesProblemSolvingSkills1__lxn ; DisplaysSelfConfidence1__lxn ; SharesTakesTurnAndCooperatesWithPeers1__lxn; TakesCareOfPersonalProperty1__lxn)];

Truncate(

        (AdaptsToNewSituations1__lxn + 
        ControlsEmotions1__lxn + 
        DemonstratesProblemSolvingSkills1__lxn + 
        DisplaysSelfConfidence1__lxn +
        SharesTakesTurnAndCooperatesWithPeers1__lxn + 
        TakesCareOfPersonalProperty1__lxn ) / divisor ; 1
     )
)

You might try this:

 

Let ( [
values = 
  List ( 
  AdaptsToNewSituations1__lxn ; 
  ControlsEmotions1__lxn ; 
  DemonstratesProblemSolvingSkills1__lxn ; 
  DisplaysSelfConfidence1__lxn ; 
  SharesTakesTurnAndCooperatesWithPeers1__lxn ; 
  TakesCareOfPersonalProperty1__lxn
   ) ;
total = Evaluate ( Substitute ( values ; ¶ ; "+" ) )
] ;
Truncate ( total / ValueCount ( values ) ; 1 )
)

How about =

Truncate (
Average (
AdaptsToNewSituations1__lxn ;
ControlsEmotions1__lxn ;
DemonstratesProblemSolvingSkills1__lxn ;
DisplaysSelfConfidence1__lxn ;
SharesTakesTurnAndCooperatesWithPeers1__lxn ;
TakesCareOfPersonalProperty1__lxn
) ; 1 )

 

Not sure why you are using Truncate() and not Round(), for example - or why is it necessary to limit the calc's precision at all.

 

 

I would also question the structure, as it seems that the six parameters would be better represented by six records in a related table, with each record having a field for Type and Values. Then it becomes very simple to compute the average by =

Average ( Parameters::Value )
  • Author

Thank you all!

 

To answer your questions, Comment:

 

1) I suggested the same thing but was instructed to truncate instead of round. Since the calc will be used to calculate GPAs, there's a protocol in our school district that states that rounding isn't allowed. I truncated the number because of field character length limitations; repeating decimals could put a number's length into the ozone. (The result has to appear in its entirety within a box on a State form--need I say more?)

 

2) I'm being hamstrung by a superior who has trouble working with relational databases--he prefers flat as much as possible so he can see what's going on. *sigh* Some people just can't leave Excel behind. :S

Since the calc will be used to calculate GPAs, there's a protocol in our school district that states that rounding isn't allowed.

 

Well, I don't know what your business rules are. I suspect that if it was my average that was being calculated, I would protest against any kind of rounding - and truncating is just another type of rounding.

 

 

I truncated the number because of field character length limitations; repeating decimals could put a number's length into the ozone. (The result has to appear in its entirety within a box on a State form--need I say more?)

 

Actually, Filemaker has a built-in precision limit of 16 decimals (which you can extend using the SetPrecision() function). And number fields can be formatted to display only a preset number of decimals.

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.