Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Insert excerpt
_Banners
_Banners
nameanalysis
nopaneltrue

Introduction

Enriching data is at the heart of analysis modelling from adding additional data and extrapolating information to performing complex calculations and deduplication, PhixFlow covers it all. In this page we will highlight some of the key areas of enrichment, provide examples, and list the links to additional useful enrichment resources.

PhixScript Functions

PhixScript is the language of PhixFlow and it can be used anywhere that supports expressions, such as attributes on a table and in filters.

There 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:

  1. Comments can be added to a single line using // or to a section using /* */.
  2. if: used where you need to evaluate a simple condition before processing an expression.
    1. Syntax: if(condition, trueExpression, falseExpression).
  3. switch used where there are multiple conditions to evaluate and depending on the outcome : evaluates a set of conditions in turn, and returns the associated result for the first match.

    1. Code Block
      switch(
      	[condition1, result1],
      	[condition2, result2],
      	[conditionN, resultN],
      	defaultResult
      )


  4. forEach
  5. listToString
  6. contains
  7. listContains
  8. replaceAll
  9. dateDiff
  10. dateAdd
  11. now and today
  12. ifNull and _NULL
  13. substring
  14. stringLength
  15. trim
  16. toString
  17. toDate


Error Handling

Debug

error


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
)

Variables

make reference to variable.

Lookup Information

Lookups can be performed using three different techniques, the method selected depends on your requirements.

Lookup Function with Filtering

Scenario

Lookup information from a separate table and pass filtering information dynamically to return only selected records. 

Example

You need to retrieve all invoices for a specific date range that have not been sent.

Solution

Show one with _out.someting - Typically running a model

Show one with $variable - If your using an action and dynamically setting the $variable.

Lookup Function 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 lookups.

Example

You have a product code on an invoice and want to return the name of the product to display. There are a finite amount of products.

Solution



Merges

Matching

Simple exact matches and make reference to addition al functions for more advanced matching see Lev Distance etc.

Task Plan