Skip to Content
Former Member
Sep 18, 2014 at 06:33 PM

Crosstab not calculating correctly from array


J. Wiseman created an array to help me summarize the incentives assigned to a drive based on a projected/performed field in the database. And then showed me how to add a second column in which the incentives would be totaled based off another column that contained the incentive or unit cost.

And it is working beautifully on the first cross-tab that looks at the pre-drive numbers. But I'm trying to add a second cross-tab that performs the same calculations based off procedures performed, instead of projected procedures but it seems like the second cross-tab is still using the the array or variables that were assigned to the pre-drive cross-tab and I'm not sure how to change it.

The array used to build the values is:


stringvar d:= {OBI_EquipmentMaster.Description};

numbervar p:= {DriveProjectionAndCollectedTotals.ProcedureProjection};

numbervar pe:= {DriveProjectionAndCollectedTotals.ProceduresPerformed};

stringvar array ad;

numbervar array ap;

numbervar array ape;

numbervar c2:= 1;

numbervar n:=0;

// check to see if the description has been added to the string array

// if not, add it plus add the initial projection value to the number arrays

if not (d in ad) then


numbervar c:= c + 1;

redim preserve ad[c]; ad[c]:= d;

redim preserve ap[c]; ap[c]:= p;

redim preserve ape[c]; ape[c]:= pe;



// if the description is already in the array, find its position

// then add the new projection as a running total to the appropriate number array values


while c2 <= count(ad) do


if d = ad[c2] then (n := c2; exit while);

c2 := c2 + 1


ap[n]:= ap[n] + p;

ape[n]:= ape[n] + pe;


// grand running totals

numbervar gp:= gp + p;

numbervar gpe:= gpe + pe;

And then on the display string for the cell where I summed the values of the incentives:


stringvar t:= GridRowColumnValue ("rpt_EquipmentMaster.Description");

stringvar array ad;

numbervar array ap;

numbervar c3:= 1;

numbervar n2;

while c3 <= count(ad) do


if t = ad[c3] then (n2 := c3; exit while);

c3 := c3 + 1


numbervar apn:= ap[n2];


And the display string where I calculated the total cost of the incentive:


numbervar apn;

numbervar apnrt:= apnrt + apn*currentfieldvalue;

"$"+totext(currentfieldvalue * apn,2)

My guess is that because I used the same formula for the second cross-tab as the two directly above for the display string, it is causing me to display the same numbers twice. But how this array was created and the formulas used to display the records is above my understanding.

Any suggestions on how to correct this second cross-tab?


2nd Crosstab.JPG (52.6 kB)