Skip to main content

Using object variables

You can store the metadata of a particular metric or attribute in a an object variable. You can then reference that object variable in View components such as input dropdowns, text boxes, and component fields and reuse it in multiple Studio assets. You can also reuse the object's properties in the PQL editor. Using variables ensures consistency across dashboards and means if the business logic or calculations change, you only need to update each object variable in one place.

The object variable schema follows JSON syntax and is generated when a default value or a current value is set. You need to define key-value pairs for the object variable. For example:

{
"key1": "String",
"key2":123,
"key3":true
}

This is then added to the Default Value field when creating or editing the object variable:

A screenshot showing an example of object variables.

Object variables are referenced in the following ways:

  • PQL editor:

    ${object_one.value}
  • Component fields:

    ${object_one.name}

Object variables are often stored in JSON. The JSON syntax typically looks like this:

{
  "variables": [
    {
      "name": "VAR_PLANT",
      "type": "OBJECT",
      "objectType": "COLUMN",
      "columnId": "Plant",
      "dataType": "STRING",
      "multiple": false,
      "defaultValue": null,
      "values": [
        { "key": "1000", "label": "Berlin" },
        { "key": "2000", "label": "Munich" },
        { "key": "3000", "label": "Hamburg" }
      ]
    }
  ]
}

This is created using the following fields:

  • Name: The variable’s internal name (VAR_PLANT).

  • Type: "OBJECT" for object variables.

  • objectType: Usually "COLUMN" (linked to a data model column).

  • columnID: The actual column in the Data Model.

  • datatype: "STRING", "INTEGER", "DATE", etc.

  • multiple: True if multi-select is allowed.

  • defaultValue: Optional starting value.

  • values: An array of key-label pairs, representing the selectable items for the dropdown. The values array is structured as key-label pairs:

    { "key": "1000", "label": "Berlin" }
    • key: The actual value stored in the variable (used in PQL queries).

    • label: The human-readable name shown in the View component for users.

You can use object variables as input dropdowns in Views. The column values from your Data Model display in the input dropdown, allowing users to select input dropdown values dynamically, making your Views interactive and reusable without hardcoding filters. In this example,

Suppose you have a dashboard where users should filter by Plant:

  1. Create an object variable VAR_PLANT linked to the column Plant.

  2. Add an input dropdown that displays all distinct plants from the Data Model.

    ${object_one.name}
  3. When a user selects "Plant = 1000", the variable VAR_PLANT stores 1000.

  4. You can now use VAR_PLANT in your PQL filters, e.g.:

    FILTER "Plant" = ${VAR_PLANT}

In this example, different time attribute values are added to an Input dropdown component and used as dynamic inputs to a chart component. When the Input dropdown is changed, the chart automatically updates.

  1. In a View, add an Input dropdown component.

  2. In the PQL editor, add date attributes as manual inputs to the Input dropdown component. Here, we add EVENTTIME and round the time dimension to MONTH:

    ROUND_MONTH("ACTIVITY_TABLE". "EVENTTIME")
  3. Add additional manual inputs to the Input dropdown component for time dimensions QUARTER and YEAR:

    ROUND_QUARTER("ACTIVITY_TABLE". "EVENTTIME")
    ROUND_YEAR("ACTIVITY_TABLE". "EVENTTIME")
  4. In the View, select Settings > Variables for the Input dropdown component and create a variable objvar1 for the object type:

    Screenshot showing the New Variable modal with the fields completed for a variable named objvar1.

    The date dimensions are added as options in the Input dropdown component:

    Screenshot showing the input dropdown with the month, quarter and year options
  5. Add a Chart component to the View.

  6. Link the object variable to the Chart component by adding the object variable as a chart dimension in the PQL editor:

    ${objvar1.pql}

    Tip

    You can also customize the column settings here so the name and format display as required in the chart. Using the variable object type metadata in the chart title also ensures the chart title changes when the dimensions are switched in the chart.

  7. Use the Input dropdown component options to change the chart dimensions and data displayed. Here Quarter has been selected in the Input dropdown component and the chart displays the data for Quarter:

    A View showing the input dropdown with a value of quarter and the chart displaying the values for quarter.

Related topics