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.

Need help averaging repeating fields

Featured Replies

I'm trying to create a formula to average some fields, but am currently stumped.

I have a FMP database that I created to use as a journal for my stock trading.

I have a field set to calculate the average price of the stock based on the initial price, plus any additional stocks that I purchased after the initial purchase. The average price of the position should "average down" as I scale in more shares at a lower price, or average up if I buy higher priced shares. 

The fields related to this formula would be openingPosition (how many shares purchased),

openingPrice (cost of initial shares purchased),

scaleInPosition (number of additional shares purchased after the initial purchase - a repeating field with 10 repetitions), 

scaleInPrice (price of the new shares that were scaled in  - also a repeating field with 10 reps)

averagePrice (the calculation field to return the average price of the position after scaling in)

The closest I got to this working was:

(openingPrice + Sum ( scaleInPrice )) / (1 + Count ( scaleinPrice ))

but that only works if everything bough is 1 (1 initial share, 1 share scaled in each time, etc)

If I scale in 10 shares, it does not work.

any help or suggestions would be greatly appreciated.

Thanks.

 

This would be much simpler if you had a related table of transactions, where each purchase would be an individual record with fields for price and amount purchased. Then you could use a summary field to produce the average of price weighted by amount.

With your current structure, you will need to multiply each individual price by the corresponding amount, sum the results and divide by the total amount.

 

  • Author

Thanks for the reply. That gives me a good idea where to start. I'll try the related table approach.

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.