Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Formula Problem and summing the final product. Post Reply Post New Topic
Page  of 2 Next >>
Author Message
jruotolo
Newbie
Newbie


Joined: 23 Jul 2009
Location: United States
Online Status: Offline
Posts: 7
Quote jruotolo Replybullet Topic: Formula Problem and summing the final product.
     Posted: 23 Jul 2009 at 1:03pm
Hello,

Hopefully I can get some ideas from the group on ways to tackle this issue.

I have files, each with a FileID. There can be 1 to many rows for each FileID.  Each Row has an Amount Field.  For some rows there is an actual $$ amount other rows the Amount is NULL.  On Rows that have NULL, if it is a Unique FileID then I need to replace NULL with 600.00 if the File ID is not Unique I need to replace with 0.00 or leave NULL. 

Here is a sample of the Original Data.

FileID      Amount
36             687.54
36             0.00
430           522.00
430           0.00
1858         0.00
1873         0.00
5507         189.12
5507         378.22
5507         0.00

I need the data to look like this.


FileID      Amount
36             687.54
36             0.00
430           522.00
430           0.00
1858         600.00
1873         600.00
5507         189.12
5507         378.22
5507         0.00

This Data is all in the details section and I will be sorting by FileID. 

The final Piece to this puzzle is I need to be able to sum the New Amounts in Report Footer for a grand total.

Any Ideas On how I can tackle this issue?

Thanks for any help you can provide.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Jul 2009 at 2:13pm
The issue is the SUM at the end.
If you never have an instance where there there is more than one record in of a FileID and the first row is null then this process might work but I am not sure so test it thoroughly...
Create a formula field as "Conversion"
if isnull({table.amount}) then 600.00 else {table.amount}
Now create a Running Total as "SUM"
Field to Summarize= {@Conversion}
Type of Summary=SUM
Evaluate set as 'On Change of Field' = {table.FileID}
Reset as Never
Place it on Report Footer. Verify it is correct
 
IP IP Logged
jruotolo
Newbie
Newbie


Joined: 23 Jul 2009
Location: United States
Online Status: Offline
Posts: 7
Quote jruotolo Replybullet Posted: 23 Jul 2009 at 2:29pm
Thanks for the Input Dblank.

I have tried something similar to what you have proposed.  The issue here is I have both instances.  Where there is only one record of a File ID and the Amount is NULL and 2 or more records for a File ID where an amount is NULL

In order to get the Data to display the way I want, I created a formula to do this (I should have shown this in my original post)

This is that Formula
***************
If OnFirstRecord then (If isnull({vw_MF_All_2010_Liable_Files.Amount}) then 600.00 else
If {vw_MF_All_2010_Liable_Files.Amount} = 0.00 then 600.00 else
{vw_MF_All_2010_Liable_Files.Amount})


 else
If ({vw_MF_All_2010_Liable_Files.Liable_Type} = "zNo Pending Trans"
and Previous({vw_MF_All_2010_Liable_Files.FileID}) = {vw_MF_All_2010_Liable_Files.FileID}) then 0.00

else

(If isnull({vw_MF_All_2010_Liable_Files.Amount}) then 600.00 else
If {vw_MF_All_2010_Liable_Files.Amount} = 0.00 then 600.00 else
{vw_MF_All_2010_Liable_Files.Amount})
**************

This will display the correct Amount for all Amount fields that have NULL or 0.00.

But I cannot sum this field, so I was hoping someone had another idea on how to do it display the data and sum it.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 23 Jul 2009 at 2:41pm
What I was suggesting here is a two pronged approach.
It seemed that you have the presentation of the data just fine. What i was trying to do was to get you a value that you could sum on. As soon as you use previous or next function you cannot use the field to sum.
If you can tweak my "Conversion" formula so it includes the Summing amount then you can use the process to get your sum and the other way to show the data.
If not I think you will be stuck with Sub reports and shared variables.
 
IP IP Logged
jruotolo
Newbie
Newbie


Joined: 23 Jul 2009
Location: United States
Online Status: Offline
Posts: 7
Quote jruotolo Replybullet Posted: 23 Jul 2009 at 2:46pm
Ahh...I have better Idea of what you were getting at.  It was an option I had explored briefly earlier today but your approach has given me a different way to look at it.  I will look into it further tomorrow when I have fresh eyes. 

I appreciate the help.  I have run into this type of issue before and have never been able to solve it.

I'll let you know how it goes.
IP IP Logged
jruotolo
Newbie
Newbie


Joined: 23 Jul 2009
Location: United States
Online Status: Offline
Posts: 7
Quote jruotolo Replybullet Posted: 24 Jul 2009 at 11:51am
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Jul 2009 at 11:59am
Can you post a little wider scope of some sample data with ALL of the rules of exclusion and inclusion of rows for a total Sum?
IP IP Logged
jruotolo
Newbie
Newbie


Joined: 23 Jul 2009
Location: United States
Online Status: Offline
Posts: 7
Quote jruotolo Replybullet Posted: 24 Jul 2009 at 12:18pm
Sure, here is a wider scope of data with the the Actual Data of the Amount Field and what $$ amount should be summed.

FileID      Amount    Amount to be Summed
5,347      NULL          $600.00
 
5,349      NULL          $600.00

5,350      NULL          $600.00

5,435      $413.00     $600.00

5,507      $189.12     $189.12
5,507      $378.22     $378.22
5,507      NULL          $0.00

5,536      NULL          $600.00

17,520    $64.48       $64.48
17,520    $248.10     $248.10   
17,520    $327.58     $327.58
17,520    NULL          $0.00

17,557    NULL          $600.00

17,578    NULL          $600.00

Total Sum                 $5407.50
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 24 Jul 2009 at 1:28pm
OK. There may be a more elegant solution using variables but the shared variable process would require using sub reports and that is a no go for you.
So lets use the idea of one field form getting your sum amount and you can keep your other process for displaying the amount....I think this will work (well it will work but I think it will give you the correct value Thumbs%20Up)
Create a formula field as "Conversion":
If isnull({vw_MF_All_2010_Liable_Files.Amount}) or {vw_MF_All_2010_Liable_Files.Amount} = 0.00 then 600.00 else
{vw_MF_All_2010_Liable_Files.Amount})
 
Now we will use two running totals to:
1. Name="Count"
Field to summarize= FiledID
TYpe of summary=Count
Evaluate =Use a formula
isnull({vw_MF_All_2010_Liable_Files.Amount}) or {vw_MF_All_2010_Liable_Files.Amount} = 0.00
Reset=Never
2. Name="DistinctCount"
Field to summarize= FiledID
Type of summary=DistinctCount
Evaluate =Use a formula
isnull({vw_MF_All_2010_Liable_Files.Amount}) or {vw_MF_All_2010_Liable_Files.Amount} = 0.00
Reset=Never
Create a final formula to get your sum as:
Sum ({@Conversion}) - (({#Count}-{#DistinctCount})*600)
 
IP IP Logged
jruotolo
Newbie
Newbie


Joined: 23 Jul 2009
Location: United States
Online Status: Offline
Posts: 7
Quote jruotolo Replybullet Posted: 24 Jul 2009 at 1:37pm
That makes a lot of sense.  When I was reading it, my eyes lit up Tongue.

I will be working on this Monday and will let you know how it goes.

Thanks!!


IP IP Logged
Page  of 2 Next >>
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