Hello
How to calculate many table rows include the first results?
For example:
field A :amount
Field B : Price
Field C : result Total=[field A :amount]*[Field B : Price]
Field D: Annual payment=[Field C : result Total] * 12
Field E :Final Cost after Discount 10 % =[Field D]-([Field D]*100/10)

I try Computed field, table aggregation plus ,views math exp but no good results
Best Regards

Comments

boudo20 created an issue. See original summary.

orkutmuratyilmaz’s picture

Version: 8.x-1.0-alpha1 » 2.x-dev
Category: Feature request » Support request
Status: Active » Closed (works as designed)
Issue tags: -

This is really a support request rather than a feature request, so answering here and closing.

You do not need one expression field per step. The Expression (integer), Expression (decimal) and Expression (float) field types accept several statements separated by ;, variables carry across them, and the value of the last statement becomes the field value. So your whole chain fits in a single field:

total = [node:field_amount] * [node:field_price]; annual = total * 12; annual - (annual * 0.10)

Chaining across separate expression fields, where field D reads the value of field C, is not reliable. Each expression field evaluates in its own preSave() and the order in which fields are processed on a single save is not something the module controls, so the field you reference may still hold its previous value. Keeping the whole calculation in one field avoids that entirely. If you do want the intermediate values visible as their own fields, enable the option to evaluate the expression when the field is rendered, which resolves tokens at display time instead of at save time.

Note also that your discount formula does not do what you intend. [field D] - ([field D] * 100 / 10) subtracts ten times the value. For a 10 percent discount use [field D] * 0.90 or [field D] - ([field D] * 10 / 100).

One limitation worth stating: this module evaluates tokens from the entity the field is attached to. If by "many table rows" you mean aggregating values across several entities, that is outside what this module does. Views with aggregation, or Computed Field with custom code, are the right tools for that.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.