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 PhixFlow analysis model, data is loaded into streams from external sources, such as files and databases. Usually we want to calculate additional values and use them in subsequent streams. Key concepts to be aware of:
- In PhixFlow, you use an expression to run calculations on data in order to generate different data from it.
- The expression is in an attribute, which is like a column header in Excel.
- When you run the analysis model, PhixFlow runs the calculation on every record, adding the data to each cell in the attribute's column.
- PhixFlow processes attributes in the order they are listed in the stream. If you want to use a value from an attribute, it must appear earlier in the attribute list in the stream.
Solution
- Create the stream and connect it to its data source or input stream.
- Run analysis to check that the data is loading into the stream correctly.
At this point you can optionally run rollback to clear the data. - Now add the new attributes to the stream. This is the same as adding a new column to an Excel table. Remember to set the correct data Type and Length.
Make sure the Order number is greater than the attributes you want to use in the calculation.
- In the Expression field, write the expression to calculate the value. This is the equivalent of the Excel formula. To tell PhixFlow to use values from another attribute, specify its name using:
_out.<name>
Example
A stream contains an attribute called GrossValue
. A new attribute for the net value should be 75% of the gross.
Create the attribute NetValue
and in the expression, enter: _out.GrossValue * 0.75
Tip |
---|
Another way to pass values between attributes and streams in a stream is to write an expression that calculates a $-variable. These are most useful when the value you want depends on context. This can be the case when looking-up data or triggering actions. |
See also
- rolling back streams: training module 13 Rolling back Streams and Rollback
- expressions and $-variables: Using Variables and Expression Basics
- values that depend on context: Context Parameter