Re: Totals on change



brm6546545 (russell.allbritain@xxxxxxxxx) writes:
I have a tblTax. It has fields InvoiceNum, TaxAuthority, TaxableTotal,
NonTaxableTotal, TaxCollected.

Sample data

1,county,10.00,0.00,0.40
1,city,10.00,0.00,0.10
2,state,0.00,15.00,0.15

When totaling invoice 1 should have totals of 10.00,0.00,0.50 because
the 10.00 is the total for the invoice, but 0.50 is the total tax
collected. I nee these totals in a report. In crystal reports i could
just do a total on change of invoice number for the Taxable and
nonTaxable Totals. but i have to this on an Access adp. I was hoping i
could get a query to return something like


inv,auth,Taxable,nonTaxable,Collected,TaxableTot,NonTaxableTot,CollectedTot
1,county,10.00,0.00,0.40,10.00,0.00,0.50
1,city,10.00,0.00,0.10,10.00,0.00,0.50
2,state,0.00,15.00,0.15,0.00,15.00,0.15

SELECT InvoiceNum, TaxAuthority, TaxableTotal,
NonTaxableTotal, TaxCollected,
CollectedTot = SUM(TaxCollected) OVER (PARTITION BY InvoiceNum),
GrandCollected = SUM(TaxCollected) OVER ()
FROM tblTax

I did not include TaxabltTotal and NonTaxableTotal, since I don't really
see the point with them. Can the taxable amount be different for different
authorities? In such case, I don't know the business rules to compute
them.

The solution requires SQL 2005.



--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: Newbie, Help needed with rounding errors
    ... This is why tax should only be computed on the sub-grouped total values, ... The Revenue's method of subtracting the computed price net of tax from the ... price per item on the invoice, so I round to get 21.57 each. ... incorrect totals." ...
    (microsoft.public.access.gettingstarted)
  • Re: Formula selection: a real tough one
    ... I misread the OP saying he wanted the Invoice TOTAL, where Item SYSTM was included. ... The totals will be just for that Item. ... Drag Item No to Page area ...
    (microsoft.public.excel)
  • RE: SubTotals on Forms
    ... No. SubForm 3 draws on the invoice query and only has two items on the ... I want to have two totals at the bottom of the ...
    (microsoft.public.access.forms)
  • Re: report group subtotals incorrect
    ... there are multiple payments of the invoice, ... This text box accumlates the total for the customer over their invoices, ... An alternative idea would be to use a subreport for the payments. ... > tehn totals per group. ...
    (microsoft.public.access.queries)
  • Re: save calculated form fields to a table
    ... Allen is totally correct you should try to never store a value in a table ... if the underlying data that makes up the calculation ... one item on the invoice was credited, you would have to recalculate the ... >>> save my totals? ...
    (microsoft.public.access.formscoding)