How to create iterative prompts in Copilot in Fabric: step by step
This tutorial teaches how to create iterative prompts in Copilot in Fabric to refine outputs (text, code, queries) until you obtain the desired response. Knowing how to iterate with prompts is useful to reduce errors, adapt outputs to the organization context and speed up tasks such as generating SQL, DAX or model explanations.
Prerequisites
- Account with access to Microsoft Fabric and Copilot enabled.
- Permissions to open Workspaces and relevant files (Notebook, SQL Endpoint, Dataflow).
- Sample database or file (CSV/Parquet) uploaded to the Lakehouse or Warehouse to test prompts.
Step 1: Choose the scenario and write the first prompt
Decide the concrete objective (e.g., generate a SQL query that compares sales by category while filtering anomalies). Write a simple, direct initial prompt. The first prompt serves to give context and intent.
Prompt inicial (exemplo):
"Tenho uma tabela Sales no Warehouse com colunas: OrderDate, Category, Amount. Quero uma query SQL que mostre vendas mensais por Category e destaque meses com queda > 20% face ao mês anterior."
Step 2: Run in Copilot and analyze the response
Enter the prompt into a Copilot window connected to the resource (e.g., SQL endpoint or Notebook). When you receive the response, read it and identify points that need clarification: assumptions, missing columns, performance.
Exemplo de saída esperada (resumo):
-- SQL sugerido pelo Copilot
SELECT
FORMAT(OrderDate, 'yyyy-MM') AS Month,
Category,
SUM(Amount) AS TotalAmount,
LAG(SUM(Amount)) OVER (PARTITION BY Category ORDER BY FORMAT(OrderDate,'yyyy-MM')) AS PrevMonth
FROM Sales
GROUP BY FORMAT(OrderDate,'yyyy-MM'), Category
HAVING (TotalAmount < PrevMonth * 0.8);
Step 3: Refine with iterative prompts — clarify assumptions
Ask Copilot to explain assumptions or adapt the query to your table format. For example, ensure OrderDate is in datetime format and that the FORMAT function exists in your Warehouse SQL dialect.
Prompt de refinamento:
"Agradeço. Confirma que OrderDate é datetime e que o Warehouse suporta FORMAT e LAG? Se não, adapta para usar CONVERT/TO_CHAR e janelas compatíveis."
Step 4: Fix common errors with focused prompts
If the first version produces an error (e.g., unsupported function, invalid aggregation with window), request a specific correction. Indicate the error you saw and ask for an alternative solution.
Prompt de correcção:
"Ao executar recebi: 'Windowed aggregates not allowed'. Ajusta a query para calcular PrevMonth usando CTEs em vez de window aggregate."
Step 5: Ask for optimizations and performance considerations
Request Copilot for optimization options: suggested indexes, limiting the temporal scope, using PARTITIONing or pre-aggregating in a Dataflow. This avoids unnecessary scans on large tables.
Prompt de optimização:
"Sugere melhorias para performance numa tabela Sales com 100M+ linhas. Propõe índices, filtros iniciais e versão que usa CTE ou temp table."
Step 6: Validate the result in the environment (Notebook or SQL endpoint)
Execute the final version generated by Copilot in your environment. If using a Notebook, paste the SQL into a SQL cell and run; if using the Warehouse, test it in the SQL Editor. Note any error message for a new iteration cycle.
Verify the result
Confirm that the query runs without errors and that the results make sense: expected columns, months with drops correctly identified and acceptable performance (execution time). Compare results with manual samples (e.g., summarize in Excel) to validate the logic.
Conclusion
Iterative prompts in Copilot in Fabric help turn a vague request into precise code or analyses, reducing common errors and improving performance. Next steps: automate the final prompt in a parameterized Notebook or save versions in a Repository. Tip: keep a history of iterations to replicate improvements and ask — which hypothesis do you want to test next?