The āHighest Returnā formula depends on the āHighest Priceā Rollup (Aggregation) in comparison to the āPurchase Priceā.
You are wanting another formula, āCurrent Returnā related to āPurchase Priceā, which means you need another Rollup (aggregation) for the āCurrent Returnā formula to depend on. However, this rollup (aggregation) will require a few preliminary steps to set it up.
Youāll need a Rollup field in your TICKER table to rollup all of the āStock Valuesā records, but instead of looking at the āValueā field and returning MAX(values), you will point it at the āDateā field and return MAX(values) [letās call this field āMax Dateā]. Now youāve got the most recent Date that a value was fetched for that Stock.
Now go back to your āStock Valuesā table ā we will create a Lookup field here called āMax Dateā that looks at the āStockā linked record field (which is coming from the TICKER table), and returns the āMax Dateā field from that table. Now every record in the āStock Valuesā table knows what the most recent date that a value for stock of that type was fetched.
So now we can create another formula field that says āif the date of this record matches the date of the most recent value fetch for this stock, display the value fetched here as the current value of the stockā.
Letās call this field āCurrent Value?ā, and give it this formula:
IF(
IS_SAME(
Date,
{Max Date},
'day' <-- compares the date values to an accuracy of a day; adjust to 'hour' if multiple values are fetched in a single day
),
{Current Price}
)
Format this field as currency; it will be blank for all records except the most recently fetched value for each type of stock, and for that most recently fetched stock of each type, this field will show the current value.
So the final step here is to create that Rollup in the TICKER table that your āCurrent Returnā formula will be based on. Letās call this Rollup field āCurrent Valueā, point it at the āStock Valuesā linked record field, the āCurrent Value?ā table, and use the SUM(values) rollup function. Format as currency. Since there is only 1 value (the most recent value) for any given stock in this rollup, it will always return {Current Value} + 0 + 0 + 0⦠ie, only the Current Value.
(Note: if you are getting more than one value returned for the same stock in this rollup, and thus getting an inflated āCurrent Valueā since more than one value fetched is being summed here, then adjust that accuracy of ādayā in the IS_SAME() formula to be more precise ā maybe āhourā or āminuteā, depending on how often you fetch values)
Now you can create your āCurrent Returnā formula, comparing āPurchase Priceā to āCurrent Valueā:
{Current Value} - {Purchase Price}
Formatted as currency and allowing negative numbers.
You can hide all the superfluous fields that were needed to get here, and only show your final comparison formula fields, if all the others are distracting/messy.
Hope that helps!