WPCubed Product Support

generating sum using wpreporter

I am using wpreporter to generate sum value of one column, it works well when using one group in the report. but now i want to use wpreporter to generate report of master-detail structure. it can sum value of master records, but it can't sum value of detail values of one master record. here is an example, the expecting result is following:

master    1    1001detail      1    2              1    3              1    4sum              9                   master    2    1002detail      2    1              2    3              2    4 sum            8grand sum    2003

but now i get the result is:

master    1    1001
detail      1    2
              1    3
              1    4
sum              17                   
master    2    1002
detail      2    1
              2    3
              2    4
 sum            17
grand sum    2003

the problem is the sum of detail values are sum of all the detail records,but i want is the sum of detail records of same master record.

did i describe my question clearly?

please help me

#1 ✎ ♥ 0
5.4k Views 1 links 2 users read 3 min
support

Hi,

When you receive the event BeforeStartGroup you need to set the value which you use for the subtotal to 0.

Julian

#3 ♥ 0

i use following code to sum totals

if Sender<>SourceText.Memo then   try      tbl := pobj.ParentPar.ParentTable;      colnr := pobj.ParentPar.ColNr;      sum := 0;      if pobj.SOURCE='TOTALNR' then // Sum in this Column ------------------------      begin        list := TList.Create;        try          tbl.GetObjList([wpobjMergeField],list,nil,'NR');          for i:=0 to list.Count-1 do          //OPTION: if TWPTextObj(list[i]).ParentPar.ColNr=colnr then  //<--- only in same COLUMN!!!          begin            // sum := sum + StrToFloat(TWPTextObj(list[i]).EmbeddedText);            sum := sum + TWPTextObj(list[i]).EmbeddedTextAsFloat;          end;        finally         list.Free;        end;      end else // Sum on this page with same parent table ----------------------      begin        for i:=0 to page.EmbeddedObjectCount([wpobjMergeField],pobj.Source)-1 do        if page.EmbeddedObjectGet(i).ParentPar.ParentTable=tbl then // Only sum up in same table!        begin         // sum := sum + StrToFloat(page.EmbeddedObjectGet(i).EmbeddedText);         sum := sum + page.EmbeddedObjectGet(i).EmbeddedTextAsFloat;        end;      end;      ResultText := FloatToStr(sum);      UseIt := TRUE;   except      ResultText := 'ERR';      UseIt := TRUE;      if PaintCanvas<>nil then         PaintCanvas.Font.Color := clRed;   end;

but this line

tbl.GetObjList([wpobjMergeField],list,nil,'NR');

sum all the column in whole table, it is not wanted,i want to sum only in one master record.

how should i do?

#4 ♥ 0
support

Hi,

the TWPTextObj reported by GetObjList all have a property ParentPar . This reference can be used to check the location of the object in the document - for example serach for hidden text which marks the different queries.

You could in column 1 insert the master record id - as hidden text. Using
ParentPar.ParentRow.FirstCol you can check for the id
[](http://www.wpcubed.com/manuals/wptools5/IDH_Class_TWPTextObj.htm)
Julian

#5 ♥ 0
This category is archived. No new posts are possible.