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.

Counting with two specific values

Featured Replies

I'm trying to count related records (within the same table) where two values are met. The first value is a serial number (Serial), the second value is a "1" (flag). 

For example:

Record 1 / Serial: 12345 / Flag: 1
Record 2 / Serial: 12345 / Flag: 1
Record 3 / Serial: 12345 / Flag : (empty)
Record 4 / Serial: 6789 / Flag: 1
Record 5 / Serial: 6789 / Flag: (empty)

Records with serial number 12345 should have a count of 2. Records with serial number 6789 should have a count of 1. To quickly explain, this is for conditional formatting. I have a portal with groups of records that fall under a "header" row. If one or more items within a group (joined by Serial) have a 1 in the flag field then the header needs to be a certain color for that specific group.

I think I'm over complicating this but I haven't found a solution that works. Would this be better calculated as an SQL statement?

  • Author

Ok, using the following SQL statement I achieved what I was looking for, but it's extremely slow. Is there a way to make this statement a little lighter on the computer?

ExecuteSQL ("SELECT Count (*) 

FROM Items 
WHERE Flag = 1 
and Serial 
IN ( ? , ? , ? , ? )
" ; "" ; "" ; Serial ; "" ; "" ; ""
)

 

What you want is probably

ExecuteSQL ( "
  SELECT COUNT (*) 
  FROM Items 
  WHERE 
    Flag = 1 AND 
    Serial = ?
  " ; "" ; "" ; Items::Serial 
)

or create a self-join for Items by Serial, then use Count ( Items_selfJoinBySerial::Flag ).

  • Author

or create a self-join for Items by Serial, then use Count ( Items_selfJoinBySerial::Flag ).

Just what I thought - totally overthinking it.

:thumbsup: Thanks eos!

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.