mcpdata Request an invite

Answers / Report with AI

How do I pivot data by month and region with AI?

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

Ask for the value grouped by both month and region: one query returns a row per month and region, which is a pivot table once the regions become columns. Your AI can lay it out, and a saved report can open it in the workbench's pivot directly.

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, revenue by month and region for 2025 from Demo.Orders, as a table with a column per region.
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_month", "region"], agg=[{"func": "sum", "column": "revenue", "alias": "revenue"}], sort=[{"column": "order_month", "desc": false}, {"column": "region", "desc": false}], limit=100) → 36 rows
What you should get · the recipe's real result from its last run
order_monthAPACAmericasEMEA
2025-0131,308,52365,707,86959,462,781
2025-0228,851,95460,315,30754,646,255
2025-0332,284,18267,671,76561,718,086
2025-0431,132,65565,476,85059,046,685
2025-0533,213,48869,285,38862,213,675
2025-0633,667,73669,698,34663,292,061
2025-0736,987,80976,946,70469,931,726
2025-0835,804,57774,864,59667,624,060
2025-0933,395,09469,275,22262,673,023
2025-1034,904,03272,328,85365,906,703
2025-1138,661,08781,419,66573,598,030
2025-1243,656,30791,427,03782,143,808

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

A pivot is a group-by on two columns, turned sideways. Doing the grouping in the database means every cell is an exact total over all the rows; the assistant only rearranges 36 rows into a 12 by 3 table.

Related questions