Expression Boxes

S

SeanM

I have a repeating table to compute mileage expense. One text box contains
miles, the other the rate.I use an expression box to multiply the two boxes
for a total. I need there to be a subtotal for this table so that I can add
it to the other table subtotals. How do I total up those boxes (expression)
that are within the repeating table?
 
A

Andrew Watt [MVP - InfoPath]

I have a repeating table to compute mileage expense. One text box contains
miles, the other the rate.I use an expression box to multiply the two boxes
for a total. I need there to be a subtotal for this table so that I can add
it to the other table subtotals. How do I total up those boxes (expression)
that are within the repeating table?

If you want to avoid code then you probably need to convert the
expression boxes inside the repeating table to text boxes. That
enables you to access the value in that text box as part of a grand
total in an expression box.

Use the fx button to put a formula in the text box as it's default
value. Probably make the text boxes read only.

Then you can use sum() as I previously described, since the values in
the text box(es) are accessible to XPath.

The more that you have one result feeding into another the more text
boxes you need or you need to use code to do the necessary
calculations. XPath isn't particularly mathematically powerful.
Combined with the way the tree of nodes in InfoPath works it pushes
you, for anything but pretty simple stuff, to coding the answer.

Andrew Watt
MVP - InfoPath
 
W

wjasonstrutz

I've found a way to do this without code. It requires some xpath knowledge,
and it's really slow (unless it's the amount of data that makes my form
chug), but it works.

I have a repeating table of items (purchase_request_item), each line of
which has a quantity and unit_price (those are the xml attribute names). I
use an expression box to multiply these, and get a total. At the end of the
table, I have an expresion box in the footer that calculates the grand total.

The function for that expression box is:
sum(eval(purchase_request_item, "@quantity * @unit_price"))

eval() returns a nodeset containing the result of the expression given in
the second argument applied to the nodeset given in the first argument.
Then, sum takes that result nodeset and computes the total.

HTH,
jason.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top