web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How can i create a gross profit margin field that calculates the %

(0) ShareShare
ReportReport
Posted on by 180

Hi

I am trying to create a field in Opportunites that tells me the gross profit margin for a deal.

I have created a gross profit field which subtracts the resource cost from the estimated revenue to give me a gross profit figure but I would like a % field to tell me the margin

 

Please can anyone advise how to set this up and what script I would need to add?

 

many thanks!!!

 

*This post is locked for comments

I have the same question (0)
  • Jeremy Winchell Profile Picture
    1,165 on at

    You could setup this field as a decimal, float or just a basic text field.  The script would be pretty easy to just do:

    crmForm.all.new_grossmarginpct.DataValue = (grossmargin \ estimatedrevenue) * 100

    Jeremy

  • suzi Thurston Profile Picture
    180 on at

    Hi

    thanks for this. Sorry to be dumb here but I'm not sure where to put this code? I already have some other code running in the onsave event and it doesn't seem to let me add it to the same event? where should I put this?

    Sorry I am new to the scripting thing!

    thanks!

    suzi

  • Jeremy Winchell Profile Picture
    1,165 on at

    Suzi,

    Not a problem at all.   Depending on when you would need the calculation to happen will determine where the code should go:

    1. If the user needs to see the value changing as they update the Est. Revenue and/or Actual Revenue, then the best place to put this code would be in the OnChange() events of the Est. Revenue & Actual Revenue.  That way as the user makes changes they'll see the gross margin % update.

    2.  Otherwise, if you just want to make sure it is calculated when the user saves the record then you are fine just putting it in the OnSave() event of Form itself.  

    There really isn't a true limit for how much JavaScript you can put in the OnSave() and OnChange() events of CRM.  Eventually if you start adding thousands of lines of code, then you'll potentially start to see issues plus it makes troubleshooting quite difficult.

    Thanks,

    Jeremy Winchell

  • Eric benco Profile Picture
    320 on at

    so, the only way to have a calculated field is either with javascript or a plugin?  

    If that is the case, I would think that it might be better to do both,  the javascript would used to have a good UX and show the value changing when different values are entered, and the plugin for when data is not input thru a form (eg Data Import).  

    Please correct me if I'm wrong in my assumptions

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans