Jump 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.

Conditional count function ?

Featured Replies

Hello,

Is there a way to make a conditional count using a single script ?

For example:

Count ((Invoices::Balance) > 0 )

The above line is not accepted. The intension is to count all records whose balance is non zero.

Of course this could be done by setting a seperate calculation field as a flag and then counting the flags .... but can it be done more elegantly by script without introdusing new fields?

I'm slightly puzzled here, the payment is done in the table for invoices? Are you accepting partial payments for one invoice?

Well

Show All Records 

Go to Record/Request/Page [ Last ] 

Loop 

     If [ invoices::Total > invoices::Payment ] 

           Omit Record 

    Else 

           Go to Record/Request/Page [ Previous; Exit after last ] 

    End If 

End Loop 

Show Omitted Only 

Show Custom Dialog [ Title: "Invoices whose balance is non zero."; Message: Get ( FoundCount ); Buttons: “OK” ] 

Show All Records 

--sd

  • Author

SD,

Thank you for this hint. I will give it a try using your script suggestion.

About the invoices (sorry to confuse you) it was chosen by way of example. In reality it is the "projects" table and tracks all info about a project including total value and payments received to date. So we need to know (just as a statistic) how many projects still have outstanding balances.

Again, many thanks for your help :B

Best Regards,

Thomas

For a "live", self-updating calculation, you need to add that extra field.

If you prefer a static snapshot, you can simply do a find for >0 in the Balance field.

  • Author

For a "live", self-updating calculation, you need to add that extra field.

If you prefer a static snapshot, you can simply do a find for >0 in the Balance field.

Thank You.

Yes, "live self-updating" calculations are always a high priority. This particular count will be a numeral (live statistic) on top of a portal.

Regards,

Thomas

This:

For a "live", self-updating calculation, you need to add that extra field.

...kind of defeats the object with this:

but can it be done more elegantly by script without introdusing new fields?

...but whether it's more or less elegant, won't I be the judge!

--sd

...Alternatively, you could add an extra field in your related table: Calc field, with result:

If(Balance = 0 ; "" ; "A")

And then count this from your other side.

The reason this will work is because count only counts records where that field is not empty.

~Genx

Oh right... no new fields.. oops..

Still, i dont see whats so bad about adding an extra field...

Create an account or sign in to comment

Important Information

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

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.