mcpdata Request an invite

Answers / Analyse data

How do I compare two time periods in one query?

Recipe verified on Ran on the public demo (read-only)
Short answer

Filter to both periods and group by the period as well as what you're comparing. Your AI asks for revenue by region for 2024 and 2025 in one query and gets a row per region and year, ready to put side by side.

Steps

  1. Connect your assistant to the public demo. It's a read-only instance with 10 million synthetic orders, so you can try this before you have your own. In Claude Code:
    claude mcp add --transport http mcpdata-demo https://demo.mcpdata.org/mcp --header "Authorization: Bearer cdb_live_PkVoldus8qcE-hqffjajNZzQwiA7rTHMoR4RLSAxsCE"

    The key is public on purpose: it can only read the demo's sample data. For Claude Desktop, Cursor and other apps, see Connect your AI.

  2. Ask your question. Give your AI this prompt:
    Using mcpdata, compare total revenue by region in 2024 and 2025 from Demo.Orders.
What your AI does: the tool call it makes for this prompt, and what came back
query(table_name="Demo.Orders", filters=[{"column": "order_year", "op": "in", "value": [2024, 2025]}], group_by=["region", "order_year"], agg=[{"func": "sum", "column": "revenue", "alias": "revenue"}], sort=[{"column": "region", "desc": false}, {"column": "order_year", "desc": false}]) → 6 rows
What you should get · the recipe's real result from its last run
regionorder_yearrevenue
Americas2024751,617,490
Americas2025864,417,603
APAC2024359,678,461
APAC2025413,867,443
EMEA2024678,537,780
EMEA2025782,256,894

Synthetic data: the demo's orders are generated, not real customers.

The assistant needs mcpdata connected (step 1) to run the query.

Why this works

Two separate queries can drift (different filters, a typo in one). One query with both years in the filter and the year in the group-by guarantees both periods are counted the same way. For a ready-made side-by-side layout, a saved view can use SUM(CASE WHEN order_year = 2025 THEN revenue ELSE 0 END).

Related questions