A weekly sales report emailed to you automatically from Google Sheets
A small script in Google Sheets counts orders and total sales for the last 7 days and emails them to you every Sunday morning, without you opening the spreadsheet.
The problem
You record your sales in a spreadsheet, but you only open it when you remember. So you don't know how much you sold this week compared to the last, and you notice a drop in sales late. What you want is a short summary that reaches you every week at a fixed time, without having to remember anything.
The tool
Google Sheets with Google Apps Script. According to the official docs, a script bound to the spreadsheet can read its data as an array and send email through MailApp. Its run can be scheduled with a time-driven trigger that sets the weekday and the hour in code through ClockTriggerBuilder, as we will do. The docs require that atHour be used with a frequency method such as everyDays or everyWeeks.
The steps
- Prepare a sheet in the spreadsheet named Sales, with column headings in the first row. Make column A the order date and column C the order amount. Make sure the dates are entered as real dates, not text, or the comparison won't work.
- From the spreadsheet choose Extensions then Apps Script. This creates a script bound to the spreadsheet.
- Delete the existing code and paste the following code. Replace the email with yours, and adjust the column numbers if your columns differ (0 is column A, and 2 is column C):
function weeklyReport() {
const sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sales');
const rows = sh.getDataRange().getValues();
rows.shift();
const cutoff = new Date(Date.now() - 7 * 24 * 3600 * 1000);
let count = 0, total = 0;
rows.forEach(r => {
if (r[0] >= cutoff) { count++; total += Number(r[2]); }
});
MailApp.sendEmail('you@example.com', 'Weekly sales report', 'Orders: ' + count + '\nTotal sales: ' + total);
}
function createWeeklyTrigger() {
ScriptApp.newTrigger('weeklyReport').timeBased()
.onWeekDay(ScriptApp.WeekDay.SUNDAY).atHour(8).create();
}
- Click Save. The getSheetByName function returns null if it can't find a sheet with that name, so if an error appears, check the sheet's name.
- Choose the function weeklyReport from the menu and click Run. Google will ask for permission to read spreadsheets and send email. Approve it. Then check that the email arrives and that the numbers are right by comparing them with the spreadsheet.
- After the test succeeds, choose the function createWeeklyTrigger and run it once only. This creates a trigger that runs every Sunday at 8 AM. Run it more than once and the triggers are duplicated, and you will get several emails.
- Verify the trigger: click Triggers in the left menu, and you should see one trigger for the function weeklyReport.
- Timezone: according to the docs, the script's timezone is used by default. Add inTimezone with the name of your zone, such as Asia/Riyadh, before create to be sure of the right time.
- To add a comparison with last week, add a second calculation for the period from 14 to 7 days ago and subtract. Start with the simple version and add more when you need to.
The real cost
Nothing. The quota limits according to the official page: email is 100 recipients a day for free accounts and 1,500 for Workspace accounts, and total trigger runtime is 90 minutes a day for free accounts. One weekly report is nowhere near these limits. Check the current numbers on the official page.
The free alternative
You can open the spreadsheet each week and add a total row with SUM, or use a Pivot table. It is manual but needs no script.
Notes
- We have not tried these steps ourselves yet; they are based on the current official docs. Button names may change, so if your interface differs, follow the docs.
- According to the docs, a recurring run time may be randomized within the set hour and then stay consistent day to day, so don't rely on minute-level accuracy.
- If the spreadsheet grows to thousands of rows, read the data in one go as in the code, and don't read cell by cell, because according to the docs repeated reads are very slow.
- Don't share the spreadsheet or the script with anyone who doesn't need to see your sales figures.
Sources
Did you like this guide?
The weekly newsletter is being prepared. Leave your email and we'll send it when it launches.
We use your email only to send the newsletter. Privacy policy
