Use case
A common analytics need is to show each row’s contribution to the overall total. For example, given revenue broken down by product brand, you might want to display what percentage of all revenue each brand represents:| brand | revenue | share of total |
|---|---|---|
| American Apparel | $5,930 | 28.98% |
| Patagonia | $239 | 1.17% |
| Columbia | $14,302 | 69.85% |
- Calculated fields — add a % of total column directly in a workbook without any data model changes. Best for ad-hoc exploration.
- Data modeling — define the share measure in the semantic model so it is available everywhere: APIs, embedded analytics, AI agents, and Explore. Best for a metric that should be reusable across the product.
Using calculated fields
Calculated fields let you add derived columns to a workbook report without touching the data model. To add a % of total column:- Build a table with the
products.branddimension and theorder_items.total_sale_pricemeasure. - Open the header menu on the
Total Sale Pricecolumn. - Choose Calculations → % of total.
% of total is available for measures with Count or Sum aggregation
types. See Calculated fields for the full list of
built-in calculations and how to edit them.Data modeling
When the share measure needs to be part of the semantic model — so it is returned by the API, visible in Explore, or accessible to AI agents — define it using multi-stage measures powered by Tesseract. The key building block is thegroup_by parameter: when set
to an empty list, the inner aggregation stage groups by nothing, computing
the grand total across all rows. The outer stage then joins that total back and
groups by the query’s dimensions as usual.
Calculating share of total requires three measures:
- A base measure — the regular aggregate, e.g.,
total_sale_price. - A helper measure — a multi-stage measure that re-aggregates the base
measure with
group_by: [], fixing the innerGROUP BYto nothing (the grand total). This measure is internal and should be hidden from views. - A ratio measure — a multi-stage measure that divides the base by the helper total.
order_items cube from the
ecommerce demo model. The brand and category
dimensions are proxied from the joined products cube so they can be
referenced by group_by.
Share of grand total
Add the three measures toorder_items:
group_by: [] tells Tesseract that the inner stage for total_revenue_grand_total
should group by no dimensions, producing a single grand-total row. The outer stage
joins it back and groups by whatever dimensions are in the query (e.g., brand),
so every row receives the same total denominator.
Hiding the helper measure from views
total_revenue_grand_total is a computation artifact — its value never changes
with dimension grouping, so it is meaningless to end users on its own. Exclude it
from the view using the excludes key while keeping includes: "*" for everything
else:
total_sale_price and revenue_share are exposed to consumers of the view.
Share of a fixed subtotal
Sometimes you want each row’s share within a category rather than the overall total — for example, each brand’s share of its product category’s revenue. Usegroup_by with the dimension you want to fix as the subtotal boundary.
The inner stage will group only by that dimension, and the outer stage will
group by the full set of query dimensions:
group_by: [category], the inner stage computes revenue per category.
The outer stage groups by both category and brand, so each brand row
divides its revenue by the right category total. Exclude
category_revenue_grand_total from the view the same way as shown above.
Result
Becausetotal_revenue_grand_total is excluded from the view, only the
meaningful measures — total_sale_price and revenue_share — are visible
to end users in Explore, workbooks, and the API.
Query filters applied to the dimension used in share calculations (e.g.,
filtering to a specific brand) will also filter the data used to compute
the total, making that row’s share appear as 100%.