Re: Questions about the 'Sum' function

2017-04-13 Thread Keisuke Miyako via 4D_Tech
Sum() has been improved to work with indexes since v11, with arrays since v13.
if the restriction is still there, perhaps one can "selection to array" as a 
workaround.

> 2017/04/14 0:06、Keith White via 4D_Tech <4d_tech@lists.4d.com> のメール:
>
> QUERY([ClientInvoices]; blah blah blah..)
> nThisCustomerTotal:=Sum([ClientInvoices]Balance)
> Nope, doesn't work.
> Tried to report to 4D as a bug a vry lng time ago, but was told this 
> was "Standard Behaviour".




**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Questions about the 'Sum' function

2017-04-13 Thread Keith White via 4D_Tech
Hi

Sum for a selection of another table doesn't work if used in "On Printing 
Detail" of an output form.

So say you were printing a list of clients and you wanted to include on that 
list a total balance of invoices for each client.  So you'd think:-

QUERY([ClientInvoices]; blah blah blah..)

nThisCustomerTotal:=Sum([ClientInvoices]Balance)

Nope, doesn't work.

Tried to report to 4D as a bug a vry lng time ago, but was told this 
was "Standard Behaviour".

Best regards

Keith White
Synergist Express Ltd, UK.
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Questions about the 'Sum' function

2017-04-12 Thread Tim Nevels via 4D_Tech
On Apr 12, 2017, at 2:00 PM,Kirk Brooks wrote:

> Sum works fine on a selection of records or on an array. It used to be a
> little slow but not now.

Sum and the other series commands are optimized and will use the index on field 
a field if it exists. Saves loading all the records in the selection into the 
data cache. 

> If you are working on 4D server it's useful to build some functions that
> will run on the server to speed things up even more. Using your example you
> could write:
> 
> // Customer_get_invoiceSum (id)
> QUERY([INVOICE];[INVOICE]customer=$1)
> $0:=Sum([INVOICE]amount)
> UNLOAD RECORD([INVOICE])
> 
> Set the Execute on server attribute and use it as
> 
> $total:= Customer_get_invoiceSum(2)

The series command are also optimized for 4D Server. So it will already do the 
Sum on 4D Server. 4D has already done the optimizations for you with the Series 
commands. Doing the work on 4D Server and using indexes is what makes this 
super fast.

Tim


Tim Nevels
Innovative Solutions
785-749-3444
timnev...@mac.com


**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Questions about the 'Sum' function

2017-04-12 Thread Kirk Brooks via 4D_Tech
Peter,
Sum works fine on a selection of records or on an array. It used to be a
little slow but not now.

If you are working on 4D server it's useful to build some functions that
will run on the server to speed things up even more. Using your example you
could write:

// Customer_get_invoiceSum (id)
QUERY([INVOICE];[INVOICE]customer=$1)
$0:=Sum([INVOICE]amount)
UNLOAD RECORD([INVOICE])


Set the Execute on server attribute and use it as

$total:= Customer_get_invoiceSum(2)


If you are actually on a server this will not change the selection of
invoices on your client machine.


On Wed, Apr 12, 2017 at 4:22 AM, Peter Jakobsson via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Hi
>
> Occasionally I’d like to use the “Sum” function on a current selection but
> am hesitant because of distant memories of it only being supported in
> certain circumstances (e.g. in reports, on single user.not client server
> etc).
>
> Do people use this outside of a report context and on any current
> selection ? e.g. can you safely just do this…
>
> QUERY([INVOICE];[INVOICE]customer=2)
> $total:=Sum([INVOICE]amount)
>
> Is anyone aware of any circumstance where this won’t work ?
>
> Thanks in advance !
>
> Peter
>
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **




-- 
Kirk Brooks
San Francisco, CA
===

*The only thing necessary for the triumph of evil is for good men to do
nothing.*

*- Edmund Burke*
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Questions about the 'Sum' function

2017-04-12 Thread Sujit Shah via 4D_Tech
Just recalling the term series from memory. Something I read in the manual.
My understanding is a selection or array i think it works for both.

Not in front of computer so not 100% sure.
On Wed, 12 Apr 2017 at 9:34 pm, Peter Jakobsson via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> On 12 Apr 2017, at 13:29, Sujit Shah via 4D_Tech <4d_tech@lists.4d.com>
> wrote:
>
> > Sum has always worked on a series
>
> Thanks Sujit. But what’s the definition of a ‘series’ ?
>
> Does a field from a current selection qualify as a ‘series’ ?
>
> Peter
>
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **

-- 

xxx
"There must be ingenuity as well as intention, strategy as well as
strength. "
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Questions about the 'Sum' function

2017-04-12 Thread Peter Jakobsson via 4D_Tech
On 12 Apr 2017, at 13:29, Sujit Shah via 4D_Tech <4d_tech@lists.4d.com> wrote:

> Sum has always worked on a series

Thanks Sujit. But what’s the definition of a ‘series’ ?

Does a field from a current selection qualify as a ‘series’ ?

Peter

**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Re: Questions about the 'Sum' function

2017-04-12 Thread Sujit Shah via 4D_Tech
Perhaps you are confusing it with subtotal?

Sum has always worked on a series

E


On Wed, 12 Apr 2017 at 9:22 pm, Peter Jakobsson via 4D_Tech <
4d_tech@lists.4d.com> wrote:

> Hi
>
> Occasionally I’d like to use the “Sum” function on a current selection but
> am hesitant because of distant memories of it only being supported in
> certain circumstances (e.g. in reports, on single user.not client server
> etc).
>
> Do people use this outside of a report context and on any current
> selection ? e.g. can you safely just do this…
>
> QUERY([INVOICE];[INVOICE]customer=2)
> $total:=Sum([INVOICE]amount)
>
> Is anyone aware of any circumstance where this won’t work ?
>
> Thanks in advance !
>
> Peter
>
> **
> 4D Internet Users Group (4D iNUG)
> FAQ:  http://lists.4d.com/faqnug.html
> Archive:  http://lists.4d.com/archives.html
> Options: http://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
> **

-- 

xxx
"There must be ingenuity as well as intention, strategy as well as
strength. "
**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**

Questions about the 'Sum' function

2017-04-12 Thread Peter Jakobsson via 4D_Tech
Hi

Occasionally I’d like to use the “Sum” function on a current selection but am 
hesitant because of distant memories of it only being supported in certain 
circumstances (e.g. in reports, on single user.not client server etc).

Do people use this outside of a report context and on any current selection ? 
e.g. can you safely just do this…

QUERY([INVOICE];[INVOICE]customer=2)
$total:=Sum([INVOICE]amount)

Is anyone aware of any circumstance where this won’t work ?

Thanks in advance !

Peter

**
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:4d_tech-unsubscr...@lists.4d.com
**