How to calculate EBITDA in SQL
Contents:
Why EBITDA matters
It is Sunday night and the head of FP&A at a Stripe-sized fintech messages the on-call analyst: "Board deck goes out Tuesday, I need quarterly EBITDA and EBITDA margin for the last six quarters by segment, and the bridge from net income line by line." That is an EBITDA question, and it shows up in finance analyst loops at Stripe, Snowflake, Databricks, DoorDash, Airbnb, and Tesla — anywhere an investor narrative is built on operating cash generation rather than reported earnings.
EBITDA — Earnings Before Interest, Taxes, Depreciation, and Amortization — is the closest single number to "what does the operating engine throw off before financing decisions and accounting choices." It strips out interest because capital structure is a choice, taxes because jurisdiction is a choice, and D&A because they are non-cash allocations of past spend. It anchors the EV/EBITDA multiple in most M&A and growth-equity valuations, and it is the metric most often abused by management teams who want a flattering chart. This post walks from a runnable quarterly query through margin and adjusted variants to EV/EBITDA, and stops at the pitfalls that catch first-time authors.
The SQL formula
EBITDA has two equivalent forms. The first builds up from the bottom of the income statement and adds back the four items the acronym names. The second starts from operating income — which already excludes interest and taxes — and adds back D&A. Both produce the same number if the source data is consistent; teams pick the form that matches how their P&L is structured in the warehouse.
EBITDA = Net Income + Interest + Taxes + Depreciation + Amortization
EBITDA = Operating Income (EBIT) + Depreciation + Amortization
EBITDA Margin = EBITDA / RevenueThe trap most analysts hit is conflating EBITDA with cash flow. EBITDA ignores changes in working capital, ignores capex, and ignores stock-based compensation in the "adjusted" variant most tech companies publish. A capital-intensive business with healthy EBITDA can burn cash every quarter; a SaaS business with negative EBITDA can be cash-positive once deferred revenue is netted. Treat EBITDA as a profitability proxy, not a cash proxy.
Quarterly EBITDA query
Assume one fact table, quarterly_financials(date, segment, revenue, net_income, interest_expense, tax_expense, depreciation, amortization). Each row is one segment for one period at the natural grain of the source system. The query rolls the grain up to quarter, applies the add-back, and computes both the absolute EBITDA and the margin.
WITH pnl AS (
SELECT
DATE_TRUNC('quarter', DATE) AS quarter,
SUM(net_income) AS net_income,
SUM(interest_expense) AS interest,
SUM(tax_expense) AS taxes,
SUM(depreciation) AS depreciation,
SUM(amortization) AS amortization,
SUM(revenue) AS revenue
FROM quarterly_financials
WHERE DATE >= CURRENT_DATE - INTERVAL '24 months'
GROUP BY 1
)
SELECT
quarter,
revenue,
net_income + interest + taxes + depreciation + amortization AS ebitda,
ROUND(
(net_income + interest + taxes + depreciation + amortization)::NUMERIC * 100
/ NULLIF(revenue, 0),
2
) AS ebitda_margin_pct
FROM pnl
ORDER BY quarter;Two design choices matter. The NULLIF(revenue, 0) guard prevents a divide-by-zero in a quarter where a segment had no revenue — a real case for newly launched product lines. The cast to NUMERIC before multiplying by one hundred keeps the margin in basis-point precision; otherwise integer division floors the result to zero on warehouses that infer integer types from integer inputs.
A bridge version — what the FP&A lead actually wants for the board deck — splits the add-back into separate columns so a reader sees how net income became EBITDA. This is also the format an auditor will ask for.
SELECT
DATE_TRUNC('quarter', DATE) AS quarter,
SUM(net_income) AS net_income,
SUM(interest_expense) AS plus_interest,
SUM(tax_expense) AS plus_taxes,
SUM(depreciation) AS plus_depreciation,
SUM(amortization) AS plus_amortization,
SUM(net_income + interest_expense + tax_expense + depreciation + amortization) AS ebitda
FROM quarterly_financials
WHERE DATE >= CURRENT_DATE - INTERVAL '24 months'
GROUP BY 1
ORDER BY quarter;EBITDA Margin
EBITDA Margin is EBITDA divided by revenue. It is the most-cited efficiency metric in growth-equity decks because it normalizes EBITDA across companies of different sizes — a SaaS business at one hundred million revenue with twenty-five percent margin is roughly comparable to one at one billion with the same margin.
SELECT
SUM(revenue) AS revenue,
SUM(ebit + depreciation + amortization) AS ebitda,
ROUND(
SUM(ebit + depreciation + amortization)::NUMERIC * 100
/ NULLIF(SUM(revenue), 0),
2
) AS ebitda_margin_pct
FROM financials
WHERE DATE >= '2026-01-01'
AND DATE < '2026-04-01';Sector benchmarks — public SaaS at scale lands at twenty to thirty percent, mature hardware ten to fifteen, marketplaces fifteen to twenty-five, ad networks thirty to forty. Banks do not use EBITDA at all because net interest income is the business. If a candidate quotes forty percent for a hardware company, the interviewer will dig into cost classification.
EBITDA vs Operating Income vs Net Income
Three lines on the income statement, three different stories. Operating Income — EBIT — is revenue minus COGS minus operating expenses. It excludes interest and taxes but still includes D&A. EBITDA adds those two non-cash charges back. Net Income is the bottom line after interest, taxes, and below-the-line items like impairments or one-time gains.
Revenue
- COGS
- Operating Expenses
= Operating Income (EBIT)
+ Depreciation
+ Amortization
= EBITDA
EBIT - Interest - Taxes = Net Income (simplified)Walking up from net income to EBITDA is the standard interview exercise. The reverse — walking down from EBITDA to net income — is what CFOs ask in roundtables because it forces a candidate to articulate which charges are real, which are accounting, and which are financing. A clean answer covers depreciation as past capex allocation, amortization as the same for intangibles, interest as cost of capital structure, and taxes as a function of jurisdiction.
Adjusted EBITDA
Companies publish an "Adjusted EBITDA" line that strips out items management deems non-recurring — restructuring charges, M&A integration costs, litigation settlements, and, controversially, stock-based compensation. The accounting board does not define Adjusted EBITDA, which is why two companies in the same sector can publish very different numbers with similar underlying economics.
SELECT
quarter,
revenue,
ebitda,
ebitda + restructuring + ma_integration + litigation + stock_based_comp AS adjusted_ebitda,
ROUND(
(ebitda + restructuring + ma_integration + litigation + stock_based_comp)::NUMERIC * 100
/ NULLIF(revenue, 0),
2
) AS adjusted_ebitda_margin_pct
FROM financials_quarterly
WHERE quarter >= DATE_TRUNC('quarter', CURRENT_DATE - INTERVAL '24 months')
ORDER BY quarter;Stock-based compensation is the most-debated add-back. Companies argue SBC is non-cash and should be excluded; growth-fund analysts argue SBC is a real cost — dilution is paid by existing shareholders even if cash never moves. The interview answer is to acknowledge both views and default to including SBC unless the asker is modeling cash compensation specifically.
EV/EBITDA multiple
EV/EBITDA is the workhorse valuation multiple for mature businesses. Enterprise Value is market cap plus debt minus cash; dividing by trailing or forward EBITDA produces a multiple comparable across capital structures because EBITDA itself is pre-interest. Public SaaS at scale trades in the ten to twenty range on forward EBITDA, mature industrials at six to ten, and high-growth software above twenty when forward EBITDA is small relative to growth.
EV = Market Cap + Debt - Cash
EV / EBITDA = valuation multipleA candidate who only knows revenue multiples will struggle when an interviewer pivots from a pre-IPO growth company — where EV/Revenue dominates — to a profitable mid-cap where EV/EBITDA is the only number that matters.
Common pitfalls
When teams calculate EBITDA for the first time, the most common mistake is treating it as a synonym for operating cash flow. EBITDA ignores changes in working capital and ignores capital expenditure entirely. A capital-intensive business such as a logistics network or a chip foundry can report twenty percent EBITDA margin and still burn cash every quarter once capex is netted in. The fix is to compute Free Cash Flow alongside EBITDA and present both on the same slide so the reader cannot anchor on the rosier figure.
A second trap is uncritical use of Adjusted EBITDA. Management teams have a permanent incentive to widen the add-back list because every dollar excluded lifts the headline number and the implied multiple. The interview answer is to read every add-back, reject restructuring charges that recur quarter after quarter — by definition not non-recurring — and apply skepticism whenever SBC is excluded. The SQL fix is the bridge query that shows every add-back as its own column.
A third pitfall is double-counting depreciation. If the source P&L embeds depreciation inside COGS rather than breaking it out as a separate line, summing net_income + interest + taxes + depreciation + amortization will pull depreciation in twice. The fix is to confirm with accounting where D&A lives in the chart of accounts, and to add a sanity check that EBITDA built from the bottom matches EBITDA built from the top within tolerance.
A fourth pitfall is comparing EBITDA across sectors as if it were universal. Margins are sector-dependent — twenty-five percent is great in marketplaces and weak in mature software — and multiples shift with growth and capital intensity. The right framing is sector-specific benchmarks with growth-rate context.
A fifth pitfall is reporting negative EBITDA without context for an early-stage company. Most venture-backed companies are EBITDA-negative for years by design — they spend operating expense to capture share. Applying mature-company logic to a Series B company misses the point. The fix is to pair EBITDA with growth rate and the Rule of 40 — growth percentage plus margin percentage at or above forty.
Optimization tips
For warehouses that materialize daily P&L data — Snowflake, Databricks, BigQuery — pre-aggregate to a quarterly fact table refreshed once per close. A nightly job that writes one row per segment per quarter to financials_quarterly runs EBITDA queries in milliseconds at any board-deck horizon. Partition the daily table on date and cluster on segment for ad-hoc day-grain analysis.
Pre-classify cost lines into "above the line" (operating expense), "below the line" (interest, tax, one-time), and "non-cash" (D&A, SBC) at the data-model layer rather than in every query. A canonical income-statement view with a category column saves you from re-deriving the mapping in every dashboard. For EV/EBITDA, pull market cap and net debt into a small dimension refreshed daily; the multiple is then a one-line join on the latest EBITDA row.
Related reading
- How to calculate Contribution Margin in SQL
- How to calculate COGS in SQL
- How to calculate Burn Rate in SQL
- How to calculate Burn Multiple in SQL
- How to calculate Cash Conversion Cycle in SQL
- How to calculate Deferred Revenue in SQL
If you want to drill finance-analyst SQL like this every day, NAILDD is launching with five hundred plus problems across this pattern.
FAQ
What is the difference between EBITDA and Net Income?
Net Income is the bottom line — revenue minus every expense including COGS, operating expense, D&A, interest, and tax. EBITDA backs out the last four, so it is by construction always greater than or equal to net income for a company with positive interest, tax, and D&A. The two answer different questions — net income tells you what shareholders earned, EBITDA tells you what the operating engine generated before financing and accounting choices.
Why is EBITDA controversial?
Warren Buffett called it a "stupid" metric and Charlie Munger said it should be replaced with "bullshit earnings" whenever it appears in a deck. Their argument is that depreciation is a real cost — assets wear out and need replacing — and excluding it lets capital-intensive businesses look more profitable than they are. The counter is that for many software businesses depreciation reflects past spend that does not recur one-for-one. Most practitioners read both together.
When should I use Adjusted EBITDA versus reported EBITDA?
Adjusted EBITDA helps when comparing companies with very different one-time items — one restructured, another did a major acquisition, a third settled a lawsuit. The discipline is to read every add-back, reject anything that recurs, and default to including SBC. If the adjusted figure looks dramatically better than reported EBITDA, that is usually a flag that management is being optimistic with the definition.
What is a typical EV/EBITDA range?
Public SaaS at scale trades at ten to twenty on forward EBITDA, with the multiple compressing as growth slows. Mature industrials sit at six to ten. High-growth software with small absolute EBITDA can trade above twenty or thirty when the market is pricing forward growth. Distressed businesses can trade below five — value plays or value traps depending on whether the depression is cyclical or structural.
How does EBITDA relate to Free Cash Flow?
Free Cash Flow starts from EBITDA, subtracts capex, subtracts the increase in working capital, and subtracts cash taxes. For an asset-light SaaS business with little capex and modest working-capital swings, EBITDA and FCF are close. For a logistics business with heavy fleet capex or a hardware business with inventory, FCF can be a fraction of EBITDA. Always pair the two in any analysis where the reader might mistake one for the other.
Can EBITDA be negative and is that always bad?
Negative EBITDA means the operating engine is losing money before non-cash and below-the-line items. For a mature business this is a serious problem. For an early-stage business funded to capture share, it is the expected profile for years; the question is trajectory and Rule of 40. Context matters more than the sign.