Database queries are used to define which data is pulled in from your BI/Database system into Lucanet xP&A (Extended Planning & Analysis). They are entered during the set-up process of the integration (see individual set-up instructions for each system) and need to be structured in a certain way.
In this chapter we explain how a database query is defined, how to import dimension hierarchies and what needs to be considered in regards to linked dimensions that are queried.
selectdate, users, country, region as "country > region"fromusers_table
Explanation:
The data is queried from the users_table.
The first column (date) has the dates of the transactions (timestamp or date type).
The second column (users) contains the values of the "users" variable (number type).
The third column (country) is a dimension column, the users are broken down by country (string).
The fourth column ( region as "country > region") is a dimension mapping. The region is not an independent dimension, but the countries are assigned to regions.
Example query result:
Example query result
Querying Constant Values
If you only want to import constant values (no time series), the date column can be null. For example:
selectnull as date, price, plan_namefromprice_table
When you create or edit a database data source in xP&A, choose the option that matches your query results:
Variable names as column names: Each variable has its own numeric column, e.g. Revenue and Costs. Enter these columns under Variable columns.
Variables as values in a single column: One column contains the variable names and another column contains their numeric values. Enter the column with the variable names under What column is the variable name in? and the column with the numeric values under Where is the value?.
You configure the date column separately. xP&A treats the remaining columns as dimensions. You do not need to pivot the query results into separate variable columns.
Example query with variables in a single column:
sql
The following table shows the result of the example query:
date
metric
amount
country
2026-01-01
Revenue
1000
Germany
2026-01-01
Costs
600
Germany
2026-02-01
Revenue
1200
Germany
2026-02-01
Costs
700
Germany
For this query result, configure the data source in xP&A as follows:
Enter date under Date column.
Select Variables as values in a single column.
Enter metric under What column is the variable name in?.
Enter amount under Where is the value?.
The query form with this configuration is displayed as follows, for example:
As a result, Revenue and Costs become separate data items in xP&A that you can link to model variables. The country column becomes a dimension. The metric column identifies the variables and does not become a dimension.
You can import a dimension hierarchy in xP&A directly from the values that a SQL query returns. To do so, activate the Import dimension hierarchies check box when you create or edit the SQL data source. The check box is available for all SQL data sources in xP&A. It is located below the Variable columns field in the data source dialog:
'Import dimension hierarchies' check box in the data source dialog
The Import dimension hierarchies check box is deactivated by default. When the check box is deactivated, > remains part of the dimension item name. For example, xP&A imports Retail > Customer A as one flat item. Activate the check box only when your query returns hierarchy paths.
When the check box is activated, separate the hierarchy levels in the values of a dimension column with >. For example, Retail > Customer A creates Retail as a parent item and Customer A as its child item. xP&A ignores spaces before and after >. A path can include more than two levels. xP&A creates missing parent items automatically.
The position of > determines its meaning. The following table compares > in a dimension column's value with > in a column header:
Where it appears
Example
Meaning
In a dimension column's value, with the Import dimension hierarchies check box activated
Retail > Customer A
A parent and child within the Customer dimension
In a column header
Customer > Country
A mapping from the Customer dimension to the Country dimension
For example, a query can return the following result:
date
Revenue
Customer
Customer > Country
2026-01-01
100
Retail > Customer A
Germany
2026-01-01
200
Retail > Customer B
France
2026-01-01
300
Wholesale > Customer C
Germany
When the Import dimension hierarchies check box is activated, the Customer dimension contains Retail with Customer A and Customer B beneath it, and Wholesale with Customer C beneath it. xP&A assigns the revenue values to the customer items. The Customer > Country column maps Customer A to Germany, Customer B to France, and Customer C to Germany. The automatically created parent items Retail and Wholesale do not receive these customer-to-country mappings.
Refreshing a hierarchy: xP&A identifies each imported item by its full path. When you refresh the data source and a path is unchanged, the item remains the same. If a path changes, for example from Retail > Customer A to Wholesale > Customer A, xP&A creates a new linked item at the new path and detaches the old item from the data source. xP&A does not move existing manual inputs on the old item to the new item.
Limits and input quality: Automatically created parent items count toward the dimension item limit. Use named items at every hierarchy level. xP&A skips empty segments in malformed paths. If a value contains no named segments, xP&A leaves the value unassigned and the import reports a warning.
Hierarchy levels within one dimension are different from chained mappings between dimensions. Activating the Import dimension hierarchies check box does not remove the limitations for querying linked dimensions (see Limitations and Workarounds for Querying Linked Dimensions in xP&A).
When working with queries, you can only create one level of linked dimensions (mappings) per query. This means you can establish multiple direct relationships from a single source dimension, but you cannot create chained relationships within the same query.
Allowed in one query:
A → B
A → C
A → D
Not allowed in one query:
A → B and B → C simultaneously
Workaround Solution
To handle multi-level relationships, you need to create two separate queries:
Query 1: Define the initial mapping relationship
Query 2: Define the secondary mapping relationship using a fictional value