# Source: https://getlago.com/docs/guide/analytics/invoice-overdue.md

> ## Documentation Index
> Fetch the complete documentation index at: https://getlago.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Overdue invoices

The Overdue Invoices dashboard displays the total amount from your finalized invoices that are either pending or failed and have passed their due date. It does not include voided or disputed invoices. At a glance, you can see what your customers owe you, providing quick insight into the state of your revenue collection.

<Tabs>
  <Tab title="Dashboard">
    To access the Overdue invoices dashboard:

    1. Navigate to the "Analytics" section; and
    2. Access the "Overdue invoices" Dashboard.

    Our overdue balance calculation considers the following factors:

    * Finalized invoices;
    * With pending or failed as a payment status; and
    * A due date that is past;

    It is not taking into account invoices that are disputed or voided.

    <Frame caption="Overdue invoices dashboard">
      <img src="https://mintcdn.com/lago-docs/L57i4PY_iDpAEuWL/guide/analytics/images/overdue-invoices.png?fit=max&auto=format&n=L57i4PY_iDpAEuWL&q=85&s=ebe3e51befaca14ea5058ac07b09f17a" data-og-width="893" width="893" data-og-height="79" height="79" data-path="guide/analytics/images/overdue-invoices.png" data-optimize="true" data-opv="3" srcset="https://mintcdn.com/lago-docs/L57i4PY_iDpAEuWL/guide/analytics/images/overdue-invoices.png?w=280&fit=max&auto=format&n=L57i4PY_iDpAEuWL&q=85&s=2e3a64760af2512937169e501c68d813 280w, https://mintcdn.com/lago-docs/L57i4PY_iDpAEuWL/guide/analytics/images/overdue-invoices.png?w=560&fit=max&auto=format&n=L57i4PY_iDpAEuWL&q=85&s=7dc8f755ac545941790706f438b2d33f 560w, https://mintcdn.com/lago-docs/L57i4PY_iDpAEuWL/guide/analytics/images/overdue-invoices.png?w=840&fit=max&auto=format&n=L57i4PY_iDpAEuWL&q=85&s=d49470bb22225652e0f771b1f15760bb 840w, https://mintcdn.com/lago-docs/L57i4PY_iDpAEuWL/guide/analytics/images/overdue-invoices.png?w=1100&fit=max&auto=format&n=L57i4PY_iDpAEuWL&q=85&s=280e1c172c13c83296512c9203bb9c03 1100w, https://mintcdn.com/lago-docs/L57i4PY_iDpAEuWL/guide/analytics/images/overdue-invoices.png?w=1650&fit=max&auto=format&n=L57i4PY_iDpAEuWL&q=85&s=290d1f1e18da462bb9cc9f7011a7aa9f 1650w, https://mintcdn.com/lago-docs/L57i4PY_iDpAEuWL/guide/analytics/images/overdue-invoices.png?w=2500&fit=max&auto=format&n=L57i4PY_iDpAEuWL&q=85&s=69560f48a4c5b98f3027b606d502ff40 2500w" />
    </Frame>
  </Tab>

  <Tab title="API">
    <CodeGroup>
      ```bash Get Overdue balance theme={"dark"}
      LAGO_URL="https://api.getlago.com"
      API_KEY="__YOUR_API_KEY__"

      curl --location --request GET "$LAGO_URL/api/v1/analytics/overdue_balance?currency=USD" \
      --header "Authorization: Bearer $API_KEY" \
      --header 'Content-Type: application/json' \
      ```
    </CodeGroup>
  </Tab>

  <Tab title="SQL Query">
    <Info>
      The generated amounts are in cents, making it compatible with different currencies.
    </Info>

    <CodeGroup>
      ```sql SQL Query used by Lago theme={"dark"}
      --- Start date of the query is the organization creation date
      WITH organization_creation_date AS (
      SELECT
          DATE_TRUNC('month', o.created_at) AS start_month
      FROM organizations o
      WHERE o.id = '__YOUR_ORGANIZATION_ID__'
      ),

      --- Generate a number of date series in the future
      all_months AS (
      SELECT
          generate_series(
              (SELECT start_month FROM organization_creation_date),
              DATE_TRUNC('month', CURRENT_DATE + INTERVAL '10 years'), 
              interval '1 month'
          ) AS month
      ),

      --- Get total of overdue invoices
      payment_overdue_invoices AS (
      SELECT
        DATE_TRUNC('month', payment_due_date) AS month,
        i.currency,
        COALESCE(SUM(total_amount_cents), 0) AS total_amount_cents,
        array_agg(DISTINCT i.id) AS ids
      FROM invoices i
      LEFT JOIN customers c ON i.customer_id = c.id
      WHERE i.organization_id = :organization_id
      AND i.payment_overdue IS TRUE
      ---AND c.external_id = 'hooli_1234' --- FILTER BY CUSTOMER
      GROUP BY month, i.currency, total_amount_cents
      ORDER BY month ASC
      )

      --- Get overdue balances month over month
      SELECT
      am.month,
      #{select_currency_sql},
      SUM(invs.total_amount_cents) AS amount_cents,
      jsonb_agg(DISTINCT invs.ids) AS lago_invoice_ids
      FROM all_months am
      LEFT JOIN payment_overdue_invoices invs ON am.month = invs.month
      WHERE am.month <= DATE_TRUNC('month', CURRENT_DATE)
      ---AND am.month >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '11 months') --- LAST 12 MONTHS
      --- AND cd.currency = 'EUR'
      AND invs.total_amount_cents IS NOT NULL
      GROUP BY am.month, invs.currency
      ORDER BY am.month;
      ```
    </CodeGroup>
  </Tab>
</Tabs>