•    Free Pascal
• Website
• Downloads
• Wiki
• Bugtracker
• Mailing List
•    Lazarus
• Website
• Downloads (Laz+FPC)
• Packages (OPM)
• FAQ
• Wiki
• Bugtracker
• CCR Bugs
• IRC channel
• GIT
• Mailing List
• Other languages
•    Foundation
• Website
• Project Roadmap
• Getting the Source
• Screenshots
• How to use the forum

### Author Topic: Is possible sum if condition  (Read 2279 times)

#### eldonfsr

• Sr. Member
•    • Posts: 295 ##### Is possible sum if condition
« on: November 13, 2021, 10:34:14 pm »
Hi i need a report witch column input and outs so create a report i can get print information separated but i don't know how sum that band total or group.

can possible use formula loke this

if( [DM.SQLQTrans."type"]='add' or [DM.SQLQTrans."type"]='asin') then begin sum([DM.SQLQTrans."quntity"]
end else begin
[DM.SQLQTrans."quntity"]=0;
end;

#### eldonfsr

• Sr. Member
•    • Posts: 295 ##### Re: Is possible sum if condition
« Reply #1 on: November 14, 2021, 01:01:57 am »
Ok after play i made some changes

you can see on image or report how i put de data intotals and outtotals

code some events on report events.
Code: Pascal  [Select][+][-]
1. procedure TFormTransPeri.frReportPartTransEndBand(Band: TfrBand);
2. begin
3. //  if(Band.Name = 'DetailData1') Then begin
4.   if(Band.Name = 'DetailFooter1') Then begin
5.      intotals:=0;
6.      outtotals:=0;
7.   end;
8.
9. end;
10.
11. procedure TFormTransPeri.frReportPartTransGetValue(const ParName: String;
12.   var ParValue: Variant);
13. begin
14.   if( ParName='datestart') then begin
15.     ParValue:= DEStart.Date;
16.   end;
17.   if( ParName='dateend') then begin
18.     ParValue:= DEEnd.Date;
19.   end;
20.   if( ParName='incomes') then begin
21.     if( (DM.SQLQTrans.FieldByName('Type').AsString = 'add') or (DM.SQLQTrans.FieldByName('Type').AsString = 'asin') ) then begin
22.       ParValue:= DM.SQLQTrans.FieldByName('quantity').AsString ;
23.       Intotals:=Intotals+DM.SQLQTrans.FieldByName('quantity').AsInteger;
24.   end else begin
25.       ParValue:='' ;
26.   end;
27.   end;
28.   if( ParName='outgoing') then begin
29.     if( (DM.SQLQTrans.FieldByName('Type').AsString = 'sub') or (DM.SQLQTrans.FieldByName('Type').AsString = 'asout') ) then begin
30.       ParValue:= DM.SQLQTrans.FieldByName('quantity').AsString ;
31.       Outtotals:=Outtotals+DM.SQLQTrans.FieldByName('quantity').AsInteger;
32.   end else begin
33.       ParValue:='' ;
34.   end;
35.   end;
36.  if( ParName='intotals') then begin
37.       ParValue:=intTostr(intotals) ;
38. //      intotals:=0;
39.   end;
40.  if( ParName='outtotals') then begin
41.       ParValue:=intTostr(outtotals) ;
42. //      outtotals:=0;
43.   end;
44.
45.
46. end;
47.