mcpdata Request an invite

Answers / Analyse data

How do I calculate totals by week?

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

Group by a week column and sum. In the demo every order carries order_week (ISO weeks such as 2025-W10), so your AI asks for revenue and order counts per week in one query and gets a row per week.

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, total revenue and number of orders per week for 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": "eq", "value": 2025}], group_by=["order_week"], agg=[{"func": "sum", "column": "revenue", "alias": "revenue"}, {"func": "count", "column": "order_id", "alias": "orders"}], sort=[{"column": "order_week", "desc": false}], limit=60) → 53 rows
0M14M29M43M58M2025-W012025-W072025-W132025-W192025-W252025-W312025-W372025-W432025-W49
What you should get · the recipe's real result from its last run, first 12 of 53 rows
order_weekrevenueorders
2025-W0126,153,06748,132
2025-W0235,330,66465,813
2025-W0335,399,98166,328
2025-W0435,801,97066,755
2025-W0535,647,63966,018
2025-W0636,004,38366,949
2025-W0735,688,42067,109
2025-W0835,964,71967,043
2025-W0936,096,52167,353
2025-W1036,153,10967,295
2025-W1136,590,01667,930
2025-W1236,086,52567,427

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

Week numbering is where hand-made totals go wrong (which week does 30 December belong to?). Keeping an ISO week column next to the date makes the grouping explicit and repeatable: the same question gives the same rows every time.

Related questions