Search code examples
vb.netvisual-studiosummary

Crystal Reports Duplicating Field Value when summarizing 1 field


So this is my problem, im using this functions to calculate the amount for each kind of bill.

if {TB_Facturas.F_Condiciones}="Efectivo" then
Numbervar  X:=X+{@T_Total}
else
X:=X

if {TB_Facturas.F_Condiciones}="Deposito" then
Numbervar  D:=D+{@T_Total}
else
D:=D

and this function to reset each variable when it changes to other group

WhilePrintingRecords;
Global numbervar X; 
X:=0;

WhilePrintingRecords;
Global numbervar D;
D:=0;

In the group footer a put another field with this formula for each summary

{@TotalClone}

when there are more than one value it works perfect, but when it just have to count 1 value it duplicates the result, for example if the value is 135000 the obtained result is 270000 for no reason...

here is an image so you can see what i got as a result https://i.sstatic.net/VU1dY.png


Solution

  • You have two possibilities:

    1. Use two different groups one for each kind of bill, and let Crystal Reports summarize it all for you in each of the group footers.
    2. Use Formula Fields to summarize it up manually.

    To use Formulas, you need to create a Formula field from the right-hand menu (based on standard UI layout) and in your formula you need to either sum one kind or the other.

    shared numbervar sumOfEffectiveBills;
    shared numbervar sumOfDepositBills;
    
    if {TB_Facturas.F_Condiciones} = "Efectivo" then 
        sumOfEffectiveBills+= {@T_Total}
    else if {TB_Facturas.F_Condiciones} = "Deposito" then 
        sumOfDepositBills+= {@T_Total}
    
    stringvar groupFooterSummary = "EFECTIVO: " 
                                 + totext(sumOfEffectiveBills, 2) 
                                 + "    DEPOSITO: "
                                 + totext(sumOfDepositBills, 2)
    groupFooterSummary
    

    This formula output shall be as follows:

    EFECTIVO: 99.99    DEPOSITO: 99.99
    

    I don't clearly remember how to declare a shared variable using Crystal syntax, nor am I sure that you will have no code replacement to make, as I have no Crystal Reports to test, nor data to retrieve.