Add script calculations

The R and Python script languages are supported in Data Preparation.

When adding a script for a calculation, you can choose how to process the data in a script: vector or scalar.

  • You have an AI connection in the AI connections pane. For details, see Add AI connections.
  • You are creating a dataset.
  1. Depending on the page, do one of the following:

    • On Step 2 – Refine, select a data source, and then click Calculations.

    • On Step 3 – Join and preview, next to the data source name, click More options and then Calculations.

    The Calculationsdialog appears.

  2. In the Calculation name field, type a name for the calculation.
  3. In the drop-down list on the right, select the calculation data role (dimension, measure, date).

  4. In the Type calculation field, depending on the script type that you need, type script or scalar, and then click the Edit script button that appears.

    Alternatively, you can drag the SCRIPT or SCALAR functions that are included in the Data Science group.

  5. In the Script / Scalar pane that appears, do the following:

    1. Select the following settings:

      • Connector – DataClaritPy (built-in) or any other defined AI connector.
      • Language – Python or R.
      • Calculation – Specify how to calculate the data in the script:
        • Vector – Multiple rows are sent as a table in one request to the server for processing.
        • Scalar – Each row is sent and calculated in the server separately, one by one.
      • Result – The format of the returned value: double, string, or integer.

    2. In the Type script field, enter your script.

      Note: You can use only scripts that return data in one column.

    3. Click within the Click to add columns field, and select the column that you want to use as the first argument for the script. Repeat this step for each argument of the script.

    4. If you need to change the default aggregation, click a column name, and select a new aggregation.

    5. Click Apply.

      The script is added to the calculation pane.

  6. Click Save.

    The calculation column is added to the dataset.