By the end of this chapter you will be able to:
You will also learn how to limit a pipe to read a maximum number of data records.
In this exercise you will select the latest (most recent) sales record for each customer, from the set of combined updates you created in the previous exercise.
Create an aggregate stream
- In the model toolbar, find Error rendering macro 'excerpt-include' : No link could be created for '_add_stream_aggregate'.and drag it into the model.
- Set the stream Name to
Latest Package Update
. - Add a pipe from
Combined Updates
:- Hover your mouse pointer over the stream
Combined Updates.
- In the context toolbar, click Error rendering macro 'excerpt-include' : No link could be created for '_add_pipe'..
- Click the stream
Latest Package Update
to connect the pipe.
- Hover your mouse pointer over the stream
- Drag all attributes from
Combined Updates
toLatest Package Update
.- Hover your mouse pointer over the stream
Combined Updates
again. - In the context toolbar, click Error rendering macro 'excerpt-include' : No link could be created for '_stream_attributes'.. Phixflow lists the data attributes (column titles) for this stream.
- Select all the attributes and drag them into the
Latest Package Update
settings → Aggregate Attributes section. - Click OK to save and close the
Latest Package Updates
settings. - Close the attributes pop-up window.
- Hover your mouse pointer over the stream
- In the
Channel Package
model toolbar, click Save.
When you next run this model, the Latest Package Updates
stream will pull in the all the data from the Combined Updates
stream.
Group and order data on an input pipe
At the moment the data will come into the aggregate stream in any order. You are going to sort the data as it comes through the input pipe to the aggregate stream.
- Group the data, so that all the records with the same
Customer Ref number
are adjacent in the table. - Sort the data by date, newest to oldest, using
Sales Date
. This means that the first record delivered by the input pipe, for each Customer Ref, is the most recent for that customer.
- Double click on the pipe from
Combined Updates
- Go to the Sort/Group section
- Press - Show Stream Attributes
- Drag in
CustomerRef
- Drag in
SalesDate
- You will leave
CustomerRef
as a grouping attribute - You will update
SalesDate
to be a ordering attribute:- Double click on
SalesDate
in the Sort/Group attributes list - Set the Sort Direction to descending: Z-A
- Untick the Group flag
- Press
- Double click on
- Set Maximum Number of Records per Group to: 1
- Press - Show Stream Attributes
This setting means that for each key value – in this case for each value of CustomerRef
– only the first record will be returned; since you have also ordered by SalesDate
descending, this will be the latest (most recent) record for each CustomerRef
- Press in the main pipe configuration form to save your changes
Test your new Stream
- Run analysis on your new stream
- Make sure that for all customers the most recent sales update has been selected