Data Connectivity
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Data Connectivity
Message Icon Topic: How to use loops in formula field on a crystal rep Post Reply Post New Topic
Author Message
klps
Newbie
Newbie


Joined: 20 Feb 2012
Online Status: Offline
Posts: 1
Quote klps Replybullet Topic: How to use loops in formula field on a crystal rep
    Posted: 20 Feb 2012 at 9:42pm
I need to check all the records in a table.I'm having a foreach loop in my web application. I need to use this loop in crystal report's formula field. I'm new to crystal reports and I have no idea with how to write it in formula field. Can anyone help me?

     
foreach (DataRow dr in ds.Tables[0].Rows)
        {
            type = (dr["type"]).ToString();
            if (type == "c")
            {
                c_total = c_total + Convert.ToDouble(dr["amount"]);
            }
            else if (type == "d")
            {
                d_total = d_total + Convert.ToDouble(dr["amount"]);
            }
        }
IP IP Logged
rkrowland
Senior Member
Senior Member
Avatar

Joined: 20 Dec 2011
Location: England
Online Status: Offline
Posts: 259
Quote rkrowland Replybullet Posted: 21 Feb 2012 at 12:18am

I'd assume you do this to get a balance of debits and credits after individual transactions (records)?

If so I'd just create a formula field as follows and then create a running total on this field;
 
if {table.typefield} = "c" then -{table.amountfield} else
if {table.typefield} = "d" then {table.amountfield}
 
You may need to change the "-" position - You should be able to create a running total on this field on each record resetting at customer/supplier or whatever you need.
 
If I'm misunderstanding what you're trying to accomplish let me know.
 
Regards,
Ryan.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.000 seconds.