From: Scott W. <swa...@my...> - 2003-04-17 17:07:42
|
On Thu, 17 Apr 2003, mowestusa wrote: > Hello, > I love Pilot-DB, and I would love the answer to this > question because it would give me the chance to make > new databases that would be really cool. > > I want to know how to use a script to keep a running > total going in the calculated field. > Example: > Field0 Date (A date field) > Field1 Type (A list field) > Field2 Description (A string field) > Field3 Cost (A floating point field) > Field4 Total (A calculated field that keeps a > running total (or if possible a running total by > type?)) > off the top of my head how about: (sort 0 1)(+ %3 (ffr 4 -1 0.0)) sort by date, then keep a running total of cost or: (sort 1 1 0 1)(+ (? (seq (ffr 1 -1 'n/a') %1) (ffr 4 -1 0.0) 0.0) %3) sort by type then date, keep running totals per type. That is, check to see if the previous record is the same type as the current record (? (seq ffr 1 -1 'n/a') %1). If so, add its running total (ffr 4 -1 0.0) with the current cost (%3). Otherwise add the default value (0.0) to the current cost (%3) If you want to do both of these, then you'll probably want to use the same sort order for the scripts, (i.e. sort 1 1 0 1) or define two views with appropriate sortings for the calculated field you display. Otherwise, one running total might look a bit odd. hope this helps -Scott |