Insert excerpt | ||||||||
---|---|---|---|---|---|---|---|---|
|
Introduction
Enriching data is at the heart of analysis modelling from adding additional data and extrapolating , from looking up reference information to performing complex calculations and deduplication, PhixFlow covers it all. In this page we will highlight some of This page highlights the key areas of enrichment, provide providing examples, and list listing the links to additional useful enrichment resources.
PhixScript
FunctionsPhixScript is the language of PhixFlow and it can be used anywhere that supports expressions, such as attributes on a table and in filters.
Single Function PhixScript
This is used in attribute expressions and filters alike where a single function is called.
Code Block |
---|
// If ExamResult is greater than 95 then return "Distinction" else return "Pass"
if( in.ExamResult > 95, "Distinction", "Pass") |
Multiple Function PhixScript
PhixScripts containing multiple functions must be wrapped in a do(). do()
can also be used within a function such as in if
or switch
. For more information see do().
The value returned from the PhixScript is the final value output, therefore it is useful to add the desired output to the end of the script.
Note that variables declared in an attribute expression (variables are declared with a $ symbol with the data type being implied) will be accessible to subsequent attributes within the same table using the $variable name.
Code Block |
---|
do(
// calculate the miles per gallon.
$mpg = in.distance / in.gallonsUsed,
// if $mpg is over 65 set efficiency to Highly Efficient
if( $mpg > 65, $efficiency = "Highly Efficient",
// ELSE, set $efficiency to be null
$efficiency = _NULL
),
// Set the value returned by the PhixScript
$efficiency
) |
Excerpt | ||
---|---|---|
| ||
Common FunctionsThere are over 115 functions available and these are listed in Functions |
, but to help you get started here is a short list of commonly used functions: |
|
|
|
|
Debugging
|
|
|
|
Writing PhixScript
Where a PhixScript is more than a single function, it must be wrapped in a do()
function. do()
can also be used within functions where you need to carryout multiple functions such as in if
or switch
.
Single Function PhixScript
This is used in attribute expressions and filters alike where a single function is called.
Code Block |
---|
// If ExamResult is greater than 95 then return "Distinction" else return "Pass"
if( in.ExamResult > 95, "Distinction", "Pass") |
Multiple Function PhixScript
PhixScripts containing multiple functions must be wrapped in a do(). For more information see do().
The value returned from the PhixScript is the final value output, therefore it is useful to add the desired output to the end of the script.
Note that variables declared in an attribute expression (variables are declared with a $ symbol with the data type being implied) will be accessible to subsequent attributes within the same table by using the $variable name.
Code Block |
---|
do(
// calculate the miles per gallon.
$mpg = in.distance / in.gallonsUsed,
// if $mpg is over 65 set efficiency to Highly Efficient
if( $mpg > 65, $efficiency = "Highly Efficient",
// ELSE, set $efficiency to be null
$efficiency = _NULL
),
// Set the value returned by the PhixScript
$efficiency
)VariablesPhixFlow contains a number of Internal Variables available to PhixScript used for obtaining system and user information. Variables in PhixFlow are declared using a |
$variable. The data type is implied by the first value entered, for example:
|
|
|
|
Clearing Data
See Rollback Recordsets, for details on removing all or selected records from your Table.
Lookup Information
Lookups can be performed using three different techniques, the method selected depends on your requirements and these are described below:
Lookup Function
See lookup for full details on the configuration.
The lookup function allows the user to pass variables to a lookup pipe. For example up, the pipe configuration for passing a variable would look like the following with the Type set to Lookup
:
To retrieve the Region data from this lookup pipe, for example in an attribute expression, this would look like the following: lookup(in, $num = _out.MyValue).Region
. For more information see Filtering and Sorting Data.
Lookup with Filtering
Scenario
Lookup information from a separate table and pass filtering filtered information to return only selected records.
Example
You need to retrieve the region Region for a particular businesses. We will use the City to perform a lookup that will return a region.business using the City from its address.
Solution
- You should have a two tables:
- one with your data that will perform the lookup e.g. Business Data.
- a second table with the data being looked up e.g. Region.
- Drag a pipe from the data to be looked up, to the data performing the lookup. In our case from Region to the Business Data.
- In the properties window that opens for the pipe:
- Set the name Name to be something short but meaningful.
- Set the Type to be
lookup
. - In the filter section we will tell the lookup pipe we want to filter
Region
byCity
using the processed City city value from our Business Data.
To use the processed version of city we use _out.City. - We are passing data and not just a string value, so click to tell PhixFlow we are passing an expression.
- To use the processed version of City we use _out.City. The filter as followsThe filter will look like this:
Region
.- In the expression type
pipe.attribute
, in our case this will bergn.Region
. - Save your changes.
Insert excerpt | ||||||
---|---|---|---|---|---|---|
|
Lookup with Order/Index
Scenario
This is a highly efficient method for performing a lookup against a small set of records. This kind of lookup will automatically cache a set amount of records, 3000 by default, in memory allowing for faster lookupsretrieval.
Example
You have a product Product ID on an invoice Invoice and want to return the name of the product to display. There are a finite amount of products so it is efficient to cache them. The setup will look similar to:
Solution
MergesMerging Data
See Merging Tables for full details. This technique can also be used to deduplicate.
Matching
Simple exact matches and make reference to addition al functions for more advanced matching see Lev Distance etc.
Task PlanRecords
See Compare or Match Data for deduplicating and matching records.