ipIterPrompt

Window Function Analysis — Finance & FP&A

Solve a sequencing/ranking problem with window functions. Purpose-built for finance & fp&a contexts.

iterpromptUpdated 2026-07-17553 copies

A structured data analyst prompt for sql & queries: solve a sequencing/ranking problem with window functions, tailored to revenue, cost, and budget data where the numbers must reconcile. It walks the model through a proven process with an explicit quality bar, and delivers the query using appropriate window functions with frame clauses explained, a worked mini-example showing the window math, and the common off-by-one traps checked.

The prompt

Variables to fill in: {{question}}{{schema}}{{dialect}}

You are a staff analytics engineer who writes SQL that is correct first, fast second, and readable always. I need your help in the context of revenue, cost, and budget data where the numbers must reconcile.

TASK: Solve a sequencing/ranking problem with window functions.

DELIVERABLE: Produce the query using appropriate window functions with frame clauses explained, a worked mini-example showing the window math, and the common off-by-one traps checked.

PROCESS:
1. Review the inputs below. If anything critical is missing or ambiguous, ask me up to three clarifying questions before producing the deliverable.
2. Restate what the question means in terms of the actual tables and grain from the inputs before writing SQL.
3. Build incrementally with CTEs named after business concepts; each step should be checkable alone.
4. State the assumptions the query makes (dedup rules, timezone, null handling) right in the comments.
5. Produce the deliverable in a clean, skimmable format I can use directly.

QUALITY BAR:
- Handles the classic traps: fan-out joins, nulls in aggregates, timezone drift, late-arriving data.
- Readable by the next analyst without a walkthrough.
- Includes the validation query that proves the result is sane.

INPUTS:
- The business question the query must answer: {{question}}
- Relevant tables with their columns, grain, and quirks you know about: {{schema}}
- SQL dialect/warehouse: BigQuery, Snowflake, Postgres, etc.: {{dialect}}

Run this prompt on a real model without leaving the page. Every run is saved to your history for this prompt.

Fill in the variables

How to use

  1. 1Fill in the {{question}}, {{schema}}, {{dialect}} variables with your real details — specifics in, specifics out.
  2. 2Paste the prompt into ChatGPT, Claude, Gemini, or any capable model.
  3. 3Answer the clarifying questions it asks; that step is what makes the output fit your situation.
  4. 4Iterate on the deliverable: ask for alternatives, tighter versions, or a different angle on any section.

Pro tips

  • If the output feels generic, add more concrete detail to the inputs — names, numbers, and constraints sharpen everything.
  • Works well in a thread: keep the conversation going to refine the query using appropriate window functions with frame clauses explained, a worked mini-example showing the window math, and the common off-by-one traps checked.

Related

The Quant Edge Engine

Turn any AI chat into the quant edge engine with this community persona prompt.

4,987 copiesOpen ↗

Data Architect & Business Strategist (CSV Audit & Pipeline)

Turn any AI chat into a data architect & business strategist (csv audit & pipeline) with this community persona prompt.

3,905 copiesOpen ↗

Query Debugging — Supply Chain

Find why a query returns wrong numbers. Purpose-built for supply chain contexts.

3,866 copiesOpen ↗

SQL Code Review — SaaS Metrics

Review an analyst's query for correctness and maintainability. Purpose-built for saas metrics contexts.

3,457 copiesOpen ↗