Derived source

The derived source allows you to perform arbitrary operations using the data returned in columns from other sources.

For example, if you have a report with a column for gross revenue and a column for net revenue that are both pulled from the database, you could have a derived column to display the gross margin by performing the operation (net revenue / gross revenue * 100).

Column types

class blingalytics.sources.derived.Value(derive_func, **kwargs)

A column that derives its value from other columns in the row. In addition to the standard column options, this takes one positional argument: the function used to derive the value.

The function you provide will be passed one argument: the row, as pulled from other data sources but before the post_process step. The row is a dict with the column names as keys. Your function should return just the derived value for this column in the row. The function is often provided as a lambda, but more complex functions can be defined wherever you like.

Continuing the example from above:

derived.Value(lambda row: row['net'] / row['gross'] * Decimal('100.00'))

By default, the footer for this column performs the same operation over the appropriate footer columns. This is generally the footer you want for a derived column, as opposed to simply summing or averaging the values in the column. If one of the columns involved in the derive function does not return a footer, this will return a total.

Table Of Contents

Previous topic

Static source

Next topic

Merge source

This Page