QuickBooks Desktop to Excel, with a refresh button

QuickBooks Desktop's Excel button makes a copy that is out of date the next day. Desktop Books gives each company file a Power Query, so the same workbook refreshes from the file whenever you open it.

Three ways to get QuickBooks Desktop into Excel

WayWhat you getRefresh
Export to Excel from a QuickBooks reportA copy of one report as it was when you clickedExport again by hand
An ODBC driver on the QuickBooks PCTables you can query from Excel on that PC or networkWhen you refresh, on that PC or network
Desktop Books and Power Query18 kinds of records and 5 reports, in any workbook, anywhereWhen you refresh, or on a schedule in Power BI

Set it up

  1. In Desktop Books, open the company file and click New API key. Copy it.
  2. On the same page, pick what to read (open invoices, customers, A/R aging) and copy the Power Query it shows.
  3. In Excel: Data > Get Data > From Other Sources > Blank Query, then Advanced Editor, paste and click Done.
  4. When Excel asks how to connect, choose Basic, paste the key as the user name and leave the password empty.
  5. Click Close & Load. Next time, Data > Refresh All.

The query for open invoices looks like this:

// Desktop Books: Invoices from "Acme Construction"
// In Excel: Data > Get Data > From Other Sources > Blank Query, then Advanced Editor. Paste this and click Done.
// The first refresh asks how to connect: choose Basic, paste your API key as the User name, leave Password empty.
let
    Path = "v1/files/file_8f2c41/invoices",
    Options = [flat = "1", limit = "500", status = "open"],
    GetPage = (cursor as nullable text) as record =>
        let
            Query = if cursor = null then Options else Options & [cursor = cursor],
            Body = Json.Document(Web.Contents("https://desktop-app.greatwork.company", [RelativePath = Path, Query = Query, ManualStatusHandling = {400, 404, 409, 429, 500, 503}])),
            Checked = if Record.FieldOrDefault(Body, "error", null) <> null then error Error.Record("Desktop Books", Record.FieldOrDefault(Record.Field(Body, "error"), "message", "The request didn't work."), Record.FieldOrDefault(Record.Field(Body, "error"), "hint", "")) else if Record.FieldOrDefault(Body, "status", "") = "queued" then error Error.Record("Desktop Books", Record.FieldOrDefault(Body, "message", "This company file answers at the next Web Connector check-in. Refresh again after that.")) else Body
        in
            Checked,
    Pages = List.Generate(() => GetPage(null), each _ <> null, each if _[next_cursor] = null then null else GetPage(_[next_cursor]), each _[data]),
    Rows = List.Combine(Pages),
    Columns = {"id", "edit_sequence", "created_at", "modified_at", "number", "date", "memo", "currency", "exchange_rate", "customer_id", "customer_name", "due_date", "subtotal", "tax", "total", "applied", "balance", "is_paid", "terms_id", "terms_name", "class_id", "class_name", "status", "days_overdue", "line_count"},
    Table = if List.IsEmpty(Rows) then #table(Columns, {}) else Table.FromRecords(Rows, Columns, MissingField.UseNull),
    Typed = Table.TransformColumnTypes(Table, {{"id", type text}, {"edit_sequence", type text}, {"created_at", type datetimezone}, {"modified_at", type datetimezone}, {"number", type text}, {"date", type date}, {"memo", type text}, {"currency", type text}, {"exchange_rate", type number}, {"customer_id", type text}, {"customer_name", type text}, {"due_date", type date}, {"subtotal", type number}, {"tax", type number}, {"total", type number}, {"applied", type number}, {"balance", type number}, {"is_paid", type logical}, {"terms_id", type text}, {"terms_name", type text}, {"class_id", type text}, {"class_name", type text}, {"status", type text}, {"days_overdue", Int64.Type}, {"line_count", Int64.Type}}, "en-US")
in
    Typed

It reads every page of results and keeps the key out of the workbook, so you can send the file to a client. Why it is written this way.

Reports that stay current

More about Excel

QuickBooks Desktop for Windows has good Excel tools of its own, and for some people they're all that's needed. Here's where they stop.

What QuickBooks Desktop does on its own

Intuit's help article "Export reports as Excel workbooks in QuickBooks Desktop" covers three things:

That works well when the person building the workbook sits at the QuickBooks PC with the company file open. It doesn't help when:

That's the gap a Power Query fills: the workbook asks us, and we answer from the last Web Connector check-in.

Building a client workbook

A pattern that works for month-end packages:

  1. One query per client file for open invoices and one for open bills, each loaded to its own sheet.
  2. One query per client for the profit and loss for the month just closed. A report for dates you choose runs at the file's next check-in, so the first refresh after you change the month stops with a note to refresh again after that check-in; after that it answers at once. Set the new month the day before the meeting.
  3. A summary sheet of your own, with formulas that point at those tables. Power Query replaces the rows on each refresh and keeps the table names, so the summary formulas keep working.
  4. Data > Refresh All before the meeting. Each query reads the file as of its last check-in, which the file's page in your account shows.

Because the key lives in the credential store built into Excel and never in the workbook, you can send the finished file to a client. When they open it, they see the numbers as of your last refresh; they can't refresh it without a key of their own.

Why Basic, with the key as the user name

Excel offers several ways to sign in to a web source. We use Basic because the Power BI service accepts it for scheduled refresh, which Microsoft's Web connector documentation says isn't true of its Web API option, and because Basic keeps the key in Excel's credential store instead of the query text. The Power Query docs go through the query line by line.

When the Export button is the problem

If the Excel button in a QuickBooks report is greyed out or the export fails, that's QuickBooks and Excel talking to each other on that PC, and Intuit's article "Fix export to Excel issues in QuickBooks Desktop" is the place to start. A Power Query doesn't use that export at all, so it isn't affected.

Excel is a trademark of Microsoft Corporation.

Start a trial

14-day trial with one company file. Read-only: nothing is ever written to your books.