---
id: casos/dre-automatizada
area: Finance
usage: widely used
effort: medium
grain: Entry x allocation (category and cost center) x accrual month
---

# Automated P&L (DRE)

The month's management P&L built from ERP entries, using finance's chart of accounts, matching the official close and without closing the month by hand.

## Executive summary

**For:** Finance, controllership and leadership at companies that close the month's results in a spreadsheet built from the ERP.

**What it solves**

- The month's P&L builds itself and matches the number finance presents.
- Every real booked in the ERP lands on a management line, and anything unclassified shows up instead of disappearing.
- Accrual and cash stop being mixed in the same report.

**Why it matters:** The ERP stores entries, not results: each category has to be taken to the right line, with sign, allocation and status handled. Done by hand, the close takes days and each person arrives at a different margin. With an automated P&L, budget vs actual, the cash flow and the questions to the AI agent all start from the same number.

**Business questions it answers**

- What were net revenue, gross margin and EBITDA in the last closed month?
- Why did the margin drop compared with the previous month?
- How much did we spend on people, technology and marketing per month this year?
- Which entries still have no management classification?
- How does the quarter's actual compare with the budget?

**What you need**

- Finance ERP connected to Nekt (entries, categories and cost centers)
- Finance's management chart of accounts and the mapping from each ERP category to a P&L line
- One closed reference month to validate the number

**What you get**

- A table per entry and allocation, already classified on its management line
- The monthly P&L with margins, EBITDA and comparison with the previous month and the budget
- A to-do list of whatever still has no mapping
- An AI agent that answers about results using finance's rules

## Detailed

### The problem

The ERP has entries with category, nature and status, but not the P&L leadership uses. Whoever sums by ERP category mixes accrual with cash, counts cancelled and replaced bills as expenses, multiplies values when opening allocations and treats transfers between accounts as results. The month closes with a margin different from the one finance presents, and nobody knows which is right.

### Business rules

1. **The P&L is on accrual, cash is on payment.** The P&L uses the entry's accrual date (or the bill's issue date). The cash flow uses the date of the actual settlement. They are two tables and two different questions, never added together. If the ERP has no reliable accrual date, choose which date replaces it (issue or due date), write the choice in the context document and keep the criterion every month. (Avoid: Adding the accrual view and the cash view in the same report.)
2. **The management chart comes from the mapping, not the ERP structure.** Each ERP category points to a management line (gross revenue, deductions, costs, variable expenses, operating expenses, financial result) in a mapping table kept by finance, usually a connected spreadsheet. The P&L structure configured inside the ERP is often outdated or was never used. When there is an official P&L made by controllership or an outside consultancy, the automation reproduces that number and does not invent new criteria. (Avoid: Using the P&L configured in the ERP or grouping by parent category without validating.)
3. **Anything without a mapping shows up, never disappears.** A new or unmapped category lands on an Unclassified line, visible in the P&L, and goes to a to-do list with amount and description. The transformation does not fail and does not drop the entry. The goal is a zero line at close. (Avoid: Filtering out unmapped entries or letting the join drop the row.)
4. **Sign applied once.** Revenue positive, cost and expense negative, applied from the entry's nature (in Omie, R adds and P subtracts). If the column already comes signed, do not flip it again. The month's result is the sum of all lines for that accrual month. (Avoid: Flipping the sign in the transformation and again in the dashboard.)
5. **Allocate by percentage, one line per allocation.** An entry can be split across several categories and cost centers. Create one line per allocation with amount = entry amount x percentage / 100; a null percentage counts as 100%. The allocation lines must add back to the entry amount. Opening the category list without the percentage repeats the full amount on every line. (Avoid: Exploding the category list and summing the full amount on each one.)
6. **Status and operation type decide what counts.** Cancelled is out. A renegotiated bill that the ERP zeroes and replaces with new installments is out, and the new installments are in. For expenses, actual is the paid amount, not the bill's total. Bill movements such as replacement, cancellation and rescheduling are not costs: only payment and advance count. Summing every operation type inflated paid expenses by 30% to 50% in real cases. (Avoid: Summing every bill and every settlement in the period.)
7. **Moving money is not a result.** Transfers between own accounts, investments and redemptions, shareholder contributions, loans taken or repaid, advances and the corporate card bill payment change cash, but are not revenue or expense. They stay out of the P&L and appear only in the cash flow. Movements between bank and investment accounts must be computed per entry so both sides cancel out. (Avoid: Classifying transfers, contributions and loans as revenue or expense.)
8. **One source per revenue.** Define which system is the revenue source: the ERP, the billing system or the invoice. Payment gateways and platforms are collection channels and only serve as a check. Adding ERP revenue to gateway payments counts the same sale twice. (Avoid: Adding ERP revenue to gateway revenue.)
9. **Cost of goods enters in the month of sale.** In retail and manufacturing, COGS is the cost of the items sold in the month (quantity sold x item cost), not the month's purchases, which go to inventory. In services, the cost of services follows the service's accrual month. Payment fees, commissions and freight are variable expenses and sit between gross margin and contribution margin. (Avoid: Booking the month's merchandise purchases as cost.)
10. **A closed month is flagged and does not change.** Each month has a closed flag, set when finance finishes the close. Actuals, comparisons and board reports use closed months only; the open month is partial and labeled provisional. Once closed, the month is stored in a version that is not recalculated, and adjustments found later go into the month in which they were found. (Avoid: Comparing the partial current month with closed months or recalculating the past on every run.)

### The management P&L structure

Each ERP category points to one of these lines through finance's mapping.

- **Sales, services and recurring revenue, on accrual** → Gross revenue
- **Sales taxes, returns and cancellations** → Deductions (`net revenue = gross - deductions`)
- **Cost of items sold or services rendered** → COGS or cost of services (`gross margin = net - COGS`)
- **Commissions, freight, payment fees, media** → Variable expenses (`contribution margin`)
- **People, admin, technology, fixed marketing** → Operating expenses (`EBITDA`)
- **Interest, investment income, bank fees** → Financial result (`profit before taxes`)
- **Category without a mapping** → Unclassified (`goal: zero at close`)
- **Transfers, investments, contributions, loans** → Outside the P&L, cash only

### Definitions

| Metric | Definition |
|---|---|
| Gross revenue | sum of operating revenue entries mapped to gross revenue, by accrual month, excluding cancelled |
| Net revenue | gross revenue minus deductions (sales taxes, returns and cancellations) in the same accrual month |
| COGS or cost of services | cost of the items sold in the month (quantity x item cost at sale) or cost of services rendered with accrual in the month |
| Gross margin | net revenue minus COGS or cost of services; as a percentage, divide by net revenue after summing the period |
| Contribution margin | gross margin minus variable expenses (commissions, freight, payment fees, media), per month |
| EBITDA | contribution margin minus operating expenses, before depreciation, interest and income taxes, by accrual month |
| Profit before taxes | EBITDA plus financial income minus financial expenses; if income taxes (IRPJ and CSLL) are not computed, the figure is always labeled as before taxes |
| Unclassified | sum of the month's entries with no mapping to a management line; goal is zero at close |

### Pitfalls

- **The ERP's P&L was never used.** The P&L structure configured in the ERP had the average cost line set to hidden and purchases tied to the cost line. Showing both would count cost twice. How to avoid: Reproduce finance's official P&L and treat the ERP's only as a reference.
- **Opened categories multiplied expenses.** Entries with three or four categories were opened without the allocation percentage, and each category got the entry's full amount. How to avoid: Use the allocation percentage and test that the lines add back to the entry amount.
- **Replacements counted as cost.** Bill replacement and cancellation settlements were summed as payments, and paid cost per cost center came out 30% to 50% above the ERP report. How to avoid: Count only payment and advance as paid expense.
- **Revenue counted twice.** Revenue came from one system and gateway payments were added to it, as if they were more revenue. How to avoid: Declare the official revenue source and use the gateway only as a check.
- **Current month with a high margin.** The cost of services is booked after the month in which the service happened, and for about 30 days the current month's P&L showed low cost and a high margin. How to avoid: Flag the month as provisional until close and compare closed months only.
- **Invoice tax duplicated across items.** Tax totals come at invoice level. Working at item grain, the invoice total repeated on every item and inflated deductions. How to avoid: Sum invoice-level values at invoice grain, and only then join with items.

### Acceptance test

- [ ] For a closed month, net revenue, gross margin and EBITDA match finance's official P&L (difference below 0.5%).
- [ ] The allocation lines of each entry add up to the entry amount.
- [ ] The Unclassified line is zero, or every entry on it appears on the to-do list.
- [ ] No transfer between accounts, investment, contribution or loan appears on a result line.
- [ ] Rerunning the pipeline does not change any value in a month flagged as closed.

### Context document

```text
Management P&L (DRE)
- The P&L is on accrual (accrual date or, if missing, <declared date>). Cash flow is by payment date and lives in another table. Never add the two views.
- Structure: gross revenue, deductions, net revenue, COGS or cost of services, gross margin, variable expenses, contribution margin, operating expenses, EBITDA, financial result, profit before taxes.
- Each ERP category goes to a line through finance's mapping. Unmapped categories go to Unclassified; mention that line whenever it is not zero.
- Sign: revenue positive, cost and expense negative, applied once.
- Allocation: amount x percentage / 100 per category and cost center; a null percentage counts as 100%.
- Excluded from sums: cancelled, renegotiated bills that were replaced, replacement and cancellation settlements.
- Transfers between accounts, investments, contributions and loans are not results.
- Official revenue comes from <source>. The payment gateway only checks.
- Use only months flagged as closed for actuals and comparisons. The open month is provisional and must be called that.
- Margins and percentages: sum the period and divide once; never average monthly percentages.
- If income taxes are not computed, say profit before taxes.
Client exceptions:
- <client>: the official P&L is the one from consultancy <name>; reproduce its number.
- <client>: category <category> is allocated across business units by <driver>.
```

### Variations

- **Several companies:** One ERP connection per CNPJ (company tax ID), joined with a company column and with transfers between group companies eliminated.
- **Budget vs actual:** The budget comes in as a table by month and management line, with the budget version frozen and its source declared.
- **Finance outsourcing:** The same model replicated per client, with each client's connection declared in the context document.
