0
0
Google Sheetsspreadsheet~15 mins

Sheets API basics in Google Sheets - Real Business Scenario

Choose your learning style9 modes available
Scenario Mode
👤 Your Role: You are a data analyst at a retail company.
📋 Request: Your manager wants you to automate the process of updating monthly sales data in Google Sheets using the Sheets API.
📊 Data: You have a Google Sheet with sales data for different products and months. The sheet has columns: Product, Month, Sales.
🎯 Deliverable: Create a Google Sheets document and use the Sheets API to add new sales data, update existing sales, and read total sales per product.
Progress0 / 5 steps
Sample Data
ProductMonthSales
ApplesJanuary120
BananasJanuary150
ApplesFebruary130
BananasFebruary160
CherriesJanuary90
CherriesFebruary100
1
Step 1: Create a new Google Sheet and enter the sample sales data into columns A, B, and C starting from row 1 with headers.
Manually input data or use Sheets UI to create the table as shown in sample_data.
Expected Result
Sheet with columns Product, Month, Sales and 6 rows of data.
2
Step 2: Use the Sheets API to append a new row with sales data: Product='Apples', Month='March', Sales=140.
Use the API method 'spreadsheets.values.append' with range='Sheet1!A:C' and values=[['Apples','March',140]].
Expected Result
New row added at the bottom with Apples, March, 140.
3
Step 3: Use the Sheets API to update the sales for Bananas in February to 170.
Use 'spreadsheets.values.update' with range='Sheet1!C4' and valueInputOption='USER_ENTERED', values=[[170]].
Expected Result
Cell C4 updated from 160 to 170.
4
Step 4: Use the Sheets API to read all sales data and calculate total sales per product.
Use 'spreadsheets.values.get' for range='Sheet1!A2:C' and then sum sales grouped by product in your code or sheet.
Expected Result
Totals: Apples=390, Bananas=320, Cherries=190.
5
Step 5: In the Google Sheet, create a summary table with unique products and total sales using formulas.
In E1 enter 'Product', F1 enter 'Total Sales'. In E2 enter =UNIQUE(A2:A7). In F2 enter =SUMIF(A:A,E2,C:C) and drag down.
Expected Result
Summary table showing Apples 390, Bananas 320, Cherries 190.
Final Result
Product   Month    Sales
Apples   January   120
Bananas  January   150
Apples   February  130
Bananas  February  170
Cherries January   90
Cherries February  100
Apples   March     140

Summary:
Product   Total Sales
Apples    390
Bananas   320
Cherries  190
Apples have the highest total sales of 390 units.
Bananas sales were updated for February to 170 units.
New sales data for Apples in March was successfully added.
Bonus Challenge

Use the Sheets API to create a chart in the Google Sheet that visualizes total sales per product.

Show Hint
Use the 'spreadsheets.batchUpdate' method with a 'AddChartRequest' specifying chart type and data ranges.