**QuickBooks Excel Formula Guide**

**Intro**
You have full access to QuickBooks data through the CData Excel Add-in for QuickBooks, but you should only pull QuickBooks data **when the user explicitly tells you to**. The CData connector enables SQL-style queries against QuickBooks tables including invoices, bills, customers, vendors, accounts, and journal entries. You can retrieve any data point by writing CDATAQUERY formulas directly in Excel cells.

**IMPORTANT:** Before completing a task involving QuickBooks, you must verify:
1. Your CDATAQUERY formulas do not return errors.
2. All values should seem reasonable and make intuitive sense based on your general knowledge of accounting.
3. Use cell references for dynamic values when possible as opposed to hardcoded values.
4. Be aware that QuickBooks data refreshes require an active connection to the QuickBooks company file.
5. Date formats in queries should use ISO format (YYYY-MM-DD) or QuickBooks date literals.

You should essentially gut check every value that shows up. If there are any errors or the values seem wrong, you likely wrote the SQL syntax incorrectly or are referencing invalid table/field names. Please correct the formula until it outputs the proper value.

---

**CData Excel Functions Overview**

CData provides one main Excel function for QuickBooks:

| Function | Purpose | Use Case |
|----------|---------|----------|
| CDATAQUERY | Execute SQL query | Retrieve any QuickBooks data via SQL SELECT statements |

---

**1. CDATAQUERY - SQL Query Function**

Returns data from QuickBooks using SQL syntax. Results spill into adjacent cells.

**Syntax:** =CDATAQUERY("SQL Query")

**Basic Examples:**
=CDATAQUERY("SELECT * FROM Invoices LIMIT 10")
-> First 10 invoices with all fields.

=CDATAQUERY("SELECT CustomerName, Balance FROM Customers WHERE Balance > 0")
-> Customers with outstanding balances.

=CDATAQUERY("SELECT * FROM Accounts WHERE AccountType = 'Income'")
-> All income accounts from chart of accounts.

**Using Cell References:**
=CDATAQUERY("SELECT * FROM Invoices WHERE CustomerName = '" & A1 & "'")
-> Invoices for customer name in cell A1.

=CDATAQUERY("SELECT * FROM Bills WHERE TotalAmt > " & B1)
-> Bills exceeding amount in cell B1.

---

**2. Connection Setup**

Before using CDATAQUERY, the CData Excel Add-in must be configured:

1. Install CData Excel Add-in for QuickBooks (~$500-1000/year license)
2. Open Excel and go to CData ribbon tab
3. Click "Get Data" or "Connect"
4. Select QuickBooks as data source
5. Authenticate with QuickBooks Online credentials or connect to Desktop company file
6. Connection persists for session; re-authenticate if connection drops

**Connection Types:**
| Type | Description |
|------|-------------|
| QuickBooks Online | OAuth2 authentication to cloud instance |
| QuickBooks Desktop | Local connection to .QBW company file |

---

**3. QuickBooks Tables Reference**

**Core Transaction Tables:**
| Table | Description | Key Fields |
|-------|-------------|------------|
| Invoices | Customer invoices | Id, CustomerName, TxnDate, DueDate, TotalAmt, Balance |
| Bills | Vendor bills | Id, VendorName, TxnDate, DueDate, TotalAmt, Balance |
| Payments | Customer payments received | Id, CustomerName, TxnDate, TotalAmt, UnappliedAmt |
| BillPayments | Payments to vendors | Id, VendorName, TxnDate, TotalAmt |
| Credits | Credit memos | Id, CustomerName, TxnDate, TotalAmt, RemainingCredit |
| Deposits | Bank deposits | Id, TxnDate, TotalAmt, AccountName |
| Purchases | Purchase transactions | Id, VendorName, TxnDate, TotalAmt, AccountName |
| SalesReceipts | Cash sales | Id, CustomerName, TxnDate, TotalAmt |
| JournalEntries | General ledger entries | Id, TxnDate, TotalAmt, Adjustment |

**Master Data Tables:**
| Table | Description | Key Fields |
|-------|-------------|------------|
| Customers | Customer master list | Id, DisplayName, CompanyName, Balance, Email, Phone |
| Vendors | Vendor master list | Id, DisplayName, CompanyName, Balance, Email, Phone |
| Accounts | Chart of accounts | Id, Name, AccountType, AccountSubType, CurrentBalance |
| Items | Products and services | Id, Name, Type, UnitPrice, QtyOnHand, Description |
| Employees | Employee records | Id, DisplayName, Email, Phone, HiredDate |
| Classes | Class tracking | Id, Name, FullyQualifiedName |
| Departments | Department/location tracking | Id, Name, FullyQualifiedName |

**Report Tables:**
| Table | Description | Key Fields |
|-------|-------------|------------|
| ProfitAndLoss | P&L report data | Account, Amount, AccountType |
| BalanceSheet | Balance sheet data | Account, Amount, AccountType |
| BalanceSheetDetail | Detailed balance sheet | Account, Amount, Date, TransactionType |
| GeneralLedger | GL transaction detail | Account, Date, Amount, TransactionType, Name |

---

**4. Common Field Reference**

**Invoice Fields:**
| Field | Description |
|-------|-------------|
| Id | Unique invoice identifier |
| DocNumber | Invoice number |
| CustomerName | Customer display name |
| CustomerEmail | Customer email address |
| TxnDate | Transaction date |
| DueDate | Payment due date |
| TotalAmt | Invoice total |
| Balance | Remaining balance |
| ShipDate | Shipping date |
| TrackingNum | Shipping tracking number |
| PrivateNote | Internal notes |
| CustomerMemo | Customer-facing memo |

**Bill Fields:**
| Field | Description |
|-------|-------------|
| Id | Unique bill identifier |
| DocNumber | Bill/reference number |
| VendorName | Vendor display name |
| TxnDate | Bill date |
| DueDate | Payment due date |
| TotalAmt | Bill total |
| Balance | Remaining balance |
| APAccountName | AP account used |
| PrivateNote | Internal notes |

**Account Fields:**
| Field | Description |
|-------|-------------|
| Id | Unique account identifier |
| Name | Account name |
| FullyQualifiedName | Full account path (with parent) |
| AccountType | Type: Bank, Income, Expense, etc. |
| AccountSubType | Subtype classification |
| CurrentBalance | Current account balance |
| Active | Whether account is active |
| Classification | Asset, Liability, Equity, Revenue, Expense |

**Account Types:**
| AccountType | Description |
|-------------|-------------|
| Bank | Bank and cash accounts |
| Accounts Receivable | Customer receivables |
| Accounts Payable | Vendor payables |
| Income | Revenue accounts |
| Cost of Goods Sold | COGS accounts |
| Expense | Operating expense accounts |
| Fixed Asset | Property, equipment |
| Other Current Asset | Inventory, prepaid expenses |
| Other Current Liability | Accrued liabilities |
| Long Term Liability | Notes payable, mortgages |
| Equity | Owner's equity, retained earnings |

---

**5. SQL Syntax Reference**

**SELECT Statement:**
```sql
SELECT column1, column2 FROM TableName WHERE condition ORDER BY column LIMIT n
```

**Operators:**
| Operator | Description | Example |
|----------|-------------|---------|
| = | Equals | `WHERE Balance = 0` |
| <> | Not equals | `WHERE Status <> 'Paid'` |
| > | Greater than | `WHERE TotalAmt > 1000` |
| < | Less than | `WHERE Balance < 500` |
| >= | Greater or equal | `WHERE TxnDate >= '2024-01-01'` |
| <= | Less or equal | `WHERE DueDate <= '2024-12-31'` |
| LIKE | Pattern match | `WHERE CustomerName LIKE 'Acme%'` |
| IN | In list | `WHERE AccountType IN ('Income','Expense')` |
| IS NULL | Null check | `WHERE Email IS NULL` |
| AND | Logical AND | `WHERE Balance > 0 AND DueDate < '2024-01-01'` |
| OR | Logical OR | `WHERE AccountType = 'Income' OR AccountType = 'Expense'` |

**Aggregate Functions:**
| Function | Description | Example |
|----------|-------------|---------|
| SUM() | Sum values | `SELECT SUM(TotalAmt) FROM Invoices` |
| COUNT() | Count rows | `SELECT COUNT(*) FROM Customers` |
| AVG() | Average | `SELECT AVG(Balance) FROM Customers` |
| MIN() | Minimum | `SELECT MIN(TxnDate) FROM Invoices` |
| MAX() | Maximum | `SELECT MAX(TotalAmt) FROM Bills` |

**GROUP BY:**
```sql
SELECT CustomerName, SUM(TotalAmt) as Total FROM Invoices GROUP BY CustomerName
```

---

**6. Example Formulas by Use Case**

**Accounts Receivable:**
=CDATAQUERY("SELECT CustomerName, SUM(Balance) as Outstanding FROM Invoices WHERE Balance > 0 GROUP BY CustomerName ORDER BY Outstanding DESC")
-> AR aging by customer.

=CDATAQUERY("SELECT * FROM Invoices WHERE Balance > 0 AND DueDate < '2024-01-01'")
-> Overdue invoices.

**Accounts Payable:**
=CDATAQUERY("SELECT VendorName, SUM(Balance) as Outstanding FROM Bills WHERE Balance > 0 GROUP BY VendorName")
-> AP by vendor.

=CDATAQUERY("SELECT * FROM Bills WHERE DueDate BETWEEN '2024-01-01' AND '2024-01-31' AND Balance > 0")
-> Bills due in January.

**Cash Flow:**
=CDATAQUERY("SELECT TxnDate, TotalAmt, CustomerName FROM Payments WHERE TxnDate >= '2024-01-01' ORDER BY TxnDate")
-> Customer payments received YTD.

=CDATAQUERY("SELECT TxnDate, TotalAmt, VendorName FROM BillPayments WHERE TxnDate >= '2024-01-01' ORDER BY TxnDate")
-> Vendor payments made YTD.

**Chart of Accounts:**
=CDATAQUERY("SELECT Name, CurrentBalance FROM Accounts WHERE AccountType = 'Bank'")
-> Bank account balances.

=CDATAQUERY("SELECT Name, AccountType, CurrentBalance FROM Accounts WHERE Active = true ORDER BY AccountType, Name")
-> Active accounts by type.

**Revenue Analysis:**
=CDATAQUERY("SELECT CustomerName, COUNT(*) as InvoiceCount, SUM(TotalAmt) as TotalRevenue FROM Invoices WHERE TxnDate >= '2024-01-01' GROUP BY CustomerName ORDER BY TotalRevenue DESC LIMIT 10")
-> Top 10 customers by revenue.

**Expense Analysis:**
=CDATAQUERY("SELECT VendorName, COUNT(*) as BillCount, SUM(TotalAmt) as TotalSpend FROM Bills WHERE TxnDate >= '2024-01-01' GROUP BY VendorName ORDER BY TotalSpend DESC LIMIT 10")
-> Top 10 vendors by spend.

**Customer/Vendor Lookup:**
=CDATAQUERY("SELECT DisplayName, Email, Phone, Balance FROM Customers WHERE DisplayName LIKE '%" & A1 & "%'")
-> Search customers by name fragment.

**General Ledger:**
=CDATAQUERY("SELECT * FROM JournalEntries WHERE TxnDate BETWEEN '2024-01-01' AND '2024-12-31' ORDER BY TxnDate")
-> Journal entries for fiscal year.

---

**7. Error Handling**

**Common Errors:**
| Error | Cause | Solution |
|-------|-------|----------|
| Connection failed | QuickBooks not connected | Re-authenticate in CData ribbon |
| Invalid table name | Typo in table name | Check table names in section 3 |
| Invalid column | Field doesn't exist | Verify field names for that table |
| Syntax error | SQL syntax issue | Check quotes, operators, parentheses |
| No data returned | Query too restrictive | Broaden WHERE conditions |
| Timeout | Query too large | Add LIMIT clause, narrow date range |

**Debugging Tips:**
1. Start with simple query: `SELECT * FROM TableName LIMIT 5`
2. Add WHERE clauses incrementally
3. Verify date format: use 'YYYY-MM-DD' or 'MM/DD/YYYY'
4. String values need single quotes: `WHERE CustomerName = 'Acme Corp'`
5. Check CData connection status in ribbon

---

**Final Checklist:**
- What QuickBooks data is needed? (Invoices? Bills? Accounts? Customers?)
- What time frame is required? (Use TxnDate or DueDate filters)
- What aggregation is needed? (Raw data vs. SUM/COUNT/GROUP BY)
- Are the table and field names spelled correctly?
- Are string values in single quotes?
- Are dates in proper format?
- Is LIMIT clause needed to prevent large result sets?
- Is the CData connection active?

---

**Additional Resources:**
- CData QuickBooks Driver Documentation: https://www.cdata.com/drivers/quickbooks/
- CData Excel Add-in Help: https://cdn.cdata.com/help/DQE/excel/
- QuickBooks API Field Reference: https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities
