Marty Zigman

Conversations with Marty Zigman

Certified Administrator • ERP • SuiteCloud

Learn How to Reconstruct NetSuite Actual Margin for Sales Commissions

Accounting ERP NetSuite Reporting



This article is relevant if you need to calculate sales commissions or other performance measures from actual margin in an existing NetSuite account, but the original implementation favored a common-sense transaction flow over a more deliberate NetSuite model. As a result, revenue and cost relationships that could have been made explicit were left to be reconstructed later. Fortunately, NetSuite’s transaction lineage often gives us enough evidence to recover those relationships with confidence.

TL;DR Summary

The arithmetic behind margin is simple:

Revenue – Cost = Margin

The real challenge is determining which actual costs belong to a specific Customer Invoice.

For an existing NetSuite account, we can often reconstruct that relationship by tracing the invoice back to its originating Sales Order, identifying how it was sourced, and then following the appropriate transaction lineage to actual cost.

Our Operations Practice Leader, Hector Cardenas, developed a practical SuiteQL-based method that follows inventory sales to fulfillment COGS and drop-ship or special-order sales to related procurement costs.

The important distinction is between costs NetSuite can prove through transaction lineage and costs that require reasonable allocation or inference. A trustworthy solution should preserve that distinction and explain how it calculated the margin.Blog header: Learn How to Reconstruct NetSuite Actual Margin for Sales Commissions, Part 1 of 2, by Marty Zigman, President and Founder of Prolecto Resources

Background

Note to start.  This is Part 1 of a two-part series. Here, I will discuss how we addressed that question by reconstructing economic relationships from transaction history already present in NetSuite. In Part 2, I explored what changes when we have greater architectural control and can deliberately shape the operating transaction model.

A client had struggled for years to create a dependable sales commission program based on actual margin. Saved Searches had been attempted. Excel tracking sheets had been developed. Yet neither approach could reliably answer the central economic question: what actual cost belonged to each invoiced sale?

I have written for years about the difference between convenient estimates and economically meaningful margin. See, for example, my 2018 article: Learn how to Reliably Measure NetSuite Gross Profit and Margin.  I have also explored commission structures based on cost rather than simply revenue.  See my 2022 article: Drive NetSuite Commissions based on Cost Instead of Revenue.

In this case, however, we were working with an inherited NetSuite transaction model and years of existing history. Redesigning the entire operational process merely to support the commission calculation would have been unnecessarily disruptive.

Hector Cardenas, our Operations Practice Leader, carefully studied the client’s transaction patterns. His insight was to stop treating the problem primarily as a reporting formula and instead treat it as a transaction relationship problem.

That distinction opened the door.

Understanding NetSuite Transaction Lineage Before Calculating Margin

The conceptual attack pattern for solving margin reporting became the following: Start at the customer invoice; then recover the originating Sales Order line; then understand how the Sales Order line was sourced; and then select the appropriate actual-cost method.

This differs fundamentally from matching transactions by item, customer, dollar amount, or transaction date. Those attributes may appear useful, but they are circumstantial.

Where possible, we instead use NetSuite’s native transaction-line lineage.

Two important SuiteQL structures are NEXTTRANSACTIONLINELINK and TRANSACTIONLINE. For example, logic resembling the following allows us to begin with a billed line and recover the commercial line from which it originated:

JOIN nexttransactionlinelink link
  ON link.nextline = line.id
 AND link.nextdoc = line.transaction
 AND link.linktype = 'OrdBill'

Once the Sales Order line is recovered, Hector’s method examines information such as:

line.uniquekey,
line.item, 
-line.netamount AS netamount,
line.costestimate,
soline.createdpo,
soline.dropship,
soline.specialorder

These fields are not simply technical. They help answer a business question: how was this particular revenue line economically supplied?

That produces a Cost Source Method such as Inventory, Drop Ship, or Special Order. No single universal algorithm can determine actual cost because the economic path differs depending on how NetSuite fulfilled the customer’s demand.    Click the image to see the model more clearly.

Reconstructing Actual NetSuite Cost from the Appropriate Source

For an inventory sale, we can follow the originating Sales Order relationship into the fulfillment activity and then inspect the accounting impact associated with COGS.

Selected logic illustrates the approach:

JOIN nexttransactionlinelink fulfillment_link
  ON fulfillment_link.previousdoc = invoice_link.previousdoc
 AND fulfillment_link.previousline = invoice_link.previousline
 AND fulfillment_link.linktype = 'ShipRcpt'

JOIN transaction fulfillment
  ON fulfillment.id = fulfillment_link.nextdoc
 AND fulfillment.type IN ('ItemShip', 'ItemRcpt')

JOIN transactionline fulfillment_line
  ON fulfillment_line.transaction = fulfillment_link.nextdoc
 AND fulfillment_line.id BETWEEN fulfillment_link.nextline
                              AND fulfillment_link.nextline + 2

JOIN transactionaccountingline accounting_line
  ON accounting_line.transaction = fulfillment_line.transaction
 AND accounting_line.transactionline = fulfillment_line.id

JOIN account cost_account
  ON cost_account.id = accounting_line.account
 AND cost_account.accttype = 'COGS'

The + 2 deserves particular attention.

NetSuite Item Fulfillments can contain an operational item line plus nearby accounting-oriented transaction lines. I previously explored this behavior in my 2016 article, Mystery Solved: Multiple Lines on NetSuite Item Fulfillments and Receipts.

Thus, the query examines the nearby line structure and then uses actual TransactionAccountingLine entries, together with the COGS account type, to identify the accounting cost.

I do not regard the + 2 pattern as some universal law of NetSuite. It is an observed transaction structure that needs to be understood and tested against the client’s actual practices. That mindset is important when building sophisticated NetSuite logic: understand what the system is doing before elevating a pattern into an assumption.

To support reporting and the commission system, Hector crafted a Commission Summary and Detail structure.  Think of the Commission Summary as starting with the Invoice, and the Commission Detail as the related records that explain revenue and costs.    The Commission Detail is especially useful because it records not simply a result, but an explanation. A line can state that its Cost Source Method is Inventory and identify a specific Item Fulfillment COGS amount used in the calculation.

That makes the margin inspectable.  Click the image to see the model more clearly.

Following the Drop-Ship Procurement Chain

Drop-ship economics follow a different path.

When the originating Sales Order line indicates createdpo, dropship, or specialorder, we can move into the procurement chain, locate the created Purchase Order, and then examine the Vendor Bills that supplied the economic cost.

This line of thinking connects directly with earlier work on proper drop-ship accounting.  I discuss these models in my 2016 article, Solved: NetSuite Drop Ship Purchase Accruals and my 2018 article,  NetSuite DropShip Flows with Proper Accrual Accounting Demonstration.

The supplied Drop Ship Commission Summary makes the economic importance immediately visible.

Revenue is $250.00. Material cost is $178.50. Accessorial cost is another $83.00. Total cost therefore becomes $261.50, producing a negative margin of $11.50, or negative 4.6 percent.

A revenue-only commission model might regard this as a productive sale. An actual-margin model reaches a very different conclusion.  Click the image to see the model more clearly.

Where Transaction Proof Ends and Allocation Policy Begins

The drop-ship example (click image to see full size) also exposes an important precision issue.

Suppose the Vendor Bill contains:

Freight        $35.00
Product       $178.50
Accessorial    $48.00

The $178.50 product cost may have strong transaction lineage back to the commercial demand. But what about the additional $83.00?

If the Vendor Bill has only one relevant product line, assigning those costs to that sale may be commercially reasonable. If the bill contains many product lines, NetSuite may establish that the freight belongs to the Vendor Bill or Purchase Order without establishing precisely how much belongs to each individual sales line.

This distinction matters:

Finding a cost is not necessarily the same as proving its line-level attribution.

Where native transaction lineage ends, allocation policy may begin. Freight might be distributed by revenue, material cost, quantity, weight, or another agreed business basis.  These qualities are often discussed in Landed Cost models (discussed here)  — yet we are working with existing NetSuite configurations that do not use those transaction constructs.

Such an allocation is not inherently wrong. But it is a management policy, not a transaction-proven fact. We should know the difference and communicate it clearly.

Our earlier work on shipping economics explores why these questions matter.  See my 2019 article, Understand NetSuite Shipping Revenue, Costs and Margin Review.

A Practical Reporting Model for Existing NetSuite Accounts

This technique becomes particularly effective when operating practices are sufficiently consistent.

  1. Transactions originate predictably: Drop Ship Purchase Orders are consistently generated from Sales Order lines, and fulfillment patterns are understood.
  2. Procurement is disciplined: Vendor Bills are created through known processes, making their relationship to the purchasing chain observable.
  3. Additional costs are entered consistently: Freight and accessorial charges follow conventions the reporting logic can interpret.
  4. Exceptions remain explicit: Unusual transaction paths are identified rather than silently forced through an algorithm that produces false precision.

This reporting model is built on observable operating practices. Its precision depends upon those practices remaining known and controlled.

That characteristic makes the approach especially attractive in a mature NetSuite account. Years of transaction history may exist without the relationships we would design if we were starting fresh today. Reconstruction can therefore be an intelligent and economical optimization technique rather than a compromise.  The good news is that the operating and bookkeeping practices do not need to change.

Just as importantly, the design preserves its reasoning. A salesperson, finance manager, or analyst can ask, “Why did the system calculate this margin?” The Commission Summary can answer with the Cost Source Method, the source transaction, and the actual cost used.

That explainability is central to building trust with recipients of this information.

Building NetSuite Margin Solutions That Can Explain Themselves

The client did not need another spreadsheet and all the extra work to maintain it. They needed a disciplined way to interrogate the economic relationships already embedded in NetSuite.

By starting with the revenue line, recovering its transaction lineage, understanding the sourcing method, and following the appropriate cost path, we can reconstruct credible actual margin where operating practices are sufficiently consistent.

Hector’s work illustrates an important dimension of NetSuite craftsmanship. The task was not merely to write SQL. It required listening carefully to the business requirement, studying the transaction model, understanding accounting consequences, testing operational patterns, and then developing a fit-for-purpose method that could explain itself.

We have approached related questions in project margin, shipping economics, gross profit, commissions, landed costs, and transaction accounting for many years. For another example of the broader margin question, see my 2021 article, Learn How To Measure NetSuite Project Margin.

Yet reconstruction raises another architectural question.  Should we always need sophisticated reporting logic to discover these relationships after the fact? Could NetSuite instead be deliberately designed so operations and accounting naturally produce the relationships needed for reliable margin reporting?

That question does not invalidate the reconstruction approach. For an existing account, reconstruction may be exactly the right economic decision.  But reconstruction and deliberate architecture are not the same thing.

In  Part 2, I compared Reporting Reconstruction with Deliberate NetSuite Transaction Architecture and explored how, particularly during new implementations or substantial optimization efforts, we can move these economic relationships upstream so operations, accounting, and management reporting converge more naturally.

If you found this article relevant, feel free to sign up for notifications to new articles as I post them. If you are ready to establish trustworthy actual-margin and commission reporting in your NetSuite account, let’s have a conversation.

Marty Zigman LinkedIn

Marty Zigman

Holding three official certifications, Marty is widely recognized as a top NetSuite expert and leads a team of senior professionals at Prolecto Resources, Inc. A former Deloitte & Touche CPA and technology executive with CTO roles, he brings over 35 years of leadership in ERP, CRM, and eCommerce business systems. Contact Marty to engage directly.

Biography • YouTube • LinkedIn • X (Twitter)

2 thoughts on “Learn How to Reconstruct NetSuite Actual Margin for Sales Commissions”

  1. Marty I have built a similar thing using SuiteQL and a scheduled script to write the COGS into a custom field right on the Invoice line then the customer can run their own saved searches because the COGS number is right on the Invoice line next to the revenue. I too use SQL to fetch the COGS from the vendor bill for drop ships traversing a “U” using NTLL/PTLL as you describe (start at Invoice, PTLL back to SO, then NTLL forward to Drop Ship PO then NTLL forward to Vendor Bill).

    But to avoid this entire problem, I recommend to clients to just use special orders even for drop ships because special orders flow through Inventory and therefore COGS is sitting on the Item Fulfillment just like regular orders, plus it solves the timing problem when the vendor bill posts COGS in a different month than the Invoice revenue.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *