Questions Across Fact Groups
What this covers
Some models hold several lines of figures: payments, settlements and targets, for example. Each line is a fact group. This article explains which figures you can show together, which fields you can show them by, how to ask for a percentage or a difference between two lines, and what each refusal means. It applies the same way in SQL, in BI tools, in Excel and in the conversational agent.
The idea
Each fact group has its own measures and its own fields. Payments are recorded by day, merchant and channel. Targets are set by month and region. A figure only has a meaning by the fields its own line records.
Tessallite never joins two lines to each other, because that repeats rows and inflates totals. Instead it answers each line on its own and lines the results up on a field that both lines share.
If every line includes the same dimension table, use the field's own name from the field list, such as region_name. If the lines use different fields for the same thing, the modeller gives those fields one conformed dimension name, such as fg_region. Use that declared name to ask across the lines. Similar names alone do not make two fields shared.
So the rule for a question that mixes lines is short:
- Group and filter by fields that every line in the question shares.
- A total with no field at all always works.
What you can ask
| Question | Result |
|---|---|
| Payment amount and target amount by month | One row per month. Each figure is computed on its own line. |
| Payment amount and target amount, no field | One row with both totals. |
| Payment amount as a percentage of target amount, by region | One row per region with the calculated column. |
| The same, only for one year, where the year is not shown | Answered. A filter does not have to be a shown column. |
| The same, ordered by the percentage, or only rows above a threshold | Answered. |
| Target amount by merchant | Refused: targets are not set by merchant. |
| Target amount by day | Refused: targets are set by month, and a monthly figure cannot be split into days. |
A month that has payments and no target shows an empty target, not a zero and not a wrong number.
Calculations between lines
Write the calculation in the query, as you would for one line:
SELECT fg_month,
SUM(payment_amount) AS paid,
SUM(target_amount) AS target,
SUM(payment_amount) / SUM(target_amount) AS share_of_target
FROM modelz
GROUP BY fg_month
ORDER BY share_of_target DESC
- Use arithmetic (
+ - * /) and the numeric functionsROUND,ABS,CEIL,FLOORandCOALESCE. Text, date and logical functions, ranking and running totals, and a total of totals are refused in a calculation between lines. - A division always gives a decimal result, never a whole-number division.
- When the divisor is zero or empty, the cell is empty. The query is not stopped.
- These two division rules hold in every query, also when all figures come from one line.
- The name you give a calculated column must not be the name of another field of the model. If it is, the query is refused with: The column name "X" is the name of another field of the model. Use a different name.
- Each figure counts its own rows. If two lines both count the same record, adding the two figures counts that record twice. This is what the sum asks for: if you add your apples to your family's apples, the result is more than your family's apples. Tessallite does not remove the overlap and does not refuse the question.
If the modeller has defined a composite measure for exactly the calculation you need, use it instead. It carries one agreed definition for everyone.
In a calculation you write between lines, use one calculation for each figure: its total or its average, for example, but not both. A figure written without a function uses the calculation set by the modeller. A column label keeps the calculation you selected: SUM(payment_amount) AS paid makes paid mean that total.
The refusals and what to do
Tessallite refuses a question it cannot answer correctly. It does not drop a figure or swap a field to make the question fit.
"The measures [list] are not available by the dimensions [list] in model [name]." One of the figures is not recorded by one of the fields. Either the field belongs to another line, or it is finer than the level the figure is kept at (a monthly target asked by day). Use a field every line shares, ask at the coarser level, or ask for the figures in separate questions.
If you group a shared date by a coarser period yourself, for example DATE_TRUNC('month', calendar_date), the question is judged at that period. A monthly target can be shown by it.
The name "X" identifies different fields. Use an unambiguous field name. A shared field has the same name as a different field of the model, so the name alone does not say which one you mean. Use the field's own name in its line, or ask the modeller to rename one of the two.
A choice between values of different fields ("this or that")
A condition that joins two different fields with or cannot be applied to lines answered separately. Use a list of values on one field (region IN ('UK', 'FR')), or ask one question per condition.
A field shared by the lines that is itself a calculation A shared field has to be a plain field on each line. Ask by the plain field it is built from.
The measure "X" uses different aggregations in this question. The question asks for two different calculations of the same figure, such as its average and its total. Ask for each calculation in a separate question, or use the same calculation wherever that figure appears.
The refusal is the same text in SQL, in a BI tool and in the agent, so you can pass it to your modeller as it is.
In the conversational agent
The agent knows which figures belong to which line and which fields the lines share, so an ordinary question ("paid against target by month this year") is planned on the shared field without you naming it.
Two things are worth knowing:
- When the query service refuses a question, the agent shows that refusal unchanged. It does not quietly answer a different question.
- The agent is not allowed to calculate figures itself. If the query service cannot make a calculation you asked for and the calculation was only a column to show, the agent returns the figures it is made of with this notice: The governed query service could not make this calculation. The Tessallite conversational agent is not allowed to calculate figures itself, because it could make mistakes. Here are the figures you can use to work out the calculation you asked for. The query service's own reason follows it. If the calculation decides the order of the rows or which rows are shown, there is no such fallback and the refusal stands.
Good practice
- Start from the shared fields. The field list shows, for each measure, the fields it can be shown by.
- Ask for totals first, then add one shared field at a time.
- For detail that only one line has (merchant, day), ask that line alone, or connect to its own catalogue from Excel. See Excel Catalogues per Fact Group.
- When two lines both carry a figure with a similar name, check with the modeller that both count the same thing before you compare them.
Pitfalls
- A refusal is not a fault. It tells you the figure has no meaning by that field.
- An empty cell in a calculated column usually means a zero or missing divisor for that row, for example a month with no target.
- A persona can see fewer lines than the model holds. A figure that is not in your field list is not part of your model, and a question that uses it is refused as an unknown field.