Multiple TOT()s, one field (was RE: TOT(0 seems broke)
Bruce Easton
bruce at stn.com
Wed Mar 7 10:56:17 PST 2007
George Simon wrote Wednesday, March 07, 2007 1:17 PM:
> -----Original Message-----
> From: filepro-list-bounces+george=worldest.com at lists.celestial.com
> [mailto:filepro-list-bounces+george=worldest.com at lists.celestial.com] On
> Behalf Of Kenneth Brody
> Sent: Wednesday, March 07, 2007 12:28 PM
> To: Bruce Easton
> Cc: filepro-list at lists.celestial.com
> Subject: Multiple TOT()s, one field (was RE: TOT(0 seems broke)
>
> Quoting Bruce Easton (Wed, 7 Mar 2007 12:09:16 -0500):
>
> > Kenneth Brody wrote Wednesday, March 07, 2007 10:40 AM:
> > > > Also, here's something you can do with TOT() that will delight and
> > > > confuse everyone here. :-)
> > > >
> > > > If: foobar eq "Y"
> > > > Then: xx = tot(foo)
> > > > If: foobar ne "Y"
> > > > Then: xx = tot(bar)
> > > >
> > > > What would you expect "xx" to hold? I'll tell you right away that
> > > > it is _not_ the same as
> > > >
> > > > If: foobar eq "Y"
> > > > Then: xx = xx + foo
> > > > If: foobar ne "Y"
> > > > Then: xx = xx + bar
> [...]
> > I would expect xx in the first example to hold only the total of foo
> > at that point, if the last occurrence of foobar was "Y", otherwise it
> > would only be the total of bar at that point.
> >
> > In the second, I would expect xx to be the total of all of occurrences
> > that foo and bar held at that point.
>
> Correct to you and Chad.
>
> There are two distinct totals being calculated in example 1. There
> are the totals for foo when foobar is "Y", and the totals for bar
> when foobar is not "Y", and they are kept track of separately,
> despite both having the current total stored into xx.
>
> In other words, xx contains either tot(foo) or tot(bar), depending
> on the current value of foobar.
>
> --
>
> _______________________________________________
> Filepro-list mailing list
> Filepro-list at lists.celestial.com
> http://mailman.celestial.com/mailman/listinfo/filepro-list
>
> So how is that different from
> If: foobar eq "Y"
> Then: xx = xx + foo
> If: foobar ne "Y"
> Then: xx = xx + bar
>
> xx would end up with the same total. No?
>
> say foo=5 and bar=6
>
> rec# 1 foobar="Y" -- x=0+5 -- x=5
> rec# 2 foobar="N" -- x=5+6 -- x=11
> rec# 3 foobar="N" -- x=11+6 x=17
> rec# 4 foobar="Y" -- x=17+5 x=22
> rec# 5 foobar="Y" -- x=22+5 x=27
>
> What am I missing?
>
George, using your example above which ends on 'foobar="Y",'
but with Ken's code using the tot function:
> > > > If: foobar eq "Y"
> > > > Then: xx = tot(foo)
> > > > If: foobar ne "Y"
> > > > Then: xx = tot(bar),
I think xx would wind up with only 15 (the total of all the
foo values encountered), since your last record has
'foobar="Y".' (Assuming that your output process processed
your rec# 5 last.)
Bruce
Bruce Easton
STN, Inc.
More information about the Filepro-list
mailing list