Subtracting amount credit/debit

Printed From: Crystal Reports Book — Forum Name: Technical Questions

Hello
 
I need to display the total of a sum based on a field value. I basically need to sum all records where a field = "Credit and all those where a field ="Debit" and then subtract the credit total from the debit total to get the overall total. Can you advise how to do this please. i've tried using groups, running totals and formulas but am getting myself in a mess. Any help would be greatly appreciated.
 
Thanks
Esther
tehre are a lot of ways to do this but if youa re not dealing with any duplicate data the easiest is to create 3 formulas to use.
//credits
if {table.typefield}='credit' then {table.amountfield}
//debits
if {table.typefield}='debit' then {table.amountfield}
//together
if {table.typefield}='credit then {table.amountfield} else {table.amountfield} *(-1)
 
now you can sum each of these at any grouplevel to get the values you want
Do you have to deal with voids? I do lots of accounting reports, and I get a little worried when I don't see voids in the logic
Sorry, I can't seem to get this to work
 
I have setup three formula fields:
 
credit: if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT}
 
debit: if {SRS_FDU.FDU_CORD}='D' then {SRS_FDU.FDU_AMNT}
 
together: if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT} else {SRS_FDU.FDU_AMNT} *(-1)
 
what do i need to do next?
Hello
 
Sorry just to add, there may be multiple credit and debit records, will this still work?
 
Thanks
it may be that there are multiple credits and debits for one customer so for each customer i need to sum the credits, sum the debits and then sum the too and compare this amount to a different field. Any ideas please?
 
Thanks

as you created each of the formulas did you place it on the detail row to make sure it was giving you the correct value per formula per row?

if so then you just need to insert a summary as a SUM for each of the formulas at each of the footer levels you want to see results in.


Edited by DBlank - 30 Oct 2012 at 3:52am
Hello
 
This isn't working and i'm now getting myself completely confused!
 
If i've grouped by customer ref where should i be putting the forumals? None of them seem to be calculating correctly.
 
Sorry for being a complete novice!

create one formula called "credits"

if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT}
place it on the detail section.
when you preview the report you should see the actual credit amount on every row that is a credit and a zero on all debit rows.
 
to get totals for just credits, click on the sigma sign (the blue E in the toolbar) to insert a summary.
select the "Credits" formual field
calculate as a SUM
Summary location will be group 1 (customer)
this will create a field in the group footer that is the sum of credits for each customer.
If you want a sum for the whole report repeat teh last step put for the summary location select Grand Total (report footer) as the location.
 
Repeat the process for "Debits" using
if {SRS_FDU.FDU_CORD}='D' then {SRS_FDU.FDU_AMNT}
 
finally create the "Together" using
if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT} else {SRS_FDU.FDU_AMNT} *(-1)
when you place this on the detail row you should see the amount on eery row but if it is a credit is is a positive value if it is a debit it is a negative value.
 
This works perfectly, thank you for you patience and help! I now only want to display records where this summary is not equal to another field {SRS_SFE.SFE_CFEE}, if i try and do a simple suppresion where the fields are equal it says 'a number is required here'
 
Any ideas?
 
Thanks
 
so you want to remove groups that have a sum = to a particular field?
what is the field type of SFE_CFEE?
Hello
 
Yes that's correct, the SFE_CFEE is a string which i'm guessing is where it's failing.
 
Thanks
Do i need to convert the number into text?
convert the text to a numeric field
//number_FEE
val({SRS_SFE.SFE_CFEE})
 
I assume this value is the same for all rows in the group
you can then insert a summary on this formula field at the group level
 
now in the select criteria you change it to the group select criteria and use the summary conditions here to excldue the whole group frmt he report
maximum({@number_FEE},{group field})=sum({other_formula},{group field})
 
Hello
 
Sorry i'm back again!
 
This doesn't seem to be working quite as i would expect it to, I have listed an example below, is anybody able to help me identify where it is going wrong?
 
customer has one credit type{SRS_FDU.FDU_CORD} record of 1,000.00 summing correctly with this forumla :if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT}
 
customer has one debit type{SRS_FDU.FDU_CORD} record of 9,000.00 summing correctly with this formula: if {SRS_FDU.FDU_CORD}='D' then {SRS_FDU.FDU_AMNT}
 
this formula does not seem to be displaying as i would expect:
if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT} else {SRS_FDU.FDU_AMNT} *(-1) -  i would expect to see -8,000.00 but is showing me -9,000.00
 
if i do a sum of this sum then the correct amount is displayed but i am unable to use this to compare with SFE_CFEE as above.
 
any advice?
 
thanks
 
it is showing exactly what it is expected to show.
All the fomrula is doing is leaving credits as a positive value and making debits a negative value. So when you go to sum this formula field it will give you the total of all credits - the total of all debits.
if you need to see it change row by row use a Running Total.
right click on Running Total
select new
name='Total" (or whatever)
field to summarize= the formula field above (if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT} else {SRS_FDU.FDU_AMNT} *(-1) )
summary type=sum
evaluate= for each record
reset=never if you want it to keep showing changes for every row or on change of a group if you want to start fresh on a new grouping
 
place it in the detail row to see row by row changes
place it in a footer to see the total only


Edited by DBlank - 06 Nov 2012 at 5:15am
Thanks for the prompt reply, makes sense to me now.
 
My running total is now displaying the figure as a - but the field i need to compare it to doesn't do this, is there a way to strip this off for the comparison?
 
Thanks
 
is it it corerctly showing as a negative value (meaning there were more debits than credits? If so just add teh 2 values together. If they = 0 then they are 'the same number' (one positive and one negative)
 
maximum({@number_FEE},{group field}) + sum({other_formula},{group field}) = 0
 
not all students will have a credit but i need to compare the total amount without the debit with the SRS_SFE.SFE_CFEE field
Can anybody help with this please? Everytime i feel like i'm a step closer I seem to undo what i've already done!
Cn you show sample data and what you want it to do? I am not really able to follow the logic of your last request as I cannot see your data.

sorry for causing so much confusion! i will list out the relevant fields and then what i am trying to achieve!

FDU_AMNT.FDU = Fee amount generated
FDU_CORD.FDU - Credit or Debit? (C or D)
SFU_CFEE.SFU = Expected Fee on Customer Record
 
The fee amount is always a positive number whether credit or debit and a customer may have multiple debits or credits or no credits. I want to sum FDU_AMNT.FDU where the FDU.CORD.FDU is C, sum them again where the FDU_CORD.FDU is D and then take away the total for C from the total for D but leave a positive number despite the figure being a debit. I then want to compare this total to SFU_CFEE.SFU and then only show records where these two figures don't match.
 
Thank you again for all your support, i am completely stumped!
 
Please let me know if you need any further information
so i assume that the expecgted fee is the same on all of the rows for the group
you should be able to use the abs() function to foece the value to be positive so try this
 
maximum({@number_FEE},{group field}) = abs(sum({other_formula},{group field}))
 
Hello
 
This doesn't seem to work. I have setup a group of customer number, say 12345678 i have then placed the FDU_AMNT in the detail and the FDU_CORD. Customer 12345678 may have a debit record of 500, a credit record of 300 and another debit of 200. I want to be able to sum the debits giving me 700 at the group footer, sum the credits giving me 300 at the group footer then sum the debit minus credit giving me 400. I then want to compare this figure with SFU_CFEE and only display the records where this doesn't match.
 
thanks
Sorry, can anyone offer any guidance?
 
Thanks
use the
if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT} else {SRS_FDU.FDU_AMNT} *(-1) 
(lets call it "Pos&Neg" for this example) formula field to sum, not the FDU_AMT field. .
 
i've created this:
 
maximum({SRS_SFE.SFE_CFEE},{SRS_SFE.SFE_STUC}) = abs(sum({@Sum of CorD},{SRS_SFE.SFE_STUC}))
 
It's saying a string is required?
 
 
what did it highlight?
abs(sum({@Sum of CorD},{SRS_SFE.SFE_STUC}))
this bit, thanks
it appears that the SRS_SFE.SFE_STUC is a string and not a number
convert it to a number first
call the formula "NumberCheck" (or whatever you want)
tonumber({SRS_SFE.SFE_STUC})
 
now us it in the other formula
maximum({@NumberCheck},{SRS_SFE.SFE_STUC}) = abs(sum({@Sum of CorD},{SRS_SFE.SFE_STUC}))
perfect thank you :)
Hello, back again sorry! the sum doesn't seem to be working properly.
 
A customer who has a debit of 9000 and a credit of 1000 is summing as 10000 rather than 8000, any ideas?
 
here's the formula:
 
//together
if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT} else {SRS_FDU.FDU_AMNT} *(1)
 
I am then doing a sum of this though this appears to be doing nothing!
 
thanks
 
it is missing the negative sign at the end (-1)
 
if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT} else {SRS_FDU.FDU_AMNT} *(-1)
If i add the negative sign it makes the comparison fall over as the SFE_CFEE record is not displayed as a negative number, is there a way to strip it our for this bit?
i dont understand your question.
you can use anything you want to display on the detail section (an diffetrnt formual field, the origianl field, etc.) but you have to use the formula with a negative 1 in order to be able to get the correct total.
Sorry, i didn't explain very well. I only want records to show where the value of SFE_CFEE doesn't match the value of
//together
if {SRS_FDU.FDU_CORD}='C' then {SRS_FDU.FDU_AMNT} else {SRS_FDU.FDU_AMNT} *(-1)
 
when i add the minus to the formula all records are returned.
 
Thanks

You are doing a group selection not a record selection.

First you have to pull all records.
Then you have to get the sum and the maximum for each group.
Then you can suppress or exclude entire groups based on the group values that you get.
 
 
Sorry, i dont understand, how do i do this?
Can anyone help with this please?