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.

calculating certain rows in a portal

Featured Replies

  • Newbies

I have a database of bills and expenses that I record every month. I have the various bills in a portal with the date they are due and the amounts. What I would like to be able to do is to select only certain rows (or ID's) from the portal and then get a summary of the amounts from all of those rows only. Then, I would like to take this total and divide it by 3 to get a new total. Can anyone help me with this?

Welcome to the Forum,

Without knowing your table structure, I will have to make a guess. Add a number field in the related table. Auto enter 0 in this field. Write a script like this.

If [NewField = 0]

Set field [NewField, 1]

Else

Set field [NewField, 0]

End If

Commit record

Add a button in the portal row that preforms the following script.

Go to relaated record [Relationship]

Preform Script [new script]

Refresh window

Make a new relationship to the related table. This relationship should include the dates (first and last days of month) aand the new field.

Use the Sum function with this relationship to get the total for the selected rows.

If this doesn't help you, post a sample of your file and I will make the changes to get this to work.

A simpler script for changing the value of NewField:

Set Field [NewField; Abs(NewField - 1)]

Commit Records/Requests

  • Author
  • Newbies

Thank you for your quick reply. I am new to this so I may need a little more explanation. First, what is the SetField doing in the script? Is it making some entries equal to 1 instead of 0? If so, how does this help? Won't it make each line equal to 1 since they are all auto entered as 0? Or does this allow me to select which entries become 1 or 0? Second, when I create the relationship to another table, how to I relate it to the beginning and end of the months? Do I have to manually type in the beginning and ending dates of each and every month? Thanks again for your help.

  • Author
  • Newbies

Also, the SetField won't let me enter it the way that you suggested on either example. It says that it is missing an operator value. I am using FileMaker 7 if that helps.

Actually, I don't think you need the Go to Related Record step. A button in a portal will act on only the current portal row (related record). So your script only need be

Set Field [relationship::NewField; Abs(relationship::Newfield - 1)]

Commit Records/Requests

This will change the selected portal row's NewField to 1 or zero, appropriately.

You could also put the related NewField in the portal and format it as a checkbox using a value list of 1. Then you wouldn't need a script at all.

The new relationship should be the same as your original one, with the addition of a calculated number field equal to 1 being mapped to the related NewField. That way it will include only the related records with NewField marked as 1 for your Sum calculation.

The semicolon in the Set Field step separates the target field, relationship::NewField, from the calculation to specify, Abs(relationship::NewField - 1). It should not be included in the actual calculation.

  • Author
  • Newbies

Thanks for your quick reply. This is going to help me tremendously. I have one more question to make sure I understand this right. Let's say that I do set the NewField equal to 1 for certain rows. At that point, what would the sum function look like to get a sum of all the specific amounts in the selected rows?

Sum(NewRel::Amount), where NewRel is the duplicate relationship with the additional mapping from a calculation of 1 to NewField.

Create an account or sign in to comment

Important Information

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

Account

Navigation

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.