AI & Business Automation

How to Automate Your Daily Sales Report with Google Sheets and Apps Script

Learn a step‑by‑step method to replace manual spreadsheet updates with a reliable Apps Script that pulls sales data, formats a report, and emails it each morning.

Problem: Every morning you open your Shopify (or other platform) dashboard, copy the day‑over‑day sales numbers, paste them into a Google Sheet, add totals, format the table, and then email the file to your team. The process takes 5‑10 minutes and is prone to copy‑paste errors.

Solution: Use Google Apps Script to pull the sales data via the platform’s API, calculate totals, format the sheet, and send the report automatically at a set time. The script runs in the cloud, so you never have to open a browser for this task again.

Prerequisites

  • Access to the e‑commerce platform’s API (e.g., Shopify Admin API token or Amazon MWS credentials).
  • A Google account with permission to create and edit a Google Sheet.
  • Basic familiarity with JavaScript syntax – the script language used by Apps Script.
  • At least one email address that will receive the report (you can add more later).

If any of these items are missing, obtain them before proceeding. For API access, refer to the platform’s developer documentation and generate a read‑only token; this limits risk if the script is compromised.

Manual Workflow – What You Do Today

  1. Log into the e‑commerce admin panel.
  2. Navigate to the sales‑summary page for the previous day.
  3. Copy the CSV or table data.
  4. Open a Google Sheet, paste the data, and adjust column widths.
  5. Insert formulas to calculate totals, taxes, and net profit.
  6. Apply conditional formatting to highlight low‑performing products.
  7. Click File → Email → Email this file and send it to the team.

This routine repeats daily, consumes time, and creates a risk of human error (wrong numbers, missed rows, or an unsent email).

Step‑by‑Step Automation Plan

1. Create the master Google Sheet

  • Open Google Drive, click New → Google Sheets, and name it Daily Sales Report.
  • In the first sheet, create header rows matching the fields you need (Date, Order ID, Product, Quantity, Gross, Tax, Net).
  • Leave a few empty rows at the top for a summary block (totals, % change, etc.).

2. Open the Apps Script editor

  • From the sheet, choose Extensions → Apps Script.
  • Delete any starter code and rename the project “Daily Sales Automation”.

3. Write a function to fetch yesterday’s orders

The example below uses Shopify’s REST API. Replace YOUR_STORE.myshopify.com and YOUR_ACCESS_TOKEN with your own values.

function fetchYesterdayOrders() { var today = new Date(); var yesterday = new Date(today); yesterday.setDate(today.getDate() - 1); var start = Utilities.formatDate(yesterday, "UTC", "yyyy-MM-ddT00:00:00Z"); var end = Utilities.formatDate(yesterday, "UTC", "yyyy-MM-ddT23:59:59Z"); var url = "https://YOUR_STORE.myshopify.com/admin/api/2023-04/orders.json?status=any&created_at_min=" + start + "&created_at_max=" + end; var options = { "method" : "get", "headers": {"X-Shopify-Access-Token": "YOUR_ACCESS_TOKEN"}, "muteHttpExceptions": true }; var response = UrlFetchApp.fetch(url, options); var data = JSON.parse(response.getContentText()); return data.orders; // array of order objects }

4. Populate the sheet with the fetched data

function writeOrdersToSheet(orders) { var ss = SpreadsheetApp.getActiveSpreadsheet(); var sheet = ss.getSheetByName("Report"); // rename if you used a different sheet name // Clear previous day’s rows (keep header rows) sheet.getRange(5, 1, sheet.getLastRow()-4, sheet.getLastColumn()).clearContent(); var rows = []; orders.forEach(function(order){ order.line_items.forEach(function(item){ rows.push([ order.created_at.substring(0,10), order.id, item.title, item.quantity, parseFloat(item.price) * item.quantity, parseFloat(order.total_tax), parseFloat(item.price) * item.quantity - parseFloat(order.total_tax) ]); }); }); if (rows.length > 0) { sheet.getRange(5,1,rows.length,rows[0].length).setValues(rows); } }

5. Add a summary block (totals, % change)

function addSummary() { var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Report"); var lastRow = sheet.getLastRow(); var grossRange = sheet.getRange(5,5,lastRow-4,1); var taxRange = sheet.getRange(5,6,lastRow-4,1); var netRange = sheet.getRange(5,7,lastRow-4,1); var gross = grossRange.getValues().flat().reduce((a,b)=>a+ (b||0),0); var tax = taxRange.getValues().flat().reduce((a,b)=>a+ (b||0),0); var net = netRange.getValues().flat().reduce((a,b)=>a+ (b||0),0); sheet.getRange("B2").setValue("Gross Sales"); sheet.getRange("C2").setValue(gross); sheet.getRange("B3").setValue("Tax Collected"); sheet.getRange("C3").setValue(tax); sheet.getRange("B4").setValue("Net Revenue"); sheet.getRange("C4").setValue(net); }

6. Email the report

function emailReport() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var file = DriveApp.getFileById(ss.getId()); var subject = "Daily Sales Report – " + Utilities.formatDate(new Date(), "UTC", "yyyy-MM-dd"); var body = "Please find attached the sales report for yesterday. The sheet includes a summary block at the top."; MailApp.sendEmail({ to: "[email protected], [email protected]", subject: subject, body: body, attachments: [file.getAs(MimeType.PDF)], // send as PDF for readability name: "Automation Bot" }); }

7. Orchestrate everything with a master function

function runDailyReport() { var orders = fetchYesterdayOrders(); if (orders && orders.length > 0) { writeOrdersToSheet(orders); addSummary(); emailReport(); } else { Logger.log("No orders found for yesterday."); } }

8. Schedule the script

  • In the Apps Script editor, click the clock icon (Triggers).
  • Choose runDailyReport as the function, set the event source to Time‑driven, and pick a daily trigger (e.g., 07:00 AM UTC).
  • Save – the script will now run automatically each morning.

Realistic Example

Ali runs a small clothing boutique on Shopify targeting customers in Pakistan and Saudi Arabia. He sells about 30 orders per day, each averaging $45. Before automation, Ali spends roughly 8 minutes each morning copying a CSV, pasting it, and emailing the file. After implementing the script:

  • Time saved: ~7 minutes per day (≈ 35 hours per year).
  • Error reduction: No more missing rows because the script pulls the exact order list.
  • Visibility: The PDF attachment is consistently formatted, so the finance team can file it without extra work.

Ali still reviews the PDF manually before the 09:00 AM meeting – a quick visual check that takes less than a minute.

Common Mistakes & How to Fix Them

  • API rate limits: Platforms often cap requests per second. If you hit the limit, add Utilities.sleep(500) between calls or request a higher quota.
  • Incorrect date handling: Time‑zone mismatches cause missing orders. Always convert dates to UTC when building the API query.
  • Missing permissions: The script needs UrlFetchApp and MailApp scopes. When prompted, grant access; otherwise the trigger will fail silently.
  • Sheet layout changes: If you add or remove columns, update the setValues range and summary formulas accordingly.
  • Failed email delivery: Check the spam folder and verify the recipient addresses. You can also enable MailApp.getRemainingDailyQuota() to ensure you haven’t exceeded Gmail’s daily limit.

Automation Checklist

  1. Confirm API credentials are read‑only and stored securely (use Google Secret Manager if possible).
  2. Create a dedicated Google Sheet with clear header rows.
  3. Copy the script sections into the Apps Script editor, replacing placeholder values.
  4. Run runDailyReport manually once to verify data appears correctly.
  5. Check the generated PDF for formatting and completeness.
  6. Set up a daily time‑driven trigger at a convenient hour.
  7. Monitor the script’s execution log for the first 3 days (View → Logs).
  8. Document any exception cases (e.g., holidays with zero orders) and decide whether to keep the email or skip it.
  9. Plan a quarterly review of API version updates and script maintenance.

When to Call a Professional

If you encounter any of the following, consider hiring a developer or an automation specialist:

  • Multiple platforms need to be merged (e.g., Shopify + Amazon) – the script will become more complex.
  • Data security requirements demand encryption or on‑premise storage.
  • You need advanced analytics (e.g., cohort analysis) beyond simple totals.
  • Your team lacks JavaScript experience and you prefer a no‑code solution like Zapier or Make.

Conclusion

Automating a daily sales report with Google Sheets and Apps Script turns a repetitive, error‑prone task into a reliable, hands‑free process. The setup takes about an hour, the script runs in the cloud, and you keep full control over your data.

Start with the small pilot described above, verify the output, and then expand to other reports (inventory, refunds, or ad spend). If you need help tailoring the automation to your exact workflow, discuss a practical automation pilot. Tell us the repetitive task, the input data, the expected result, and any exception cases – we’ll help you design a safe, maintainable solution.