2013-11-23

Use Case of Multiple Feature Attribute Support

Previous: Multiple Feature Attribute Support of the AttributeCreator in FME 2013 SP2

After that, I've come across some practical use cases:
Community > GroupBy functionality in ExpressionEvaluator
Community > pushing an attribute to variable or parameter then testing attributes against veraiable

Here, I'll give a simplified example for calculating cumulative total.
Assume every input feature has group identifier and a numeric value, like this.
_group | _value
1, 1
1, 2
1, 3
2, 4
2, 5
2, 6
2, 7
...

The goal is to append them the cumulative total of _value in each group.
_group | _value | _cumulative_total
1, 1, 1
1, 2, 3 (= 1 + 2)
1, 3, 6 (= 3 + 3)
2, 4, 4
2, 5, 9 (= 4 + 5)
2, 6, 15 (= 9 + 6)
2, 7, 22 (= 15 + 7)
...

That is, if the feature is the first one of a group, _cumulative_total should be equal to its own _value; otherwise should be sum of _cumulative_total of the previous feature and its own _value.

The AttributeCreator (FME 2013 SP2+) can do that easily.

There are two AttributeCreators in this workflow.
The 1st AttributeCreator creates an attribute named _cumulative_total, and initialize it by _value.
The 2nd AttributeCreator updates _cumulative_total using the "Multiple Feature Attribute Support" option and the "Conditional Value" setting.
If _group of the current feature is equal to _group of the previous feature, it sums _cumulative_total of the previous feature and _value of the current feature, then assign the result into _cumulative_total.
If not, it does nothing. i.e. not update _cumulative_total (= _value).

I think this will be a typical use case of the "Multiple Feature Attribute Support" option.

1 comment: