{
  "id": 2446830,
  "title": "Month-over-Month Growth in SQL: LAG, the Growth Formula, and the Traps",
  "url": "https://urgent.news/2026/08/21/month-over-month-growth-in-sql-lag-the-growth-formula-and-the-traps",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-08-21T22:55:57.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/michaelnocito/month-over-month-growth-in-sql-lag-the-growth-formula-and-the-traps-5bnp"
  },
  "original_language": "en",
  "account": "Month-over-month growth in SQL is a crucial concept that can be calculated using the LAG function. This guide will walk you through the process, explain how LAG works, and highlight three common traps that can lead to incorrect percentage calculations. To ensure accuracy, always verify your data first by counting distinct months and comparing it to the calendar. If any month is missing, your growth numbers may be comparing the wrong pairs of months. The key formula for month-over-month growth is: this month's revenue minus last month's revenue, divided by last month's revenue. This turns raw numbers into a share of the starting value, making the growth rate comparable across different scales. Remember, \"month over month\" always refers to comparing the current month with the immediately preceding month, not with the same month in the previous year, which would be \"year over year.\" Before performing any comparisons, ensure your data is in a single row per month, achieved through grouping by month and summing the amounts. Use LAG(revenue) OVER (ORDER BY month) to fetch the previous month's revenue onto the current month's row. This function sorts the rows by month and then provides the revenue from the row above it, enabling you to calculate the growth rate accurately.",
  "summary": "By Michael Nocito , data analyst · Published August 7, 2026 By the end of this page you can write a month-over-month growth query and trust its answer. You will know the growth formula and how to say it in a sentence, what LAG() actually does, and the three traps that produce wrong percentages without producing an error: integer division, the empty first month, and the missing month. It is about…",
  "key_points": [
    "Month-over-month growth calculated using LAG function",
    "LAG function fetches previous month's revenue for comparison",
    "Three common traps can lead to incorrect growth calculations"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}