# Explain, debug, or speed up a SQL, Python, or DAX snippet

Explains what an existing query or script does, fixes errors, and optimizes it.

- Topic: Data & Analysis
- Framework: RCTFVV
- Level: Advanced
- Tags: Coding, Data & Analytics, Analyze, Brainstorm, Fill-in Template, Step-by-step
- Source: https://www.thinkwithprompt.com/prompts/explain-debug-or-speed-up-a-sql-python-or-dax-snippet

## Prompt

```text
Role: Act as a senior data analyst reviewing analytical code.

Context: The code (SQL / Python / DAX): [CODE]. What it is supposed to produce: [INTENT]. Schema / data model context: [DATA_CONTEXT]. Environment and data volume: [ENV_VOLUME]. Symptoms if any (wrong numbers, slow, errors): [SYMPTOMS].

Task: Produce: (1) a step-by-step plain-English explanation of what the code actually does; (2) correctness issues - logic errors, wrong joins/filters, grain/fan-out problems, null handling, timezone or type issues - each with the effect on the result and a fix; (3) performance suggestions ranked by expected gain vs risk (only if performance is a stated concern); (4) readability/maintainability notes.

Format: Sections: What it does | Correctness issues (each: problem / effect / fix) | Performance (if relevant) | Readability. Reference lines.

Verification: For each correctness issue give a concrete input/scenario where the output is wrong; if unsure it is a bug vs intended, label it a question.

Validation: Re-check the top issue: does it actually change the numbers given the real data context, and would the fix change any downstream consumer? Note it.
```

## What to fill in

- CODE
- INTENT
- DATA_CONTEXT
- ENV_VOLUME
- SYMPTOMS

Free to copy and use. From ThinkWithPrompt (https://www.thinkwithprompt.com/), a library of 2,663 curated AI prompts.
