Unit costs
Import a business metric such as customers, requests or revenue by CSV or the Public API, and chart a saved report's cost or usage per unit of it, its gross margin, or the metric itself.
A business metric is a quantity your business counts each day, such as active customers, orders, API requests or revenue. A saved cost report that names one charts a figure of it beside its cost or usage, on a second axis, for each day, week, month or quarter: the cost or usage per unit of the metric, the gross margin with the metric as revenue, or the metric's own amount.
Before you start
- Creating, renaming, filling and deleting business metrics needs the Editor team role in a workspace your team can edit. Every team role can read them. See Access model.
- A unit cost is kept when the report is saved; see Save and manage reports.
- A gross margin needs a metric whose unit is the report's currency code, such as
EUR, with its revenue uploaded in that currency.
Create a business metric
- Open Business metrics under Reporting and select New metric.
- In Create business metric, enter a Name and a Unit, what one unit counts in the singular, such as customer. For revenue, enter its currency code, such as
EUR, which a gross margin needs. - Optionally enter Label columns, up to five separated by commas: the columns of your values file that split each day's value, such as region or plan, so that a report can count only some labels, such as
eu. None may be calleddateoramount, start with=,+,-or@, or be named twice. - Select Create metric. A field the metric cannot take says why under it, and nothing is sent. Once the metric is created, Upload values opens for it; see Upload values from CSV.
A metric's label columns are fixed once it exists, because every stored value is keyed by them. Edit business metric renames the metric or its unit only.
Upload values from CSV
- On Business metrics, select the upload icon on the metric's row, "Upload values for" followed by its name.
- In Upload values, choose a CSV file and select Upload.
The file has a header row with a date column (YYYY-MM-DD), an amount column (a number, zero or more) and any of the metric's label columns, in any order. Each row is one day for one combination of labels; a label column a row leaves empty is unlabelled.
The file is UTF-8, with or without a byte order mark; in Excel, save it as "CSV UTF-8". A file in another encoding, such as the Windows code page Excel's plain "CSV" writes, is refused rather than stored with its accented letters altered.
Download a sample file in Upload values saves a file with the metric's own columns and two example rows, dated the two days before today, to replace with your values.
Code
A summary such as "3 new, 0 replaced, 0 unchanged" says what the upload did. Under it, the confirmation says where a unit cost is charted and offers Open cost reports, which opens the workspace's default report; Chart a unit cost goes on from there. Each row replaces the value the metric already holds for its day and labels, so uploading the same file again changes nothing.
A file the import refuses stores nothing, and Upload values stays open under "The file was not imported". It lists each refused row with what is wrong in it, such as "Row 4: the amount 'many' is not a number.", or the one problem of the whole file, such as its encoding. Fix the file and upload it again.
The Values column of Business metrics shows how many values each metric holds and the first and last day they cover, or "No values yet".
Send values through the Public API
POST /v1/business-metrics/{metricId}/values takes up to 10,000 values and 30 MB a request, each a date, an amount as a decimal string and optional labels, at most one per label column, and stores them the same way: each replaces the value of its day and labels. A request that would add values past the organization's limit below answers 422 limit_exceeded and stores nothing. GET /v1/business-metrics/{metricId}/values reads them back by day. See the API reference, and Terraform for the costfluent_business_metric resource.
Chart a unit cost
- Open a report, saved or new, open More actions and choose Unit cost.
- Under Unit cost, choose the metric, shown as its name and "(per" its unit. None charts the report alone. In a workspace with no business metric yet, the hint under the field adds "This workspace has no business metrics to divide the cost by yet." and How business metrics are created, which opens Create a business metric; if you may manage business metrics, Create a business metric beside them opens the Business metrics page.
- Under Calculation, choose what to chart. The report's measure decides what is offered: Cost per unit on the cost measure and Usage per unit on the usage measure, Gross margin on the cost measure only, and Metric value on every measure.
- For a figure per unit, optionally choose a Scale, from Per unit to Per billion units, such as Per 1,000 units for the cost per thousand requests.
- Optionally, for a metric with label columns, enter values under Count only these labels, one at a time, each with Enter, such as
euandusunder region; a value may hold a comma. A column left at "Every value" counts all of it. - Select Apply. The report shows the unit cost as an unsaved change: select Save changes to keep it in a saved report, or Save as report on a new one.
The report's chart then draws the figure against its own axis on the right, and a card shows the range's figure, counting only the periods that have one:
- Cost per unit draws a "Cost per" line named with the metric's unit, in the report's currency, and an "Average cost per" card: the range's cost over the metric's amount.
- Usage per unit draws a "Usage per" line in the usage's unit, such as tokens per pull request, and an "Average usage per" card.
- Gross margin draws a "Gross margin" line as a percentage, each period's revenue less its cost over the revenue, and a "Gross margin for the period" card: the range's revenue less its cost over its revenue.
- Metric value draws the metric's own amount under its name, with no card.

With a scale, a figure per unit is per that many units: at Per 1,000 units the line reads "Cost per 1,000" followed by the unit.
How it behaves
- A unit cost needs a granularity of Daily, Weekly, Monthly or Quarterly; a cumulative report is refused with "A unit cost is a figure of each bin; choose a day, week, month or quarter bin." The Unit cost dialog checks the granularity the page shows, so choose another one on the page first. A report whose measure or granularity you change on the page after applying a unit cost draws without the line until it is one the calculation charts.
- A week runs Monday to Sunday, and a week, month or quarter sums the metric's daily amounts within the report's range.
- A period with no metric amount, or an amount of zero, has no cost or usage per unit, and a period without revenue has no gross margin: the line breaks there rather than dropping to zero.
- A period where the metric has an amount but the report has no cost, such as a day a filtered service did not run, reads zero cost or usage per unit and a gross margin of 100%, and counts toward the card's figure for the range. A period that starts after the "Data through" day stays out until its cost arrives.
- A gross margin is the metric's revenue against the cost the report counts, its filter and settings included, not your company's gross margin. A metric whose unit is not the report's currency code (compared ignoring case and spaces), or a report whose costs are in more than one currency, has no margin in any period.
- Usage per unit divides each period's quantity, so it needs the report's usage in one unit: filter the report to one usage unit, such as tokens, or it has no figure.
- The API and the
costfluent_cost_reportresource take the calculation asunitCostCalculationandunit_cost_calculation(perUnit,grossMarginormetricValue) and the scale asunitCostScaleandunit_cost_scale(1,100,1000,1000000or1000000000, other than1only withperUnit). Settings that name the metric but leave either out keep the report's own; settings without the metric return them toperUnitand1. The report's data carries each period's figure asvalue, a gross margin as a fraction, 0.4 for 40%. - Without label values the unit cost divides by the metric's whole amount for the period. With them it divides by the values whose label matches any one value listed for its column, in every column filled in:
eu, usunder region andprounder plan counts the pro values of either region. A period whose values all fall outside has no cost per unit. - The API and the
costfluent_cost_reportresource take the same choice asunitCostLabelFilterandunit_cost_label_filter, each a label column listed once with its values; it needs the metric, and a column the metric lacks is refused. - A report whose costs are in more than one currency with conversion off has no cost per unit; see Cost amounts.
- If the business metrics cannot be loaded, Unit cost says "Business metrics could not be loaded." with Retry.
- Export above the cost table offers Unit cost (CSV) under Costfluent columns while the report charts one: one row per period with its date, the metric's amount and the figure. See Export to CSV or Excel.
- An upload is all or nothing: one row with a date that is not
YYYY-MM-DD, an amount that is not a number or below zero, a label column the metric does not have, a label a spreadsheet would read as a formula, or a day and labels already on an earlier row refuses the file, naming the first rows that fail. A file holds at most 100,000 rows and 9 MB; split a larger one by date. - An organization holds at most 2,000,000 values across all its metrics, and a workspace at most 50 metrics. An upload or request that would add values past the limit is refused whole, and one that only replaces stored values always passes; delete a metric you no longer use to make room.
- Deleting a metric deletes its values, and a report charting it goes back to its measure alone. "Business metric deleted" confirms it.
- A dashboard widget and a share link show a report's unit cost as the report does.