Conditional counting - InfoPath Dev
in

InfoPath Dev

Conditional counting

Last post 11-27-2007 07:52 AM by Clay Fox. 12 replies.
Page 1 of 1 (13 items)
Sort Posts: Previous Next
  • 11-10-2007 01:58 PM

    Conditional counting

    Hi all,

    I'm probably overcomplicating this but I am trying to create a form where I can add hardware, software and users and then set configurations in orders. What I want to do is count the number of users in each order for each piece of software and hardware if it is selected in that order.

    Each hardware/software entry exists in a repeating group and consists of a unique ID (automatically assigned), a name and a quantity. "Order" is also a repeating group with three repeating fields inside for Hardware ID, Software ID and User ID which are selected in drop down lists populated by the hardware, software and user groups respectively.

    I have tried a filter but it doesn't appear to work at all: count(../../my:Order/my:UID[../my:HWID = ../../my:Hardware/my:HID])

    HWID is the repeating entity in Order that should be equivalent to HID in Hardware.

    I'm pulling my hair out on this one. Can anyone help me?

    Thanks,

    Ben

  • 11-12-2007 07:47 AM In reply to

    Ok Ben. I think I understand what you are trying to do here but correct me if I am wrong.

    After the orders are made you want to total each type of hardware and software etc.

    It has been a while since I did counts like this but I believe you want to count the repeating group my:Order, then put your filter on rather than UID or a child node.

    Let me know if that works.

  • 11-12-2007 08:15 AM In reply to

    Almost. I want to know how many users want the hardware/software rather than how many overall orders there are for them.

    I have a list of hardware, software and users uniquely identified. The user then compiles orders where a piece of hardware may be chosen. I want the quantity for that piece of hardware to reflect a sum of the user count in each order where that hardware has been chosen.

    I'm afraid I'm rather new to XPath and the original post represents the extent of my knowledge so far when it comes to filters. Although your method seems logical I don't know how to implement it. Would you have any suggestions? Ignoring software as it's the same in theory, here are the important fields:

    myFields > Hardware (Repeating group)
    myFields > Hardware > HID (Unique auto-generated number)
    myFields > Hardware > HQuantity (where I have been putting my filtered count)

    myFields > Order (Repeating group)
    myFields > Order > HWID (Repeating - references HID through drop-down list)
    myFields > Order > UID (Repeating - references unique myFields > Users > UNetID through drop-down list)

    (When I say reference I mean the drop down is populated by the Hardware and Users repeating node data respectively rather than an element reference - I just couldn't think of another way to phrase it).

    So in my best obfuscated English/Code attempt: for each HQuantity check each order to see if HID exists in HWID and if it does count the UID fields and add them to HQuaintity. I would be able to do it so easily in code! Can you see a viable way to do it through XPath?

    Thanks so much for your help already.

  • 11-12-2007 09:01 AM In reply to

    Ok

    The dropdowns should not matter for this function since we care about the final list of data Order.  I am assuming you have displayed this and this is correct, it is just a matter of filtering and calculating it.

    I think you would maybe have to use code since you have two data sets and need to loop through each one. If you were using a database this would be a bit easier. But essentially you want to step through your Hardware group and then loop through Orders with each step to total. 

    One thing that would make this much easier is if your data was organized different. Why dont you have one group? It does not seem you are gaining to much from having the seperation when they only have two fields each.

    OrderID, UserID, HWID, SWID, HQuantity, SQuantity

    Then it would be pretty easy to filter to get totals.

    Typiclaly you would have one Order Number with one UserID that would have multiple records for each HW or SW component they want to order then you would sub-total and total these per user or per order into a summary report.

    Well not sure if this helps you but the way it is setup is pretty complex. Maybe someone else has a trick or some insight.

  • 11-12-2007 09:03 AM In reply to

    Ok thinking some more...

    Typically you would build this total as the data was collected not afterwards.  So as the user was making their order you would be incrementing the totals for each HWID.  Have you looked at this?

  • 11-14-2007 07:52 AM In reply to

    I think I'm a bit confused over what you mean.

    Is there a way to use a conditional statement in square brackets such that the entry on a node can be changed individually rather than the whole lot?

    Everything I try seems to add numbers to every HQuantity at once, but I only want to add a count of users for a given order to the HQuantity when the corresponding HID is present.

    Try to think of "Users" more as recipients. There is one person ordering these configurations for a potentially large number of people so a list of hardware and software can be compiled into an order for a list of people and to add complication there can be a list of these orders for different configurations.

  • 11-14-2007 08:44 AM In reply to

    Ok, I'm trying to do this in JavaScript and I'm lost from the outset! I have used JS before but never in InfoPath. I know I will be able to pick this up myself if someone can just point me in the direction of a starter guide for node navigation and element value get/set.

     Please help!

  • 11-14-2007 09:29 AM In reply to

    There is a way to set a filter on a set field action but not in the InfoPath UI directly.  Greg has a post on here I have used before but the jist is that you set up the set field action as normal and then export the source files and modify it in the manifest and recompile it.

    I still would look at redesigning the data schema and reducing the complexity so that as the user entered the information it went into a single record or a nested record.  Then you can summarize and total the data in real-time and much easier.

    Maybe if you attached the form it would be easier to understand what exactly are the constraints.

  • 11-26-2007 04:20 AM In reply to

    Hi Clay,

    The file is attached. If you could have a look at it that would be brilliant. Do you have a link to Greg's post as well please?

    Thanks,

    Ben

  • 11-26-2007 09:59 AM In reply to

    OK Ben.

    I think the issue is that you have repeating fields within a repeating group.  There is no way to associate them together if everything is repeating.

    You need to remove the repeating fields under order.  I would have four fields OrderNum(which increments), HW, SW, User which are in your repeating Order group.  Then on the drop downs for each you can use your data already added above but then as the user makes selection you will get a row for each that has HWID, SWID, and UserID which matches together. At that point you can total or whatever.

    I do not see any data connections, at least not in InfoPath designer. What are you going to do with this data once it is collected? It will be tough to work with if it is sitting in indivdual forms.

  • 11-26-2007 10:11 AM In reply to

    Hi Clay,

    Fair point - I'll run that past the guys who want the form in the morning. Thanks so much for taking a look at it for me.

    It will be submitted to a SharePoint list and there are a few connections to pull in other bits and pieces of data from various places around our site but as they are not publicly accessible I stripped them out to save you any trouble looking at the form.

    Thanks again,

    Ben

  • 11-27-2007 03:18 AM In reply to

    I just had an idea... I don't know if it is possible but please tell me if you can see a way to make it work.

    The eval() function iterates through a node. I want to iterate through the Order node and count the users if there is a hardware item that matches mine (so I must also iterate through the HWID node). In my head, this would work with a nested eval in an eval as follows:

    sum(xdMath:Eval(../../my:Order, sum(xdMath:Eval(../../my:Order/my:HWID, contains(my:HWID, ../my:HID))) * count(my:UID)))

    At the moment I'm doing something wrong and it's giving me this error which I am about to Google - but am I at least getting close? Do you think a variation on this might work?

    This would multiply the user count by the number of times an item appears in an order. I'm sure I've made some glaring XPath mistakes but the more I use this the more I realise I'm a novice!

  • 11-27-2007 07:52 AM In reply to

    You should be able to do this with the Sum function and filters.  As long as you are outside of a control bound to the repeating group, sum or count will iterate and then you can use filters to limit which rows are counted. I do not think you need the eval's.

    So count(orderHW[orderhwid=hwid])  I am pretty sure you can get this to work. I will look at some forms I have done with analysis like this too.

Page 1 of 1 (13 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.