(+351) 21 24 10006  ·  info@bconcepts.pt
Carnaxide, Lisbon

How to Create a Prompt to Analyze Time Series in the Fabric Copilot

João Barros 03 de November de 2026 5 min read

This tutorial shows how to create a prompt in the Fabric Copilot to analyze time series: detect trend, seasonality and anomalies in time series data. Having a focused prompt makes it easier to explore patterns, generate visualizations and obtain transformation recommendations automatically with Copilot.

Prerequisites

  • Account with access to Microsoft Fabric and Copilot enabled.
  • A table or Dataset in Fabric with date/time and value columns (e.g.: Date, Value).
  • Basic knowledge of Power Query/SQL or Notebooks to follow and apply recommendations.

Step 1: Choose the Dataset and prepare the base prompt in Copilot

Open the workspace in Fabric where the Dataset is located. Identify the table with the time series (Date and Value columns). Then open Copilot (for example in a Notebook, Dataflow or in the Copilot interface where you can enter prompts) and write a base prompt that describes the task and the expected response format.

Analisa esta série temporal da tabela SalesTimeSeries (colunas: Date, Value).
1) Identifica tendência e sazonalidade.
2) Deteta até 5 anomalias com razões prováveis.
3) Sugere 3 transformações a aplicar (ex.: suavização, decomposição, agregação).
4) Fornece exemplos de código em Python (pandas) e em SQL para calcular a média móvel e detetar anomalias simples.
Retorna resposta estruturada com títulos e blocos de código.

Step 2: Refine the prompt for the Dataset context

Improve the prompt by adding context: time range, expected frequency (daily, monthly), and whether data are missing. This helps Copilot choose appropriate methods (e.g.: STL for seasonality, IQR for outliers).

Analisa a série temporal SalesTimeSeries (Date diário entre 2023-01-01 e 2024-12-31, coluna Value).
Frequência: diária. Pode haver dias com valores em falta.
Executa: decomposição em tendência/sazonalidade/residual (ex.: STL), deteção de anomalias e média móvel 7 dias.
Inclui: 1) resumo descritivo, 2) passos recomendados, 3) código em Python (pandas + statsmodels) e SQL para média móvel e marcação de anomalias.
Mostra exemplos com comentários curtos.

Step 3: Run the suggested code (Python example)

Copilot will suggest code. Copy the Python block to a Notebook in Fabric and run it. Minimal example for moving average, decomposition and simple anomaly detection using z-score:

import pandas as pd
from statsmodels.tsa.seasonal import STL
from scipy import stats

# carregar dados (exemplo: DataFrame df com Date e Value)
df['Date'] = pd.to_datetime(df['Date'])
df = df.set_index('Date').asfreq('D')

df['Value_ffill'] = df['Value'].fillna(method='ffill')
# média móvel 7 dias
df['MA7'] = df['Value_ffill'].rolling(window=7, min_periods=1).mean()
# decomposição STL
stl = STL(df['Value_ffill'], period=7)
res = stl.fit()
df['trend'] = res.trend
df['seasonal'] = res.seasonal
# anomalias via z-score do residual
df['residual'] = res.resid
z = stats.zscore(df['residual'].fillna(0))
df['anomaly'] = (abs(z) > 3)
print(df.tail())

Step 4: Adapt the solution to SQL in the Lakehouse or Synapse

If you prefer to run in SQL, ask Copilot for a T-SQL example that computes a moving average and flags potential anomalies by deviation from the mean. Copilot should return a query that uses window functions.

SELECT
  Date,
  Value,
  AVG(Value) OVER (ORDER BY Date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS MA7,
  Value - AVG(Value) OVER (ORDER BY Date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS Residual
FROM SalesTimeSeries
ORDER BY Date;
-- Para anomalias: pode calcular desvio padrão com window e marcar abs(residual) > 3 * stddev

Step 5: Make the prompt reusable and handle common errors

Create a prompt template in Copilot with variables (table name, date column, frequency). Include instructions to handle common errors: invalid dates, missing data, inconsistent frequency. An example of an additional instruction:

Se encontrar datas duplicadas, agregue somando os valores. Se faltar mais de 10% das datas, avisa e sugere imputação (ffill ou média).

Verify the result

Confirm the steps worked: visualize the DataFrame with trend, seasonal, MA7 and anomaly columns; validate that expected anomalies exist; check that the moving average follows the series without gaps. In SQL, validate that the MA7 and Residual columns were computed and that anomaly flags match visual peaks.

Conclusion

With a well-defined prompt in the Fabric Copilot you can automate basic time series analysis, obtain ready-to-use code and transformation recommendations. Next steps: ask Copilot for automatic visualizations (matplotlib/plotly) or integrate this prompt into an ETL routine for anomaly alerts. Tip: try varying the anomaly criterion (z-score vs IQR) and ask Copilot to justify the choice.