Recent

Author Topic: LazReport Running Total Field  (Read 8518 times)

r_1gm

  • New Member
  • *
  • Posts: 26
LazReport Running Total Field
« on: June 08, 2012, 08:23:47 pm »
Hi,

Anybody know about Running Total Field in LazReport ?


Best Regards,
r_1gm

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: LazReport Running Total Field
« Reply #1 on: June 09, 2012, 08:57:14 am »
   You can use Sum(expression), and band summary.
Regards.

r_1gm

  • New Member
  • *
  • Posts: 26
Re: LazReport Running Total Field
« Reply #2 on: June 09, 2012, 02:40:30 pm »
hi exdatis,

i already try your suggestion, but i cannot get result that i expect.

for example i had,

number      total
2                2
5                7
8                15

also we can set initial value for total.

with your suggestion i just get 15 for each row.

sorry for my bad english

r_1gm

  • New Member
  • *
  • Posts: 26
Re: LazReport Running Total Field
« Reply #3 on: June 15, 2012, 05:25:09 am »
Hi all,

Anybody know about running totals feature implementation(0017198) progress ?

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: LazReport Running Total Field
« Reply #4 on: June 15, 2012, 07:45:43 am »
That's not total! That's the progress, shrinkage values.
In my opinion, simple solution is:
in DBDataSet you can put calculated field, and on Calc event:
procedure TYourClass.DataSetCalc..(...);
var
  my_var : Double = 0;//or integer
begin
  my_var:= my_var + some_value;//progress of my_var
  calc_field.AsFloat:= my_var;//current value of my_var
end;
Now, you can put calculated field in your report.
Regards.

p.s. Maybe you need to reset calc_field value, to prevent double calculation, before print( my_var = 0).
       (Sorry, I'm late, I have not seen your post of  June 9)
« Last Edit: June 15, 2012, 08:12:11 am by exdatis »

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: LazReport Running Total Field
« Reply #5 on: June 15, 2012, 11:00:25 am »
LazReport is based on the FreeReport for delphi components which has evolved to fastReport commercial suite. You should try to get the documentation for one of the above suites and read upon it. In short and as far as I can remember, I haven't used those components for more than 5 years, You should create a custom expresion Variable and write code in its value, something like this

VariableName := VariableName +[LinkedIndatasetName."FieldWithData"].

This will take care of the running total calculations I dont remember where you should write code to initialize the value to 0 or how this can be accomplished within lazreport it self.
You will have to look it up on the documentation of freeReport or FastReport your self.

Edit:
By the way you are correct the term for this is "running total" because it has different value on each and depends heavily on the order the result set is returned it is called "running total"

Regards.
« Last Edit: June 15, 2012, 04:34:02 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

r_1gm

  • New Member
  • *
  • Posts: 26
Re: LazReport Running Total Field
« Reply #6 on: June 15, 2012, 02:49:01 pm »
@exdatis

ups... sorry :D
great, i will try, thank you very much exdatis.

no problem i already very grateful you are replying :D

@taazz

i will check the documentation, but AFAIK(if i not wrong) FastReport already implement this feature and LazReport not yet implementing this feature also the implementation also maybe different, but i will check it again.

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: LazReport Running Total Field
« Reply #7 on: June 15, 2012, 05:49:09 pm »
OK I found some time to play around with LazReport. Here is what I came up with.

01 ) make sure you have a report with a master data band connected to a dataset
02 ) place a text inside that band and double click to open its editor.
03 ) on the editor check the script option on the top left.
04 ) on the script window paste the following code.

Code: [Select]
IF [Line#] = 1 then RunTotal := [Dbf1."MTH_NO"]
else RunTotal := RunTotal +[Dbf1."MTH_NO"];

of-course you need to replace [dbf1."MTH_NO"] with your field, the one you want a running total.

05 ) Press OK to save the changes.
06 ) Press Preview to create the variable and close it.
07 ) reopen the editor by double clicking on the text object
08 ) press the "Variable" button.
09 ) select the fr variables category on the drop down combo.
10 ) double click the RunTotal variable to be place on Memo.
11 ) press OK and then press Preview.

You should now have a running total in your band.

Edit:
Corrected some typing errors.
« Last Edit: June 16, 2012, 09:54:49 am by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

r_1gm

  • New Member
  • *
  • Posts: 26
Re: LazReport Running Total Field
« Reply #8 on: June 17, 2012, 07:39:28 am »
@taazz

great, thank you taazz.