Hello everyone, and welcome back to our series!
In Zoho Books, the Item Amount in invoices is calculated by multiplying the Quantity and Rate fields. Previously, we shared a
function to include a custom field in this calculation. Today, we are taking it a step further to make it even more versatile for various business needs. Instead of just one custom field, you can include two custom fields to determine the Item Amount.
Item Amount = Custom Field 1 × Custom Field 2 × Rate × Quantity
Consider Mr. John Hector, who runs a steel production plant. He processes orders for steel sheets according to their dimensions. For accurate billing, he can utilize today's function. When creating the invoice, John can enter the length and width of each steel sheet into the custom fields and specify the number of sheets ordered, and the rate per square foot in the default fields. The function will automatically calculate the Item Amount using this formula:
Item Amount = Length × Width × Quantity × Rate![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1720794448848.png&blockId=edbsn112fdd58a281a969e9ddfd5bab4cfe260a23bef675198db5cfe90a10b8f925df&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
Prerequisites:
1. Create a Connection named "zbooks" to successfully execute the function. You can watch the GIF attached below to know how to create the connection.
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1720794476887.gif&blockId=edbsn71fe37bc7e2543cbfe1a552641bd2a428dc2ba8d094dead601fbed351d8ffe0a&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
2. Create the third (Length) and fourth (Width) variables as item-level custom fields (Decimal type) to be displayed in the sales transactions.
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1720794731279.png&blockId=edbsna9a88b66307e81c5264bc0d0e68bdbbca0e2beab525c06c0eb9c1eb5cb805dde&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1720794748552.png&blockId=edbsn71fe37bc7e2543cbfe1a552641bd2a42aaf43a7faec33912c54a13885fe48333&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
3. Similarly, create another custom field called " Unit Rate" to be displayed in the item table. The purpose of this custom field is to store the original sales rate of the line item.
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1720794856359.png&blockId=edbsn58ec63ca11ea335d056324a9bd4cd08df14f79e66fb0cd56aeb6914b08034922&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
Custom Function:
Navigate to Settings -> Automation -> Workflow Actions -> Custom Functions -> +New Custom Function -> Add the function code from this
GitHub link -> Save.
Workflow Rule:
Go to Settings -> Automation -> Workflow Rules -> +New Workflow Rule and set up the workflow rule as shown below:-
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1720794894553.png&blockId=edbsn58ec63ca11ea335d056324a9bd4cd08defc23ee6f1a3a15aacff9423b0a0e58a&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1720794918299.png&blockId=edbsnb891045afa63550772a8c58ba755153491adcd1096766004708927d0a7217ad6&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
In the final step of this workflow rule, associate the custom function you created and then hit Save.
Here's how the function will work:
The custom function will be executed once the invoice is saved. Initially, it copies the original sales rate to the Unit Rate (Custom) field. Then, it multiplies Length × Width × Unit Rate and populates the result in the Rate (Default) field. Following this, Zoho Books calculates Rate (Default field) × Quantity and fills the result in the Amount field.
Note: If you wish to hide the "Rate" - default field at the template level, go to Settings > Customisation > PDF Templates > Invoices > Edit > Table > Disable the checkbox for Rate field > Save. Now, the Custom Field 1 (Length), Custom Field 2 (Width), Unit Rate (Custom Field), Quantity and the Amount field will be displayed on the invoices.
![](https://desk.zoho.com:443/support/ImageDisplay?downloadType=uploadedFile&fileName=1720795012396.png&blockId=edbsn58ec63ca11ea335d056324a9bd4cd08dc3b89e13340e87d96d526d282528f4dc&zgId=edbsn7709df772cce2825696f51e4f4f5fe02&mode=view)
If you have to incorporate two extra values into your Item Amount calculation, this function is perfect for you. For further customization or assistance, please reach out to our Support team at
support[at]zohobooks[dot]com. We're here to help!
Regards,
Shireen Farhana
Zoho Cares