/databrill-core:dbl-metrics-amazon-inventory-historyfrom databrill-core
Report how much Amazon FBA stock a store held on past days — daily units per FNSKU or ASIN, and which products ran out of stock and when. Use when the user asks whether there were stockouts in a month, whether a product was in stock on a date, when it ran out or came back, or how stock moved over a period. When a product ran out and whether it came back is answered by loadAmazonFbaStockouts; stock levels on past days come from the inventory ledger through executeSql. Do not use for stock right now, for The Fulfillment Lab or Shopify stock, or for an ads pacing decision.
Ships in databrill-core. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
On a user- or organization-scoped connector, call listWorkspaces, select the
workspace, and pass its wsid explicitly to every data tool. A workspace-scoped
connector URL supplies that wsid. Never infer it from stores or from a
listWorkspaces result with one entry.
For when a product ran out of stock and whether it came back, the core MCP
server has loadAmazonFbaStockouts (next section). For units on past days,
use executeSql against amzfact_fnsku_ledger_history: Amazon's FBA
Inventory Ledger, one row per merchant, fulfilment centre, FNSKU, disposition and
day (the sections after it). For stock right now, use
dbl-metrics-amazon-inventory instead.
loadAmazonFbaStockoutsThe tool returns one row per stockout episode per merchant, marketplace and
FNSKU, with the FNSKU's current asin and every seller SKU pointing at it in
sellerSkus, so an FNSKU with several seller SKUs is one row. Its inputs are
stores (required, the usual store grammar), when (an ISO interval, or a
duration ending on the latest local today of the selected stores' marketplaces;
the last 90 days when omitted), products (child or parent ASINs, family names,
FNSKUs or seller SKUs, each token also matched exactly as an FNSKU and as a
seller SKU) and limit.
It reads two sources, and each episode end says which one dated it:
amzfact_fnsku_fbaInventory_history). A CLOSED_OUT episode starts on the
first day fulfillable stock closes at zero after a day closing in stock, and
ends on the first later day closing in stock. A day that reached zero but
closed in stock, after a day closing in stock, is a one-day INTRADAY_DIP; a
back-in-stock day is not also a dip. These ends have the basis FULFILLABLE.LEDGER_SELLABLE.stockoutBasis LEDGER_SELLABLE,
backInStockBasis FULFILLABLE.What the values mean, and what each source cannot see:
futureSupplyBuyableMax is the
highest buyable future supply on the episode's history days, which Amazon may
still sell through In-Stock Head Start; it is null for an episode with no
history day.meta.stores[].ledgerDaysWithoutReport lists those days.ledgerSummaryDateLast, the merchant's newest
summary day. A store's ledger days after it are in neither source, and for a
store with no FBA inventory history, a ledger episode still out was out on
that day.meta.stores[].ledgerCenterCountryCodes): a pan-European
marketplace pools the centres of the Pan-European FBA countries, which leave
out GB; GB, each North American country and every other marketplace count
their own country's centres. The merchant's centres with no country in
amazon_fulfillment_center, or missing from it, count in none; those with
rows on the ledger days read are named in meta.ledgerCentersWithoutCountry.stockoutDate (and stockoutBasis), and outOnOrBefore is a day
on which it was already out. daysOut is null unless the start is known and
either the end is known or the episode is still out.backInStockDate has isStillOut true only when the range
reaches the store's local today.meta.stores[] says, per store, whether history starts before the range
(historyStartsBeforeDateFirst), its first history day in the range
(historyStartsAt), and which days came from the ledger (ledgerDateFirst,
ledgerDateLast). A store with no history reads false, null and ledger
dates; a store with history throughout reads true and no ledger dates.meta.isTruncated
is true when more episodes matched than limit returned. When a required
table is missing, data is empty and meta.missingTables names it.The sections below read amzfact_fnsku_ledger_history with executeSql for
units on past days.
The ledger lists a key on a day only when it held units or moved. A day on which
an FNSKU sat at zero in a fulfilment centre has no row, so summing the rows
that exist never shows a stockout. Generate the days with generate_series,
LEFT JOIN the summed rows, and COALESCE to 0. Never carry the previous day's
balance forward.
The one exception: a day with no rows at all for a merchant is a ledger report Amazon returned empty, not a day of zero stock: such a day is missing, not a day out. The coverage check below lists those days.
There is no marketplace column. fulfillmentCenter is where the units physically
were, and a merchant's units move between centres in different countries. To
answer for one country, join amazon_fulfillment_center on fulfillmentCenter
and filter on its countryCode.
A centre with a null countryCode, or missing from that table, has no known
country. Its units drop out of a country filter, and the check below lists
them; their country is unresolved, since the shape of a centre code does not
establish its country.
Because every unit is in exactly one centre, adding centres never double counts, so a total across countries is correct here, unlike in the current-stock table.
disposition = 'SELLABLE' is stock that can be sold. The other dispositions
(CUSTOMER_DAMAGED, WAREHOUSE_DAMAGED, DEFECTIVE and so on) are not, and
are not in-stock units.endingWarehouseBalance is the units physically in the centre at the end of
the day. Units reserved for orders not yet shipped still count, so a small
positive balance does not prove the listing was buyable.inTransitBetweenWarehouses, not in the
balance. A zero day with units in transit is a transfer, not necessarily a
stockout customers saw.date is the business day in the region's local time zone.Coverage: the earliest day in the table is as far back as Amazon serves the
ledger (under two years) and nothing earlier can be fetched. The newest day
trails today by a few days, the delay Amazon's ledger reports carry. For the
last few days, amzfact_fnsku_fbaInventory_history holds fulfillable units per
marketplace, but only from the day the workspace began recording it;
dbl-metrics-amazon-inventory has its rules. That is a different measure from
the ledger balance, so the two are separate series, not parts of one.
Coverage first: days in the period with no ledger rows for a merchant.
SELECT m."merchantId", d::date AS "missingDay"
FROM (SELECT DISTINCT "merchantId" FROM "amzfact_fnsku_ledger_history") AS m
CROSS JOIN generate_series(DATE '2025-12-01', DATE '2025-12-31', INTERVAL '1 day') AS d
WHERE NOT EXISTS (
SELECT 1 FROM "amzfact_fnsku_ledger_history" AS h
WHERE h."merchantId" = m."merchantId" AND h."date" = d::date)
ORDER BY 1, 2;
Units and days at zero in one country and month. keys takes every FNSKU that held stock in
the country from a month before the period, so a product that was already out
on the first day still appears. Change the dates and 'US' together.
WITH "days" AS (
SELECT d::date AS "date"
FROM generate_series(DATE '2025-12-01', DATE '2025-12-31', INTERVAL '1 day') AS d),
"stock" AS (
SELECT h."merchantId", h."fnsku", h."date",
SUM(h."endingWarehouseBalance") AS "units",
SUM(COALESCE(h."inTransitBetweenWarehouses", 0)) AS "inTransit"
FROM "amzfact_fnsku_ledger_history" AS h
JOIN "amazon_fulfillment_center" AS c ON c."fulfillmentCenter" = h."fulfillmentCenter"
WHERE h."disposition" = 'SELLABLE' AND c."countryCode" = 'US'
AND h."date" BETWEEN DATE '2025-11-01' AND DATE '2025-12-31'
GROUP BY 1, 2, 3),
"keys" AS (
SELECT "merchantId", "fnsku" FROM "stock" GROUP BY 1, 2 HAVING MAX("units") > 0),
"filled" AS (
SELECT k."merchantId", k."fnsku", d."date",
COALESCE(s."units", 0) AS "units", COALESCE(s."inTransit", 0) AS "inTransit"
FROM "keys" AS k
CROSS JOIN "days" AS d
LEFT JOIN "stock" AS s
ON s."merchantId" = k."merchantId" AND s."fnsku" = k."fnsku" AND s."date" = d."date"),
"labels" AS (
SELECT "merchantId", "fnsku", string_agg(DISTINCT "sku", ', ') AS "skus", MIN("asin") AS "asin"
FROM "amzfact_sku_identity"
GROUP BY 1, 2)
SELECT f."fnsku", l."asin", l."skus",
MAX(f."units") FILTER (WHERE f."date" = DATE '2025-12-01') AS "unitsFirstDay",
MAX(f."units") FILTER (WHERE f."date" = DATE '2025-12-31') AS "unitsLastDay",
MAX(f."units") AS "maxUnits",
COUNT(*) FILTER (WHERE f."units" = 0) AS "daysAtZero",
COUNT(*) FILTER (WHERE f."units" = 0 AND f."inTransit" > 0) AS "zeroDaysInTransit",
string_agg(to_char(f."date", 'MM-DD'), ' ' ORDER BY f."date")
FILTER (WHERE f."units" = 0) AS "zeroDays"
FROM "filled" AS f
LEFT JOIN "labels" AS l ON l."merchantId" = f."merchantId" AND l."fnsku" = f."fnsku"
GROUP BY f."merchantId", f."fnsku", l."asin", l."skus"
HAVING COUNT(*) FILTER (WHERE f."units" = 0) > 0
ORDER BY "maxUnits" DESC
LIMIT 100;
Units in centres with no known country, which a country filter leaves out:
SELECT h."fulfillmentCenter",
SUM(h."endingWarehouseBalance") FILTER (WHERE h."date" = DATE '2025-12-31') AS "unitsLastDay",
COUNT(DISTINCT h."date") AS "daysWithStock"
FROM "amzfact_fnsku_ledger_history" AS h
LEFT JOIN "amazon_fulfillment_center" AS c ON c."fulfillmentCenter" = h."fulfillmentCenter"
WHERE h."disposition" = 'SELLABLE' AND c."countryCode" IS NULL
AND h."date" BETWEEN DATE '2025-12-01' AND DATE '2025-12-31'
GROUP BY 1
ORDER BY 2 DESC NULLS LAST;
For daily units of one product, keep days, stock and filled, filter
keys to its FNSKU, and select filled ordered by date.
One list of "days at zero" mixes very different cases:
Products that only ever held a unit or two have days at zero as well, beside the products that held meaningful stock and then ran out.
For the declared columns of any of these tables, read
${CLAUDE_PLUGIN_ROOT}/docs/schema/amazon/index.tsv and then that table's
.yaml beside it.
dbl-metrics-amazon-inventory for stock right now. dbl-metrics-traffic for
sales and buy box on given days. dbl-ask-sales-drop when the
question is why sales fell. dbl-ask-inventory-pacing for the ads decision.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub databrill/databrill-core-agent-plugin --plugin databrill-core19 skills in this plugin
/dbl-ask-inventory-pacingRecommend how advertising should respond to inventory — pause, throttle, hold, or ramp spend based on each product's runway. Use when the user asks "should we pause ads before the stockout", "we're low on stock, what about ads", "should we cut spend to stretch inventory", "we restocked — ramp back up?", "how do we sell down overstock", "long-term storage fee risk", or wants an inventory-driven ad pacing decision./dbl-ask-sales-dropDiagnose why a store's sales dropped — decompose the change into traffic, conversion, and price, and flag ad-channel and ad-efficiency causes. Use when the user asks "why did sales drop / fall / decline", "sales are down", "revenue dropped", "why did orders fall", "what happened to sales (week-over-week)", or wants a sales-decrease diagnosis for a marketplace./dbl-brand-configEdit brand configuration — product families, the ontology category and variant layer, ASIN-to-family and ASIN-to-SKU mapping, and effective-dated cost, rate and planning attributes. Use when the user asks to set up or edit product families, map ASINs to families or SKUs, seed the ontology, recategorise or relabel a family, or set a cost per unit, VAT rate or lead time for a period. Do not use for reading brand configuration — that is dbl-db./dbl-dashboardDesign or construct a dashboard, report, chart, table, or recurring analysis from Databrill MCP or database data. Use when the user asks to explore their data visually, build a dashboard or artifact, chart trends, make a management report, export a reporting dataset, or compare several accounts/workspaces./dbl-dbAnswer Databrill data questions that do not fit a dedicated metric skill by selecting the right MCP tool or a safe read-only Deno/n8n database workflow. Use for arbitrary database exploration, table or column discovery, SQL, CSV exports, orders, listings, returns, reimbursements, fees, settlements, Walmart, The Fulfillment Lab data, or questions about what data is available./dbl-metrics-adsAnalyze Amazon PPC advertising performance metrics including impressions, clicks, orders, spend, sales, CTR, CR, CPC, ACOS, and ROAS. Use when the user asks about ad performance, PPC metrics, advertising efficiency, campaign analysis, ACOS/ROAS, or spend by ad type (SP/SB/SBV/SD).Other plugins' skills for the same job