Scenario
In an Excel table, I can add a new column that contains a formula to calculate values using data on other columns. How do I do this in PhixFlow.
Concepts
In a model, data is loaded into streams from external sources, such as files and databases. Usually we then want to calculate additional values and use them in subsequent streams.
Solution
- Create the stream and connect it to its data source or input stream.
- Run analysis to check that the input data is loading into the stream correctly.
At this point you can optionally run rollback to clear the data; see Rollback 13 Rolling back Streams - Now add the new attributes to the stream. These are like the Excel columns. Remember to set the correct data Type and Length.
Make sure the order Order number is greater than the attributes loaded via the input pipe.
PhixFlow processes attributes in the order they are listed in the stream. If you want to use a value from another attribute it must appear earlier in the attribute list.
- In the Expression field, write the expression to calculate the value. This is the equivalent of the Excel formula. Specify the value to use in the calculation with
_out.<name>
For example, to set the attribute have a value that is 75% of the value in an earlier attribute, write the expression:_out.<name> /0.75
For information about:
- rolling back streams, see training module 13 Rolling back Streams and Rollback
- expressions, see Scripting and Scripting Basics
- Context Parameter
$-variables
To use the value of a context parameter
Can be useful in a lookup
Context parameters
Which country
Which Date
Ref _context.CountryCode - relates to the parameter
Calculation in expression to give a $ variable