Track accounts payable by due date

SQL query for Xero

Get accounts payable by due date.

SELECT a.AccountNumber, SUM(i.Amount – COALESCE(cn.Amount, 0) – COALESCE(p.Amount, 0)) AS AccountsPayable FROM Accounts a JOIN Invoices i ON a.AccountID = i.AccountID LEFT JOIN CreditNotes cn ON i.InvoiceID = cn.InvoiceID LEFT JOIN Payments p ON i.InvoiceID = p.InvoiceID WHERE i.DueDate < CURDATE() GROUP BY a.AccountNumber

Xero data model

Table Accounts

Table Invoices

Table Credit Notes

Table Payments

Table Manual Journals

Use SQL on all your SaaS data

Magical SQL for Xero with Peliqan.io

Explore data in a rich spreadsheet UI. Use Magical SQL to combine and transform data. SQL queries become new tables that can be shared with business users and used in any BI tool such as Microsoft Power BI, Tableau or Metabase.

Let AI do the work for you

Peliqan’s AI assistant helps you to write SQL queries to get to insights fast. Ask your question in plain English and immediately see the result in Peliqan’s rich spreadsheet viewer.

Peliqan Ask AI willl write your SQL queries from plain English