XPath for summing qty for unique rows in repeating - InfoPath Dev
in

InfoPath Dev

XPath for summing qty for unique rows in repeating

Last post 10-19-2005 08:46 AM by pmbarnes. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 10-18-2005 05:17 PM

    XPath for summing qty for unique rows in repeating

    I have an inventory form that has multiple sections in which the same part # can be entered. (Think of each section like a grouping of parts, and parts can be duplicated between sections.) After all the data is entered I want to be able to display one repeating table that has one row for each unique part #. I want this row to have the total quantity for this part # across all sections. So if a user entered part # 125P-4 in three sections, with quantities of 2, 5, and 1, respectively, I want the summary inventory table to show only one row for part 125P-4 with a total qty of 8.

    Each part is represented by a repeating group called Item, which has, among other child elements, a PartNum element.

    I figured out the XPath expression to filter the repeating table bound to the Item group so that only unique part numbers appear:

    PartNum = not(my:PartNum = preceding::my:PartNum)

    I've been trying for hours to figure out the XPath to show the total qty for each PartNum. I added another child element called ItemTotalQty to the Item group element. For the default value I'm able to get as far as displaying the total quantity across all sections for a hardcoded PartNum, e.g. the following yields 8 using my above scenario:

    sum(/descendant-or-self::node()/my:Item[my:PartNum =
    "125P-4"]/my:ItemQty)

    But it shows "8" for each row in the repeating table. So what I need to do is swap out the hardcoded part # "125P-4" with the unique PartNum in each row of the filtered repeating table. In other words, I want to say: "gimme the sum of all the Item\ItemQty elements where the Item\PartNum element = each unique PartNum entered by the user into the form." Is this even possible? How would I do this?
  • 10-18-2005 11:17 PM In reply to

    Re: XPath for summing qty for unique rows in repeating

    Hi, have you tried to play with current() ?

    Regards,

    Franck Dauché
  • 10-19-2005 08:46 AM In reply to

    Re: XPath for summing qty for unique rows in repeating

    Thank you for the tip, Frank. That did it! I'm pretty new to XPath and it has my head spinning at times, but I got this to work with your suggestion. The final expression is:

    sum(/descendant-or-self::node()/my:Item[my:PartNum = current()/../my:PartNum]/my:ItemQty)

    So I substituted "current()/../my:PartNum" for the hardcoded PartNum value.
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.