⚡0 XP🔥0

Prompts for Data, Excel and SQL

Lesson 13 of 19 ⏱ 5 min read ✎ 2 exercises ❓ 4-question quiz ▶ Runs Python

Use AI to write Excel formulas, SQL queries and pandas code, clean messy data, explain trends and build analysis plans - while protecting data privacy and checking every number.

AI as your data assistant#

AI is excellent at the thinking and writing parts of data work: choosing an approach, writing formulas, SQL and Python, cleaning rules, explaining results. The golden rule:

AI designs the analysis. Code and spreadsheets do the calculations.

LLMs can make arithmetic mistakes, especially with many rows. Formulas and code don't.

हिंदी में समझें

Data के काम में AI का सबसे अच्छा इस्तेमाल है - formula, SQL query या Python code लिखवाना, और नतीजों को समझाना। लेकिन बड़े data पर सीधे AI से हिसाब (calculation) न करवाएँ - वह गलती कर सकता है।

सही तरीका: AI से formula/code लिखवाओ → उसे Excel या Python में खुद चलाओ → नतीजा सही और दोहराने लायक (repeatable) होगा।

और ध्यान रखें: customers के नाम, फ़ोन नंबर जैसी personal जानकारी AI को न भेजें - सिर्फ column के नाम और नकली (sample) rows दें।

1. Excel and Google Sheets formulas#

Describe your sheet precisely:

In Excel 365, my sheet "Sales" has:
A: Date, B: Region (North/South/East/West), C: Product, D: Quantity, E: Price
Rows 2 to 5000.

I need a formula in another sheet that shows total revenue (Quantity × Price)
for the region in cell B1 and the month in cell B2 (e.g. "Nov-2026").
Explain how the formula works in simple steps.

More useful requests:

  • "Formula to extract the first name from 'Sharma, Ravi Kumar' in A2."
  • "Highlight rows where the due date in F has passed and status in G is not 'Paid' - give the conditional formatting rule."
  • "Explain this formula: =IFERROR(INDEX(B:B, MATCH(1, (A:A=H2)*(C:C=H3), 0)), "Not found")"
  • "Create a pivot table plan to compare monthly sales by region."

2. SQL queries#

Always give the database type and schema:

Database: MySQL 8.

Tables:
students(id INT, name VARCHAR(100), city VARCHAR(50), joined_on DATE)
enrolments(id INT, student_id INT, course VARCHAR(50), fee_paid DECIMAL(10,2))

Write a query that shows, for each city, the number of students who joined
in 2026 and the total fees paid, sorted by total fees (highest first).
Only include cities with at least 5 students. Explain each clause.
▶ Try it YourselfPython
Ctrl + Enter to run
Common Mistake

Never paste database passwords or connection strings. For queries that change data (UPDATE, DELETE), test on a copy first and check the WHERE clause carefully.

3. Python / pandas analysis#

I have a CSV "sales.csv" with columns: date, region, product, qty, price.
Write pandas code (Python 3.12) to:
1. Load the file and parse dates.
2. Add a revenue column.
3. Show monthly revenue by region as a table.
4. Plot a line chart of monthly total revenue with matplotlib.
5. Print the top 5 products by revenue.
Add comments for a beginner.

Then run the code yourself - in Jupyter, VS Code or Google Colab.

4. Cleaning messy data#

Here are 10 sample rows from a messy contact list. Suggest cleaning rules
(phone format, name capitalisation, duplicate detection, city spelling),
then write a Python function that applies them to the whole file.

<sample>
name,phone,city
  ravi KUMAR ,+91 98765-43210,indore
Asha verma,9876543210,Indor
...
</sample>

5. Understanding results#

After you calculate, AI helps explain and communicate:

Here is our monthly admissions table for 2026 (calculated in Excel).
1. Describe the main trends in 4 bullet points.
2. Suggest 3 possible reasons for the drop in June-July.
3. Suggest 2 charts that would show this clearly to the director.
Don't recalculate the numbers - use them as given.

<table>
...
</table>
Tip

Ask "What questions should I ask of this data?" - AI is great at suggesting analysis ideas you hadn't considered.

Protecting data privacy#

Do Don't
Share column names and types Paste full customer databases
Use small, fake or anonymised samples Share names, phone numbers, Aadhaar/PAN, salaries
Let AI write code that you run locally Upload confidential files to unapproved tools
Follow your company's AI policy Assume chat data is private
▶ Try it YourselfPython
Ctrl + Enter to run

Summary#

  • AI designs the analysis and writes formulas/SQL/code; spreadsheets and code do the exact calculations.
  • For formulas: give columns, rows, Excel version and the exact result wanted.
  • For SQL: give database type and full schema; test data-changing queries on copies.
  • For pandas: describe the file and steps; run the code yourself.
  • Protect privacy: share structure and anonymised samples only.

Practice Exercises

Write your code, then press Check. Your program is tested automatically.

1

Schema description for a prompt

Good SQL prompts include the table schema. Write describe_table(name, columns) where columns is a dict of column → type. Return:

Table NAME(col1 TYPE1, col2 TYPE2, ...)

2

Anonymise before sharing

Before sending sample rows to an AI, hide personal data. Write anonymise(rows) that takes a list of dicts with keys name, phone, city, amount and returns new dicts where name becomes "Customer 1", "Customer 2"... (by position) and phone becomes "XXXXXXXXXX". Keep city and amount. Don't modify the original rows.

Quick Quiz

Q1.

When asking AI for an Excel formula, what should you include?

Q2.

When asking AI for a SQL query, what must you provide?

Q3.

What's the safest way to let AI analyse customer data?

Q4.

Why ask AI to write code (Python/SQL) instead of calculating numbers directly in chat?