Hello Community!
I am reaching out to see if anyone has created or can help troubleshooting a field i am trying to create. We work a lot in proration, depending on when a tenant is moving in. Side Note: We do all of our contracts and billing outside of HubSpot and that wont change. What i would like to do is create a calculation field that creates a prorated amount based on the deal amount, move-in date, and the amount of time left in the closing month. I have turned on the function to show the elapsed or future time for date fields, but that doesnt help when looking at the full month.
Thank you for your replies/help in advanced!
Hi @NRevane7,
Generally, HubSpot allows for calculation using a dedicated property type: Create calculation and rollup properties
What you’re describing does however seem to have a complexity that is too much for the fairly basic calculation formula builder. It sounds like this may have to be done with a custom code action (available in Operations Hub Professional and Enterprise) in a workflow: Workflows | Custom Code Actions - HubSpot docs
Using Node.js and Python, you could perform any calculations you’d like.
Best regards!
Hey @NRevane7
To add on to what Karsten shared, we can do this using vanilla JS:
function calculateProratedAmount(dealAmount, moveInDate) {
const date = new Date(moveInDate);
const moveInDay = date.getDate();
const totalDaysInMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
const daysRemaining = totalDaysInMonth - moveInDay + 1; // Include the move-in day
const proratedAmount = dealAmount * (daysRemaining / totalDaysInMonth);
return proratedAmount;
}
Either by utilizing Custom Coded Workflow Actions or via webhooks and middleware you set up to handle this and use a similar workflow:
HubSpot → Webhook → Your Middleware → HubSpot API → Updated Deal
Have fun testing! — Jaycee