Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Percent of total help
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01012865
Message ID:
01012871
Views:
14
Pre-aggregate subtotals per account into a preCursor, then join for your detail table including percentage calcs.
select A1.account, sum( A1.amount ) AcntSubTotal;
   from YourTable  A1;
   group by A1.account;
   into cursor C_SubTotal

select A1.account, A1.Amount, ;
      round( A1.Amount / B1.AcntSubTotal, 3 ) LineItemPcnt;
   from YourTable  A1,  C_SubTotal B1;
   WHERE A1.Account = B1.Account;
   into Cursor C_FinalResult
Just a caution... if any possible list can have a zero balance as the final subtotal, you may need to change your calc on the second query to...
round( iif( b1.acntSubTotal = 0, 0000.00, A1.Amount / B1.AcntSubTotal ), 3)
>Hi all,
>
>How to create the formula to calculate the percentage out of the total in general format can be used all along ? from mytable.dbf
>
>account amount percentage
>
>11111 100 0.16
>11111 200 0.34
>11111 300 0.50
>---------------
>subtotal 600
>
>22222 200 0.25
>22222 200 0.25
>22222 400 0.50
>--------------
>subtotal 800
>
>
>I got the columns account , amount but need to calculate the percentage but be carefull , each time the account changes the formula of percentage should changed accordingly.
>
>Thanks in advance,
Previous
Reply
Map
View

Click here to load this message in the networking platform