Skip to Content
avatar image
Former Member

How to calculate the sum of Formula Fields

I m using crystal reports and i have varchar(500) columns which saves date and time for employees like checking in and checking out time , so i want the difference of checkout-checkin so i wrote that below formule

"NumberVar TotalSec := Time({zz_tbl_Report_New_Format.MondayOut}) - Time({zz_tbl_Report_New_Format.MondayIn}); NumberVar Hours := Truncate ( TotalSec / 3600); NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60); Totext ( Hours, '####') + ':'+ Totext ( Minutes,'00');"

it finds the difference correctly now at the end i want to add up all these rows and show the sum how can i achive that .check the attachement for more clarification

report.png (43.2 kB)
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • May 01 at 02:13 PM

    As you are using Variables you need to use another one

    Using your existing formula,

    Whileprintingrecords;

    Global numbervar GrandTotalSec;

    NumberVar TotalSec := Time({zz_tbl_Report_New_Format.MondayOut}) - Time({zz_tbl_Report_New_Format.MondayIn});

    NumberVar Hours := Truncate ( TotalSec / 3600); NumberVar Minutes := Truncate (Remainder ( TotalSec,3600) / 60); Totext ( Hours, '####') + ':'+ Totext ( Minutes,'00');"

    GrandTotalSec:= GrandTotalSec + TotalSec

    Assuming this is a Report Total you will not need to reset GrandTotalSec

    Create another Var

    @DisplayGT

    Whileprintingrecords;

    Global numbervar GrandTotalSec;

    You can then perform same Truncate and remainder on this to split into Hours and mins, then use Totext() to concatenate numbers together to display as HH:MM:SS

    Ian

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 01 at 11:29 AM

    I found the solution

    Go to Running total Fields in Field Explorer and right click on it and make your Field For total

    and if you have already made your formula then select it and [>] click it to put your formula to Field to Summarize then from Type of Summary Drop Down select Sum and click ok. Now you can see your

    New formula at Below List in Running total Fields You can put it where you want to see total.

    Regards,

    Abhi Patel



    BUT IT WONT WORK FOR ME AS I HAVE STRING TYPE SO MY SUMMARY DROPDOWN DOES NOT SHOW SUM it SHOWS COUNT AND OTHER ITEMS LIKE MAXIMUM ,MINIMUM ETC

    Add comment
    10|10000 characters needed characters exceeded