Skip to main content Skip to complementary content

CalcDim - chart function

When used in a dimension expression, CalcDim() overrides the engine's automatic interpretation of how to internally handle the expression. Specifically, the function prevents a new internal field from being created in the data model. Instead, selections made in the app are treated as selections in applicable fields from the original data model.

This function cannot be used in the load script. Additionally, a best practice for system performance is to load the fields that are used in the calculated dimension as logical fields via the load script when possible. CalcDim() offers a way to control engine behavior in scenarios where loading the calculated field from the script is not possible.

In Qlik Sense, the dimension expression is by default realized as a field-on-the-fly—that is, as an actual field, apparent in the current selection bar, built on demand. Selections are applied and inferred to this field, similar to any logical field from the script.

An expression wrapped in CalcDim() will behave the same way as all calculated dimension expressions work in QlikView, which is an ad-hoc mapping of the calculated values to the underlying source field values. All field-on-the-fly calculations can be transferred into calculated dimensions using the CalcDim() function since the calculated dimension has to meet fewer requirements based on the data model than the corresponding field-on-the-fly calculation. This transformation may be desirable in order to guarantee a similar behavior for all calculated dimensions where the data model may prevent the use of a field-on-the-fly calculation in some cases, but not in others.

Syntax:  

CalcDim(expr)

Return data type: dual

Arguments
Argument Description
expr

An expression being used as a dimension, or as a segment within a dimension expression.

When to use it

CalcDim() is useful when you need more control over how the Qlik engine handles the fields you invoke in a dimension expression.

By default, Qlik Sense automatically decides whether to create and reference internal fields in the data model when you use a custom dimension expression. Qlik Sense creates and uses these internal fields whenever it is possible. When not possible, the expression is handled with reference to the existing data model fields on which it relies.

Depending on your use case, this automatic processing might not always be desirable. For example, if you are using a variable in a dimension expression, the automatic creation of new fields can become problematic. In this case, use CalcDim() to force the expression to be handled without this method.

Here are some common use cases:

  • You have migrated QlikView content into Qlik Sense and you want to preserve the QlikView processing method for calculated dimensions.

  • You want to simplify the selection behavior in your app. For example, you prefer to show field selections as selections in fields from the original data model, rather than selections in new fields.

  • Your use case requires an ad-hoc expression for consistency and performance. For example, if your dimension expression contains user-controllable dynamic visualization parameters, such as controllable formatting, cut-off values, or periods.

Function examples
Example Result
=CalcDim(if(Year < 2023, 'Older', Year))

Making a selection in a visualization that uses this dimension will be processed and displayed as a selection in the associated Year field value from the data model.

Conversely, let's say you do not wrap the expression in CalcDim(). In this case, it would look like this:

=if(Year < 2023, 'Older', Year)

Making a selection in the above expression would be processed and displayed as a selection in the internal field =if(Year < 2023, 'Older', Year), which is not in the data model.

Example 1 – Simple comparison

Example 2 – Practical use case to modify the default behavior

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!