Python Analysis


The Python Analysis transform lets you write scripts using the Python programming language to perform analysis on data. To learn more about the Python language, see

1. Setup

Before you can use the Python Analysis transform in Dundas BI, the Python programming environment must be installed on the server.

See Install Python for more details.

2. Input

The Python Analysis transform requires one or more input transforms (each of which may produce multiple columns of data).

For example, the input could be a SQL Select transform that reads data from the AdventureWorks table, [Sales].[SalesOrderDetail].

Input table
Input table

3. Add the transform

To add this transform to an existing data cube, first select the connection link between two connected transforms.

Go to the toolbar, click Insert Other, and then select Python Analysis.

Select connection link and insert the transform
Select connection link and insert the transform

The Python Analysis transform is inserted between the two transforms and appears red because it needs further configuration.

The Python Language Analysis transform is inserted
The Python Language Analysis transform is inserted

4. Configure the transform

Double-click the Python Analysis transform (You can also select the Configure option from the context menu or the toolbar).

In the configuration dialog for the transform, the objective is to decide which input column(s) you want to analyze or apply processing to, and then enter a script that performs this analysis or processing on the input data.

For example, suppose you want to calculate the total sum of the OrderQty column from the input transform, and send this sum as the output.

To begin, click Define element placeholders in the configuration dialog. Click Add placeholder. In the Identifier text box, enter a variable name (for example, qty) for the input column which you will use in the Python script. Use the dropdown to select the corresponding input column (for example, OrderQty).

Define an element placeholder for the OrderQty input column
Define an element placeholder for the OrderQty input column

You can now write a Python script that references the qty variable by enclosing it between dollar sign characters. For example:

return sum($qty$)

This script calculates the sum of the OrderQty input column and returns the result as the output.

Python script to calculate sum of the OrderQty input column
Python script to calculate sum of the OrderQty input column

Click Edit script to open the Script Editor window and edit the same script. This is useful if you're working on a longer Python script because it offers undo/redo, go to line number, and other functionality.

5. Output

The output of the Python Analysis transform depends on the Python script it is configured with. It can be a single value, a column of values, or multiple columns.

6. Example Python script

The following example uses the polyfit function to find the least squares polynomial fit for the input columns.

6.1. Setup

This particular example relies on the NumPy package in Python and some input values:

  • To install the NumPy package, open command prompt as an administrator, navigate to the Python scripts folder (for example, C:\Program Files\Python36\Scripts), and type:
    pip install numpy
  • On a new data cube, create a Data Input transform with the following two columns using the Double data type:
    • X: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]
    • Y: [0.0, 0.8, 0.9, 0.1, -0.8, -1.0]

    Sample data input values
    Sample data input values

6.2. Define placeholders

Add the Python Analysis transform and double-click to configure it. Click Define element placeholders, and then define the two placeholders X and Y.

Define the two placeholders
Define the two placeholders

6.3. Create the script

To fit the input values to a third-power polynomial, add the following script to the Python Analysis transform:

import numpy as np

Z = np.polyfit($X$, $Y$, 3)
P = np.poly1d(Z)

return ($X$, $Y$, P($X$))

The generated output is in the form of a table consisting of the X and Y inputs, as well as the polynomial values for each entry.

Python polynomial output
Python polynomial output

6.4. Adjust the column names and the output

Configure the transform again and click Edit output elements.

Edit each output element and provide a relevant column name.

Edit output elements
Edit output elements

Select the Process Result transform and edit the X measure. Click Switch to hierarchy and then select Count from the supported aggregators.

Switch the X measure to be a hierarchy
Switch the X measure to be a hierarchy

6.5. View the result

On a new dashboard, drag all three elements from the data cube and Re-Visualize as a Curved Line.

View the result
View the result

7. See also


Dundas Data Visualization, Inc.
500-250 Ferrand Drive
Toronto, ON, Canada
M3C 3G8

North America: 1.800.463.1492
International: 1.416.467.5100

Dundas Support Hours: 7am-6pm, ET, Mon-Fri