Choosing where calculation logic belongs
You can often calculate the same number in more than one place: in the SQL of a Transform job, in a Charge job, in a measure, or in a view. The results can look the same in one report, but they behave differently when a reader changes the report, and different people can change them.
Use this page to pick the place. The question is not which tool can express the formula. It is which place can own the formula and stay correct.
Transform job --> Charge job --> Cube --> Fields --> Views
|
+--> post-charge Transform job --> Charge job --> another cube
Decision table
| You want to... | Put it in... | Why |
|---|---|---|
| Clean, join, deduplicate, or classify source rows, for example join subscriptions to customer ownership | Transform job | It establishes what a source row means, the same for every report. |
| Convert a quantity to a standard unit, or normalize currencies | Transform job | The value is fixed per row. |
| Allocate a shared cost across cost centers by usage weight | Transform job | It changes row amounts and must reconcile to the source total. |
| Set the grain, for example one row per customer, product, and billing month | Transform job | A Charge job expects a table that already has the right grain. |
Calculate a row amount, such as quantity * source_unit_price | Transform job | The amount is fixed per row and safe to sum under any grouping. |
| Apply a contracted rate or price per unit | Charge job | The value exists because of a commercial agreement, not because of the shape of the source. |
| Apply tiers, discounts, markups, fixed fees, or credits | Charge job, as charging rules | They decide the final charged amount, and commercial logic gets one place to audit and change. |
| Build one invoice row per customer and month from charged lines, or combine several charged results | Post-charge Transform job, then another Charge job | It creates a new dataset at a new grain from charged data. |
| Total or count by any dimension the reader selects | Measure | The filters and grouping of the report decide which rows take part. |
| Calculate a ratio, such as effective unit price or utilization | Measure | SUM(amount) / SUM(quantity) must use the rows of the current query. |
| Compare periods or use a rolling window | Measure | It compares aggregates over periods that the report selects. |
| Show percent of total, or a rank within a group | Measure | The total or the group exists only in the current query. |
| Classify customers in a way that every report uses | Transform job, or a canonical field | Use a Transform job when the class is a fact per row. Use a field when it comes from an aggregated result. |
| Try spend bands for one analysis | View-local field | It is analysis, and must not change production data. |
| Publish a statistical series with a fixed, documented window, or a forecast with a fixed training cutoff | Transform job | The window and its rules are part of the dataset. The result is valid only at its own grain, so publish one series per level and do not aggregate one into another. |
| Set KPI colors, trend direction, labels, number format, sort order, Top N limits, or reference lines | View | It is presentation for one view. Another view may want it differently. |
Measures are fields of the semantic model.
Decide in five questions
Ask these questions in order. Stop at the first "yes".
- Does the answer change when the reader changes a filter, the grouping, or the time range? Use a field.
- Does the logic establish what a source row means? Use a Transform job.
- Does the logic express a price, a contract, or a charge? Use a Charge job.
- Is charged data the input for a new dataset? Use a post-charge Transform job.
- Is it only about how one view shows the number? Use the view.
If two places still fit, choose the earliest one that can own a fixed fact without fixing something that the report should decide.
Test the choice with the grain
State the input grain and the output grain in one sentence each. Then ask what happens when the rows are grouped again.
- A value that you can sum safely under every grouping is additive. Calculate it once in the workflow.
- Ratios, averages, percentages, ranks, and windows are not additive. They need the rows of the current query, so they are measures.
For example, to report utilization, prepare two additive columns in a Transform job at the same grain, and divide the sums in a measure:
Transform job: runtime_hours, available_hours
Measure: SUM(runtime_hours) / SUM(available_hours)
Do not average the percentages of the rows. AVG(cost / usage) and SUM(cost) / SUM(usage) answer different questions.
Rules for a post-charge Transform job
Use a post-charge Transform job only when the charged result is the source of another dataset: the new dataset has a different grain, combines several charged results, or needs its own schedule, history, or checks.
- The Charge job it reads from can be an intermediate step without a cube.
- In the Transform job, give each Charge source a name and read it as
{{charged}}."<name>". - A later Charge job must publish the new dataset to a cube before reports can use it. Each Charge job defines its own grain.
- Reconcile the new totals to the charged results they come from.
Do not add a post-charge Transform job only to make a report faster.
See Transformers and Chargers.
Who can change what
Owners build workflows. Members work in spaces with the fields that the cube offers, and do not see the workflow. Let that decide the place too:
- A ratio, a rolling measure, or a reusable filter is a field. Nobody needs access to workflows to create one.
- Row-level and commercial logic do not belong in a view because a view is easy to edit. Ask an owner to publish the fact through the cube.
- When a report needs a column that the cube does not have, send the owner a request with the meaning, grain, unit, null behavior, and reconciliation rule:
Please prepare additive runtime_hours and available_hours at the resource and time grain,
including partial periods, and publish both through the cube.
Reconcile their totals to the runtime and availability sources.
The owner decides how to build it. Report builders keep using the same field keys and grain. See Logical cubes and Roles and access.
Mistakes to avoid
| Mistake | Why it goes wrong |
|---|---|
| The same formula in two places | Each business rule needs one owner. A measure may sum a produced column, but must not calculate that column again. |
| Joins, allocation, or deduplication inside a Charge job | Pricing starts from a table that already fits its grain. Repair rows in a Transform job. |
| A rank, percent of total, or rolling result stored in a table | The stored number is misleading as soon as a reader applies other filters or groupings. |
| Reports that read a transformed or charged table directly | Reports read a cube. Publish the dataset through a Charge job. |