+ Start a Discussion
Sandeep M 1Sandeep M 1 

formula for remaining days while entering new record

I have two fields in an object, Total_Casual_Leaves__c (Formula) 15 is constant value for it. Days_Requested__c (Number) that is user input. Now i want to write a formula for Remaining_leaves__c after Days_Requested__c taken. for that i am trying to write something like this

    ISPICKVAL( Type_of_Leave__c , "Casual Leave"),
    ISPICKVAL(Type_of_Leave__c, "Sick Leave")
   Total_Casual_Leaves__c -  Days_Requested__c ,
   Total_Sick_Leaves__c  -  Days_Requested__c

Its working fine for one instance but if i create a new record then its taking 15 records as total leaves . If i enter a new record then it must calculate using Remaining_leaves__c. Could any one help me out
Hi Sandeep,

Formula fields are record-independent. They cannot see dat from other records. The best way to achieve this is to have another parent object (Something like Leave Applicant) as a parent in a master-detail relationship and have your Leave object as its child. This way, you can have rollup summary fields on the Leave Applicant object which count and display the number of Casual Leaves and remaining days for leaves created under it. Then, on the leave object records, you can create formula fields to show/calculate remaining days based on the values in the parent Leave Applicant record.

For help on rollup summary fields, please see: https://help.salesforce.com/HTViewHelpDoc?id=fields_about_roll_up_summary_fields.htm&language=en_US

If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.

when you set the default value as 15 for all the new records it shows as 15 and then calculate the value based on the input you give on that particular record. For it to remember the balance, you need to store the leave balance on a parent record if you are creating these records as child records. Hope this helps !!