Sales Rep

profileKolh

See attached

  • 2 years ago
  • 13
files (5)

salesdata_2.py

from openpyxl import load_workbook # Open the SalesData spreadsheet workbook = load_workbook("SalesData.xlsx") sheet = workbook.active # Grab columns A (Date), C (Rep), and G (Total Sales), except title row gridData = sheet.iter_rows(min_row=2, min_col=1, max_col=7, values_only=True) # Convert that data into a list, filtering out non-numeric sales values salesList = [] salesDetails = [] # List to store details (date, rep, and total sale) for nextRow in gridData: date = nextRow[0] # Date is in column A (index 0) rep = nextRow[2] # Salesperson is in column C (index 2) total_sale = nextRow[6] # Total sale is in column G (index 6) # Check if the total sale is numeric (to avoid errors from text or blank cells) if isinstance(total_sale, (int, float)): salesList.append(total_sale) salesDetails.append((date, rep, total_sale)) # Store corresponding details # Find the index of the largest sale if salesList: max_sale = max(salesList) max_index = salesList.index(max_sale) # Get the corresponding date and salesperson from the salesDetails list max_sale_date, max_sale_rep, max_sale_value = salesDetails[max_index] # Print the result print(f"Largest Sale was {max_sale_value} made on {max_sale_date} by {max_sale_rep}") else: print("No valid sales data found.")