SAP Business One Sales Opportunities: Set Up Your Pipeline and Measure It with SQL - tutorial featured image

Publications

SAP Business One Sales Opportunities: Set Up Your Pipeline and Measure It with SQL

Hector Pincheira

Hector Pincheira

CIO | CTO
Digital Strategy & Technology Innovation

items

Configuring SAP Business One Sales Opportunities is the difference between a sales forecast that holds up and one that gets reinvented every Monday morning. I know few scenes more uncomfortable than a sales committee where the general manager asks how much we will invoice next quarter and the answer arrives wrapped in adjectives: it looks good, the customer is excited, I think this one closes. Nobody is lying. The problem is that the information lives scattered across the heads of four salespeople, a spreadsheet only its author understands, and a notebook that gets soaked when it rains.

The module is right there, installed, paid for, and almost always switched off. Therefore, the company ends up buying an external CRM to solve a problem its own ERP already solved, and along the way adds one more integration to maintain. In this tutorial we are going to switch it on: first the stage setup, then the opportunity record, and finally three SQL queries that turn that record into numbers you can defend in front of anyone.

The pipeline that lives inside the salesperson's head

An undocumented pipeline is not a pipeline: it is a rumour shaped like a meeting. When the salesperson resigns, the entire portfolio walks out with them, and the replacement starts from zero calling customers who had already said no. Besides, without a record there is no way to know at which stage the deal falls apart, and that is precisely the data point that lets you fix the process instead of scolding people.

Research on commercial management has been pointing in the same direction for years. Harvard Business Review published a 2015 analysis of B2B companies in which those with a formally defined sales process showed revenue growth up to 28% higher than those that improvised. The mechanism is not magic: what gets measured gets discussed, and what gets discussed gets corrected.

SAP Business One Sales Opportunities - sales team reviewing the pipeline
The pipeline stops being a hallway conversation once every stage is recorded.

Why you need SAP Business One Sales Opportunities

There are four concrete things you gain by turning the module on, and none of them requires extra licences if you already have Professional users.

Weighted forecast. Each stage carries an associated closing percentage. This way, the system calculates on its own what your funnel is really worth, instead of adding everything up as if every opportunity were money in the bank.

Measurable sales cycle. With the opening date and the closing date you can tell how many days your company takes to turn interest into an invoice. That number is the basis of any serious cash projection.

Loss reasons. Recording why a deal was lost hurts at first and pays off later. If 40% of the losses say price and the rest say delivery lead time, you have two very different conversations ahead: one with finance and another with operations.

Continuity. The portfolio stays in the database, not on the sales rep's personal phone. It sounds obvious. In practice, it is the reason more than one company finally decided to implement it.

Prerequisites

  • SAP Business One 9.3 or higher, on SQL Server or SAP HANA.
  • A user with a Professional or CRM licence to operate the module.
  • Superuser permissions to edit Administration > Setup > Opportunities.
  • A populated Business Partner master, including potential customers (Lead type).
  • A Sales Employee master with active salespeople and their codes.
  • Access to Query Manager or a read-only SQL tool for the reports.

Set up SAP Business One Sales Opportunities step by step

Step 1: define the funnel stages

Go Administration > Setup > Opportunities > Sales Stages. You will see a table with columns for sequence number, name and closing percentage. Next, define your real stages, not the ones from the manual.

A scheme that works in industrial companies:

  1. 1 - Initial contact, 10%
  2. 2 - Qualified need, 25%
  3. 3 - Technical visit or sample, 40%
  4. 4 - Quotation sent, 60%
  5. 5 - Final negotiation, 80%
  6. 6 - Close, 100%

Keep between five and seven stages. With more, salespeople stop updating them; with fewer, the weighted forecast loses resolution. The percentage must reflect your real conversion history, so if you have never measured it, start with these values and correct them in six months with the data the system itself will have accumulated.

Step 2: configure loss reasons and sources

In the same Setup menu you will find Loss Reasons and Opportunity Sources. Load the reasons using the vocabulary your team actually uses: price, delivery lead time, technical specification, competition, postponed project, no budget. For the sources, distinguish at least between referral, field visit, website, trade show and existing customer.

This setup looks bureaucratic. However, it is the only one that later lets you answer business questions instead of system questions: how much a referral converts compared with a trade show contact, for example, and whether it is worth continuing to pay for the booth.

Step 3: create the opportunity

Go to Opportunities > Sales Opportunity. The fields that truly matter are these:

  • Business partner: customer or lead. If it does not exist yet, create it as a Lead from the same screen.
  • Sales employee: never leave it empty.
  • Start date and expected closing date: the second one feeds the forecast by period.
  • Potential amount: the estimated value of the deal.
  • Interest level and source.

Here comes the warning that has cost me dearly more than once: if you leave the salesperson field optional, six months later a third of your pipeline will have no owner and the commission report will not reconcile with anything. Make it mandatory with a validation in SP_TransactionNotification or with a formatted search that fills it from the business partner.

Step 4: record progress by stage

in the tab Stages tab of the opportunity, a line is added every time the deal moves forward. Each line stores the stage, its percentage, the start date and, optionally, the linked document. For example, when you reach Quotation sent you can link the actual SAP quotation, so the funnel number stops being a hand-made estimate.

That link is, to my taste, the best part of the module and the one SAP documents worst. It connects the soft world of CRM with the hard world of marketing documents, and it does so without a single line of development.

Step 5: close the opportunity

When the deal is settled, tick the closing checkbox and set the status: won or lost. If it was lost, the reason is mandatory provided you configured it that way. As a result, your database starts accumulating the most valuable data in the whole module, which is not the won deals but the lost ones.

One practical detail you only learn by using it: the amount field is stored in local currency in MaxSumLoc and in system currency in MaxSumSys. If you sell in dollars and your local currency is the peso, picking the wrong column leaves you with a pipeline inflated by the exchange rate.

SQL queries: measure the pipeline for real

The module screen is for operating. For managing, you need SQL. The three queries below cover 90% of what a manager asks in a sales committee, and each one comes in its two versions, because the syntax differences between SQL Server and HANA are enough to break a good query.

Few tables are involved: OOPR stores the opportunity header, OPR1 the stage lines, OOST the stage master, OSLP the salespeople and OCRD the business partners. The Status field in OOPR uses 'O' for open, 'W' for won and 'L' for lost.

Query 1: open pipeline and weighted value by salesperson

It answers the committee's question: how much is out there and how much it is really worth.

SQL Server

-- Open pipeline by salesperson, with amount weighted by probability
SELECT
    ISNULL(T2.SlpName, 'Sin asignar')          AS Vendedor,
    COUNT(T0.OpprId)                           AS Oportunidades,
    SUM(T0.MaxSumLoc)                          AS Monto_Total,
    SUM(T0.MaxSumLoc * T0.CloPrcnt / 100.0)    AS Monto_Ponderado
FROM OOPR T0
INNER JOIN OCRD T1 ON T1.CardCode = T0.CardCode
LEFT  JOIN OSLP T2 ON T2.SlpCode  = T0.SlpCode
WHERE T0.Status = 'O'
GROUP BY T2.SlpName
ORDER BY Monto_Ponderado DESC

SAP HANA

-- Open pipeline by salesperson, with amount weighted by probability
SELECT
    IFNULL(T2."SlpName", 'Sin asignar')              AS "Vendedor",
    COUNT(T0."OpprId")                               AS "Oportunidades",
    SUM(T0."MaxSumLoc")                              AS "Monto_Total",
    SUM(T0."MaxSumLoc" * T0."CloPrcnt" / 100.0)      AS "Monto_Ponderado"
FROM OOPR T0
INNER JOIN OCRD T1 ON T1."CardCode" = T0."CardCode"
LEFT  JOIN OSLP T2 ON T2."SlpCode"  = T0."SlpCode"
WHERE T0."Status" = 'O'
GROUP BY T2."SlpName"
ORDER BY "Monto_Ponderado" DESC

The column CloPrcnt column is the opportunity's closing percentage. Incidentally, the abbreviated field name is one of those SAP design decisions you appreciate very little: searching the documentation for ClosePercent returns nothing.

SAP Business One Sales Opportunities - win rate and sales cycle analysis
Win rate and sales cycle: the two numbers that bring order to any sales committee.

Query 2: win rate and sales cycle length

This query looks backwards, at the last twelve months, and delivers two indicators worth more than any projection: what percentage of closed deals was won and how many days each one took.

SQL Server

-- Win rate and average sales cycle, last 12 months
SELECT
    ISNULL(T1.SlpName, 'Sin asignar') AS Vendedor,
    SUM(CASE WHEN T0.Status = 'W' THEN 1 ELSE 0 END) AS Ganadas,
    SUM(CASE WHEN T0.Status = 'L' THEN 1 ELSE 0 END) AS Perdidas,
    CAST(100.0 * SUM(CASE WHEN T0.Status = 'W' THEN 1 ELSE 0 END)
         / NULLIF(COUNT(T0.OpprId), 0) AS DECIMAL(10,1)) AS Tasa_Cierre_Pct,
    AVG(CASE WHEN T0.Status = 'W'
             THEN DATEDIFF(DAY, T0.OpenDate, T0.CloseDate) END) AS Dias_Ciclo_Promedio
FROM OOPR T0
LEFT JOIN OSLP T1 ON T1.SlpCode = T0.SlpCode
WHERE T0.Status IN ('W','L')
  AND T0.CloseDate >= DATEADD(MONTH, -12, GETDATE())
GROUP BY T1.SlpName
ORDER BY Tasa_Cierre_Pct DESC

SAP HANA

-- Win rate and average sales cycle, last 12 months
SELECT
    IFNULL(T1."SlpName", 'Sin asignar') AS "Vendedor",
    SUM(CASE WHEN T0."Status" = 'W' THEN 1 ELSE 0 END) AS "Ganadas",
    SUM(CASE WHEN T0."Status" = 'L' THEN 1 ELSE 0 END) AS "Perdidas",
    ROUND(100.0 * SUM(CASE WHEN T0."Status" = 'W' THEN 1 ELSE 0 END)
          / NULLIF(COUNT(T0."OpprId"), 0), 1) AS "Tasa_Cierre_Pct",
    AVG(CASE WHEN T0."Status" = 'W'
             THEN DAYS_BETWEEN(T0."OpenDate", T0."CloseDate") END) AS "Dias_Ciclo_Promedio"
FROM OOPR T0
LEFT JOIN OSLP T1 ON T1."SlpCode" = T0."SlpCode"
WHERE T0."Status" IN ('W','L')
  AND T0."CloseDate" >= ADD_MONTHS(CURRENT_DATE, -12)
GROUP BY T1."SlpName"
ORDER BY "Tasa_Cierre_Pct" DESC

Notice the NULLIF: without it, a new salesperson with no closed deals blows up the query with a division by zero. It is the kind of detail that does not show up until the report runs on a Monday at eight in the morning.

Query 3: stalled opportunities

A pipeline nobody cleans fills up with zombie deals that keep adding to the forecast with no activity behind them. This query brings them to light using the last stage movement date recorded in OPR1.

SQL Server

-- Open opportunities with no stage progress for more than 30 days
SELECT TOP 50
    T0.OpprId                    AS Oportunidad,
    T1.CardName                  AS Cliente,
    ISNULL(T2.SlpName, 'Sin asignar') AS Vendedor,
    T0.MaxSumLoc                 AS Monto,
    T0.PredDate                  AS Cierre_Previsto,
    MAX(T3.StartDate)            AS Ultimo_Movimiento,
    DATEDIFF(DAY, MAX(T3.StartDate), GETDATE()) AS Dias_Sin_Avance
FROM OOPR T0
INNER JOIN OCRD T1 ON T1.CardCode = T0.CardCode
LEFT  JOIN OSLP T2 ON T2.SlpCode  = T0.SlpCode
INNER JOIN OPR1 T3 ON T3.OpprId   = T0.OpprId
WHERE T0.Status = 'O'
GROUP BY T0.OpprId, T1.CardName, T2.SlpName, T0.MaxSumLoc, T0.PredDate
HAVING DATEDIFF(DAY, MAX(T3.StartDate), GETDATE()) > 30
ORDER BY Dias_Sin_Avance DESC

SAP HANA

-- Open opportunities with no stage progress for more than 30 days
SELECT
    T0."OpprId"                          AS "Oportunidad",
    T1."CardName"                        AS "Cliente",
    IFNULL(T2."SlpName", 'Sin asignar')  AS "Vendedor",
    T0."MaxSumLoc"                       AS "Monto",
    T0."PredDate"                        AS "Cierre_Previsto",
    MAX(T3."StartDate")                  AS "Ultimo_Movimiento",
    DAYS_BETWEEN(MAX(T3."StartDate"), CURRENT_DATE) AS "Dias_Sin_Avance"
FROM OOPR T0
INNER JOIN OCRD T1 ON T1."CardCode" = T0."CardCode"
LEFT  JOIN OSLP T2 ON T2."SlpCode"  = T0."SlpCode"
INNER JOIN OPR1 T3 ON T3."OpprId"   = T0."OpprId"
WHERE T0."Status" = 'O'
GROUP BY T0."OpprId", T1."CardName", T2."SlpName", T0."MaxSumLoc", T0."PredDate"
HAVING DAYS_BETWEEN(MAX(T3."StartDate"), CURRENT_DATE) > 30
ORDER BY "Dias_Sin_Avance" DESC
LIMIT 50

Variations and use cases

Forecast by expected closing month. Change the grouping in Query 1 to the period of PredDate. In SQL Server use FORMAT(T0.PredDate, 'yyyy-MM'); in HANA, TO_VARCHAR(T0."PredDate", 'YYYY-MM'). As a result you get the classic monthly funnel that finance needs to project cash.

Conversion by source. Group Query 2 by the source field instead of the salesperson. That way you find out whether the trade show you have attended for eight years still generates deals or only generates travel expenses.

Funnel by stage. join OPR1 with OOST and count how many opportunities reached each stage during the year. The drop between two consecutive stages tells you where the process breaks; usually it is not where the team thinks.

Automatic alerts. Set Query 3 inside the SAP Alerts Management and schedule a weekly send to the sales manager. This way, cleaning the pipeline stops depending on somebody remembering.

Compare potential with actual billing. Link the won opportunity with the documents in OPR1 and compare MaxSumLoc against the total invoiced to that customer over the following 90 days. The gap between what was promised and what was collected is an uncomfortable and very useful indicator.

Best practices and common mistakes in SAP Business One Sales Opportunities

Define the stages with the team, not for the team. A setup imposed from IT fills up with fake data in three weeks. Sit down with the salespeople, ask them how a deal really moves forward, and translate that into the system.

Do not use optimistic percentages. If you assign 50% to the first stage, your forecast will double reality and you will lose credibility with the general management the first time you present it. Start conservative.

Check the currency. I mentioned it above and I repeat it because it is the mistake I have seen most often in pipeline reports: mixing MaxSumLoc with MaxSumSys in the same query produces meaningless totals.

Watch out for opportunities with no stage lines. Query 3 uses an INNER JOIN against OPR1, therefore an opportunity created and never worked on will not show up in the stalled list. If you want to catch those, switch that JOIN to a LEFT JOIN and evaluate T0.OpenDate.

Do not turn the module into a policeman. In version 9.3, if memory serves, several companies started using the pipeline to measure daily salesperson activity and the outcome was predictable: inflated records and zero analytical value. The module is there to understand the business, not to watch over people.

Close the lost opportunities. It sounds obvious and almost nobody does it. A pipeline with deals from 2023 still open is not a database: it is a rubbish bin with write permissions.

Official SAP Resources

Conclusion

Turning sales opportunities on does not change a company's commercial culture by itself. What it does is more modest and more useful: it puts on the table data that used to be opinions, and it forces sales conversations to happen over evidence. The first month will be uncomfortable, because the real pipeline almost always turns out smaller than the imagined one. From the third month on, however, you start seeing patterns no spreadsheet would have shown you, and the forecast stops being an act of faith.

Start today with the bare minimum: six stages, five loss reasons and Query 1 running every Monday. With that you are already measuring more than 80% of the industrial SMEs in the region.

Want to go deeper? In the Strategic Circle I share the extended versions of these tutorials, the queries ready to import into Query Manager, and the support to adapt them to your own reality. If this article helped you, tell me in the comments at which stage your funnel breaks down the most; that is the data point that generates the most learning among those of us reading this.

Most Read

QlikSense Hierarchy: parent-child chart of accounts expanded by levels
QlikSense Hierarchy: the Chart of Accounts That Doesn't Add Up
QlikSense Sum TOTAL: share of each family over the total
QlikSense Sum TOTAL: the Percentage That Changes When You Filter
SAP Business One Inventory Revaluation - featured image of the tutorial
SAP Business One Inventory Revaluation: Fix Wrongly Loaded Costs
Empty chamber with wooden benches: the counterweight that required being present to be used
The Veto You Had to Say in Person: Your Decisions With No Counterweight
SAP Business One customizations - featured image of the pre-upgrade audit tutorial
SAP Business One Customizations: Pre-Upgrade Audit
SAP Business One Customer Concentration - featured image of the tutorial
SAP Business One Customer Concentration: Measure Your Risk with SQL

RELATED ARTICLES