Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Grouping Puzzle
Message
De
12/09/1998 10:35:45
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Titre:
Divers
Thread ID:
00135528
Message ID:
00135798
Vues:
8
>Hi Cetin,
>
>I got the amount on the columns by using the expression
>iif(betw(nAveD,1,20),nAmount,0)
>
>Where nAveD is a variable set to average the Days per transaction group
>
>but getting the total of each column using the expression above with the sum gives a wrong answer. It adds the amount n times. Example below total for column 1 should be 4000 but using the expr above it comes out 8000 (1000+1000+3000+3000).
Hi Alvin,
Doing with report vars killing me either. I find it easier to do with SQL. Note that report fields have no alias just fieldname (which makes them free of source so you could do final SQL to a nonpredetermined cursor - report DE is empty).
*!*	crsTransactions table
*!*	Transnum Days Amount
*!*	-------- ---- ------
*!*	       1   10   1000
*!*	       1   30    500
*!*	       2   30   2000
*!*	       2   40      
*!*	       3   20   3000
*!*	       3   20   

select avg(days) as avg_days,transnum ;
	from crsTransactions ;
	group by transnum ;
	into cursor crsAverage ;
	nofilter
select a.transnum, a.days, a.amount, ;
	iif(between(b.avg_days, 1,20),1,0)*a.amount as c1, ;
	iif(between(b.avg_days,21,30),1,0)*a.amount as c2, ;
	iif(between(b.avg_days,31,40),1,0)*a.amount as c3 ;
		from crsTransactions a ;
		inner join crsAverage b ;
		on a.transnum = b.transnum ;
	into cursor crsReport ;
	nofilter

* report form myreport to file trns ascii

* report form myreport layout
* Data grouping : transnum
* Variables     : (no variables)
* Detail band   : transnum days amount
*--------------
* Group footer  : days (calc - average) c1, c2, c3 (all calc sum, reset transnum)
*--------------
* Summary band  : c1, c2, c3 (all calc sum, reset end of report)
*--------------
* Trns.txt below

*!*	  Trans    Days    Amount   (1 to 20 days)   (21 to 30)   (31 to 40)
*!*	     1     10   1.000
*!*	     1     30     500
*!*	      Avg  20              1.500
*!*	     2     30   2.000
*!*	     2     40
*!*	      Avg  35                                      2.000
*!*	     3     20   3.000
*!*	     3     20
*!*	      Avg  20              3.000
*!*	            Totals         4.500                   2.000
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform