In this article we will show how to calculate weighted scores for a collection of records using North52 BPA. We will demonstrate this using Opportunities connected to an Account. When the estimated value or probability of closing change, we will recalculate the weighted scores for all open opportunities on that account and then update the Account's description field with the name of the highest rated opportunity and it's calculated score.

North52 BPA Solution

The North52 BPA solution works like this:

  • A formula will fire whenever the Est. Revenue or Probability fields change on an Opportunity 
  • The formula will gather a list of all the Opportunities connected to that Account 
  • A weighted score will be calculated for each Opportunity as follows: Est. Revenue * (probability / 100) 
  • The list is then sorted by the weighted score in descending order
  • The (now) first record in the list is selected as it has the highest weighted score

Setup Formula

  • Navigate to Settings -> N52 Formula 
  • Create a new formula, setting the following values in the Formula Guide:
    • Source Entity set to Opportunity 
    • Set Formula Type to Save - Perform Action
    • Select the Classic editor
    • Click Create 
    • Change the Name of the formula to Opportunity - Calculated Weighted Scores
    • Expand Source & Target 
    • Under Source Property, Ctrl-Click the Est. Revenue field and the Probability field
  • Copy and paste the following formula into the Classic editor 
    ifTrue(ContainsData([opportunity.closeprobability], [opportunity.estimatedvalue]),
      xCacheLoadLocal('allOpps', FindRecordsFD('FindRelatedOpportunities', true, SetParams([opportunity.customerid]))),
      xCacheAddCalculatedFieldLocal('allOpps', 'weightedscore', 'double', 'estimatedvalue * (closeprobability/100)'),
      xCacheFilterLocal('allOpps', '', 'weightedscore DESC'), 
      SetVar('oppId', xCacheGetLocal('allOpps', 'opportunityid', '', 0)),
      SetVar('weightedResult', xCacheGetLocal('allOpps', 'weightedscore', '', 0)),
          FindValueQuickName('opportunity', GetVar('oppId')) + ' has the highest weighted value: ' + GetVar('weightedResult'))
  • Click Save 

Add fetch-XML record to the Formula

  • Click on the Fetch-XML tab on the right of the screen and then click on the plus(+) icon
  • In the new window that opens set the Name to be FindRelatedOpportunities
  • In the Query field paste in the following Fetch-XML:
    <fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
      <entity name="opportunity">
        <attribute name="name" />
        <attribute name="customerid" />
        <attribute name="estimatedvalue" />
        <attribute name="statuscode" />
        <attribute name="opportunityid" />
        <attribute name="closeprobability" />
        <order attribute="name" descending="false" />
        <filter type="and">
          <condition attribute="customerid" operator="eq" value="{0}" />
          <condition attribute="statecode" operator="eq" value="0" />
          <condition attribute="closeprobability" operator="not-null" />
          <condition attribute="estimatedvalue" operator="not-null" />
  • Click Save

You are now ready to test the formula.


Create an Account with several Opportunities on it with varying values for Est. Revenue and Probability.

As you change the values, the description field on the account will update to state which is the Opportunity with the highest weighted score.

Did you know?

North52 helps with Approvals and Routing in Dynamics 365

Every organization is different and thus has different approval and routing requirements. 

When there is complexity involved in your requirements, North52's Decision Tables can help simplify that complexity. Our no-code editor helps you build your approval/routing rules easily.

Learn more about North52 Decision Tables