analyst

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:

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

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:

Good practice

Pitfalls