Print Page | Close Window

Subtracting amount credit/debit

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=17819
Printed Date: 28 Apr 2024 at 9:21am


Topic: Subtracting amount credit/debit
Posted By: esther31
Subject: Subtracting amount credit/debit
Date Posted: 22 Oct 2012 at 2:01am
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



Replies:
Posted By: DBlank
Date Posted: 22 Oct 2012 at 3:59am
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


Posted By: comatt1
Date Posted: 22 Oct 2012 at 4:59am
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


Posted By: esther31
Date Posted: 25 Oct 2012 at 10:03pm
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?


Posted By: esther31
Date Posted: 26 Oct 2012 at 1:35am
Hello
 
Sorry just to add, there may be multiple credit and debit records, will this still work?
 
Thanks


Posted By: esther31
Date Posted: 29 Oct 2012 at 12:56am
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


Posted By: DBlank
Date Posted: 29 Oct 2012 at 3:51am

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.


Posted By: esther31
Date Posted: 30 Oct 2012 at 12:39am
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!


Posted By: DBlank
Date Posted: 30 Oct 2012 at 4:04am

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.
 


Posted By: esther31
Date Posted: 31 Oct 2012 at 1:18am
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
 


Posted By: DBlank
Date Posted: 31 Oct 2012 at 3:38am
so you want to remove groups that have a sum = to a particular field?
what is the field type of SFE_CFEE?


Posted By: esther31
Date Posted: 01 Nov 2012 at 11:49pm
Hello
 
Yes that's correct, the SFE_CFEE is a string which i'm guessing is where it's failing.
 
Thanks


Posted By: esther31
Date Posted: 04 Nov 2012 at 9:15pm
Do i need to convert the number into text?


Posted By: DBlank
Date Posted: 05 Nov 2012 at 3:55am
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
maximum( mailto:%7b@number_FEE%7d,%7bgroup - {@number_FEE},{group })
 
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( mailto:%7B@number_FEE%7D,%7Bgroup - mailto:%7b@number_FEE%7d,%7bgroup field%7d%29=sum%28%7bother_formula%7d,%7bgroup - {@number_FEE},{group  field})=sum({other_formula},{group field})
 


Posted By: esther31
Date Posted: 06 Nov 2012 at 4:04am
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
 


Posted By: DBlank
Date Posted: 06 Nov 2012 at 4:12am
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


Posted By: esther31
Date Posted: 06 Nov 2012 at 4:50am
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
 


Posted By: DBlank
Date Posted: 06 Nov 2012 at 5:22am
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( mailto:%7B@number_FEE%7D,%7Bgroup - mailto:%7b@number_FEE%7d,%7bgroup field%7d%29=sum%28%7bother_formula%7d,%7bgroup - {@number_FEE},{group  field}) + sum({other_formula},{group field}) = 0
 


Posted By: esther31
Date Posted: 06 Nov 2012 at 5:38am
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


Posted By: esther31
Date Posted: 08 Nov 2012 at 12:50am
Can anybody help with this please? Everytime i feel like i'm a step closer I seem to undo what i've already done!


Posted By: DBlank
Date Posted: 08 Nov 2012 at 1:40am
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.


Posted By: esther31
Date Posted: 08 Nov 2012 at 1:50am

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


Posted By: DBlank
Date Posted: 08 Nov 2012 at 3:53am
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( mailto:%7B@number_FEE%7D,%7Bgroup - mailto:%7b@number_FEE%7d,%7bgroup field%7d%29=sum%28%7bother_formula%7d,%7bgroup - {@number_FEE},{group  field}) = abs(sum({other_formula},{group field}))
 


Posted By: esther31
Date Posted: 11 Nov 2012 at 9:15pm
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


Posted By: esther31
Date Posted: 13 Nov 2012 at 3:16am
Sorry, can anyone offer any guidance?
 
Thanks


Posted By: DBlank
Date Posted: 13 Nov 2012 at 3:41am
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. .
 
maximum( mailto:%7B@number_FEE%7D,%7Bgroup - mailto:%7b@%7d,%7bcustomer - {SFU_CFEE.SFU},{table.customer }) = abs(sum( mailto:%7b@Pos&Neg%7d,%7bgroup - {@Pos&Neg},{table.customer }))


Posted By: esther31
Date Posted: 13 Nov 2012 at 3:51am
i've created this:
 
maximum({SRS_SFE.SFE_CFEE},{SRS_SFE.SFE_STUC}) = abs(sum( mailto:%7b@Sum - {@Sum of CorD},{SRS_SFE.SFE_STUC}))
 
It's saying a string is required?
 
 


Posted By: DBlank
Date Posted: 13 Nov 2012 at 3:59am
what did it highlight?


Posted By: esther31
Date Posted: 13 Nov 2012 at 4:00am
abs(sum( mailto:%7b@Sum - {@Sum of CorD},{SRS_SFE.SFE_STUC}))
this bit, thanks


Posted By: DBlank
Date Posted: 13 Nov 2012 at 4:20am
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( mailto:%7b@NumberCheck%7d,%7bSRS_SFE.SFE_STUC - {@NumberCheck},{SRS_SFE.SFE_STUC }) = abs(sum( mailto:%7b@Sum - {@Sum of CorD},{SRS_SFE.SFE_STUC}))


Posted By: esther31
Date Posted: 13 Nov 2012 at 4:27am
perfect thank you :)


Posted By: esther31
Date Posted: 13 Nov 2012 at 4:34am
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
 


Posted By: DBlank
Date Posted: 13 Nov 2012 at 4:37am
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)


Posted By: esther31
Date Posted: 13 Nov 2012 at 4:40am
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?


Posted By: DBlank
Date Posted: 13 Nov 2012 at 4:47am
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.


Posted By: esther31
Date Posted: 13 Nov 2012 at 5:02am
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


Posted By: DBlank
Date Posted: 13 Nov 2012 at 7:03am

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.
 
 


Posted By: esther31
Date Posted: 13 Nov 2012 at 9:38pm
Sorry, i dont understand, how do i do this?


Posted By: esther31
Date Posted: 16 Nov 2012 at 4:04am
Can anyone help with this please?
 
 



Print Page | Close Window