Understanding the revenue that any given account generates in a fiscal year can yield valuable insights, guide decisions, and shape your business strategies. For example, it can identify your top revenue-generating accounts, help assess the impact of specific sales initiatives, forecast your sales more accurately, and customize your outreach efforts based on customer value.
Creating a custom deals report—grouped by account name and filtered by closing date—can help you identify the revenue any given account generates in a fiscal year. However, to trigger revenue-specific automations or campaigns—like alerts when an account hits a specific revenue threshold—you have to store the account's annual sales data in the account's record.
Alternatively, you can use a rollup summary field to capture the total sales amount, but remember that you can't filter it by date like a fiscal year. In these circumstances, using a custom function is the most effective approach.
All you need to do is create a workflow rule that triggers whenever a deal is marked as closed-won and updates the account record with the total sales amount computed for the specified fiscal year. Read on to learn more.
Permissions and availability
- Users with the Modules Customization permission can add custom fields.
- Users with the Manage Automation permission can create and update workflow rules.
- Users with the Manage Extensibility permission can create custom functions.
- Users with the Manage Sandbox permission can manage the sandbox.
Requirements
- Add a Currency field in the Accounts module that holds the total amount of sales for the fiscal year. Learn more
- Create a workflow rule for the Deals module that triggers every time a deal is marked as closed-won. Learn more
- Write a custom Deluge function and link it to the workflow rule. Learn more
- Test the workflow rule in a sandbox before deploying it to your production environment. Learn more
Add a custom field
The first step is to add the custom currency field to the Accounts module.
- Navigate to Setup > Customization > Modules and Fields.
- Click the Accounts module to open the layout editor.
- Drag and drop the Currency field from the New Fields tray to the desired section of the layout.
- Name the currency field (e.g., "Total Sales In Amount") and define its properties as required.
- Once you have finished, click Save and Close.
Create a workflow rule
The next step is to create a workflow rule in your CRM account.
- Navigate to Setup > Workflow Rules > +Create Rule.
- Select Deals from the module dropdown list.
- Provide a name for the rule. For example: "Calculate sales for fiscal year".
- Add a description (optional), then click Next.
- In the Execute this workflow rule based on section, do the following:
- Choose Record Action, then select Create or Edit from the dropdown.
- Check the Repeat this workflow whenever a deal is edited option.
- Click Next.
- In the Which deals would you like to apply the rule to? section, specify the condition as "<Stage> <is> <Closed Won> and click Next. You can also select <Stage> <is WON> if multiple stages indicate the won stage.
- Under Instant Actions, select Function and Write your own.
- Provide a Name for the function, as well as a description, if necessary.
- In the Deluge Script Editor, do the following:
- Copy and paste the code given below.
- Click Edit Arguments.
- Enter the name as accountId, select the value as Accounts - Account Id, then click Save.
- Click Save & Execute script.
- Click Save on the workflow rule page.
The code
startDate = "2025-04-01";
endDate = "2026-03-31";
deals = zoho.crm.getRelatedRecords("Deals","Accounts",accountId);
totalSalesAmount = 0;
for each deal in deals
{
if(deal.get("Stage") == "Closed Won")
{
closedDate = deal.get("Closing_Date").toDate();
if(closedDate >= startDate && closedDate <= endDate)
{
totalSalesAmount = totalSalesAmount + deal.get("Amount");
}
}
}
info "totalSalesAmount : " + totalSalesAmount;
accountData = Map();
accountData.put("Total_Sales_In_Amount",totalSalesAmount);
info "accountData : " + accountData;
updateResponse = zoho.crm.updateRecord("Accounts",accountId,accountData);
info "updateResponse : " + updateResponse;Notes
- Make sure to use the accurate API names for their corresponding fields (e.g., "Total Sales In Amount") in the code snippet. Learn more
- Customize the start and end dates in the code snippet to compute total sales for a specific timeframe.
- You can use a scheduled function to summarize sales for a specific fiscal year and run the function periodically—such as daily, weekly, or monthly. This approach keeps the totals updated without requiring user intervention.
- The code above is an example that auto-calculates and updates the total sales for an account for the current fiscal year. You can use this code for different periods or modules by modifying the module names and parameters.
Tip
- Configure and test the function in a sandbox to ensure that further development doesn't disrupt your production environment.
Test the solution
- Navigate to Deals > + Create Deal.
- On the Deal Details page, enter the Account Name related to the deal, enter the amount, and fill in the other fields. Make sure the stage is marked as "closed won," then click Save.
- Check whether the account associated with the deal correctly reflects the amount in its Total Sales in Amount field.
- Try creating new closed-won deals or marking existing ones as closed-won to verify if their amounts are summed up in their related accounts.
Did you find this useful? Try it out and let us know how it works. Share this with your team if they'd benefit from it! If you have questions, please don't hesitate to contact us.
More info
- ModuleAccounts
- Trigger PointWorkflow Rule
- EditionEnterprise and above
- ComplexityMedium
- Implementation Time30 minutes

Looking for a custom solution?
Contact us, we will help enhance your productivity at lightning speed.
SUBMIT REQUEST