| copyright |
|
||
|---|---|---|---|
| lastupdated | 2026-05-14 | ||
| keywords | multi-fact metrics, multiple tables, calculate after aggregate | ||
| subcollection | watsonx-bi |
{{site.data.keyword.attribute-definition-list}}
{: #multi_fact_metrics}
You can create calculations that help answer questions that span multiple metrics. These calculations are based on a multi‑fact metric, which combines measures from different fact tables. Multi‑fact metrics are especially useful when you need to compare or analyze data across fact tables that share common dimensions. {: #shortdesc}
{: #prereq_multi_fact}
Before you create a multi-fact metric or multi-fact calculation, make sure that:
-
You have at least two fact tables in your semantic data model
-
Measures are already defined in each fact table that you want to use
When you query metrics that come from different facts, watsonx BI does not join them on shared dimensions. You can ask questions on shared dimensions through calculations that are created for cross-metric queries. {: note}
{: #create_multi_fact}
To create a calculation that spans multiple metrics, you must first define a metric which contains measures from the multiple fact tables.
-
Open the semantic data model that you want to create the metric in from Data and Metrics.
-
Go to Advanced mode.
-
In the semantic data model tree, select measures from the different fact tables and from the context menu, select New > Metric definition.
-
Specify the details for the metric definition, include the data scope and measure role.
-
Click Done to finish.
-
Select the metric definition that you just created and from the context menu, choose New > Calculation.
-
Define your calculation by using the measures within the metric definition. For example,
Sales_Target - Sales_Total. -
Select Calculate after aggregation.
When Calculate after aggregation is selected, the calculation is performed after values are aggregated. This is required for multi‑fact metrics so that the results from each fact table are aggregated first and only then included in the calculation. {: important}
-
Select OK to save the calculation.
-
Select Actions > Save to save your semantic data model.
-
Select the metric definition and export it to make it available in conversations.
{: #example_variance}
Consider a scenario where you have:
-
Sales fact table with a
Sale_Totalmeasure -
Sales Target fact table with a
Sales_Targetmeasure -
Time dimension that joins both fact tables
To create a Variance from plan calculation that shows the percentage of actual sales compared to target:
-
Create a metric definition by using measures
Sale_TotalandSales_Targetmeasures from the Sales and Sales Target tables. -
Select the metric definition in the semantic model and create a calculation named
Variance from plan. Use the expression:100 * Sale_Total / Sales_Target{: codeblock}
-
Select Calculate after aggregation and click OK.
This metric calculates the variance by first aggregating the sales totals and targets separately, then performing the division and multiplication to get the percentage variance.
-
Save the semantic data model and export the metric definition to the project.
When you ask a question in a conversation that uses this metric, {{site.data.keyword.wxbia_short}} uses the calculation that you created and aggregates the expression according to the context of your question.
{: #related_multi_fact}
-
Calculations{: external}
-
Building metrics in the Advanced mode{: external}
-
Data modeling in watsonx BI{: external}