Sum non-repeating option buttons with condition - InfoPath Dev
in

InfoPath Dev

Sum non-repeating option buttons with condition

Last post 03-24-2010 05:25 AM by Jimmy. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 03-24-2010 03:54 AM

    Sum non-repeating option buttons with condition

    Hi, I have what I would expect to be a very simple task to do, but am not winning at all or finding any solution elsewhere. I think I might be missing something very vital :P

    I have a simple form that has 10 Option Controls, each with 4 choices. This is set up like a multiple choice test so that for each Option control there is one correct answer.This is not set up repeating, as all 10 questions are on on page (clients choice).

    For each of the Option Controls I have made the correct answer = 1 and the other three 2,3,4. The type is Whole Number (integer), and the default value is set to 0.

    At the bottom of the questions I have a button which goes back to the intro page that displays the results. I have a field called 'Score' to get the total value of the Option buttons. I set a rule on the button that first resets the Score to 0, then updates it to add all the option button values together, BUT ONLY WHEN Option Button = 1.

    The expression I use for this is the following:

    my:Math1[. = 1] + my:Math2[. = 1] + my:Math3[. = 1] + my:Math4[. = 1]

    Unfortunately, if one of the options is NOT 1 then Score shows NaN.

    How do I achieve this so that I can add the scores for a sheet each time only when the answer is correct. Is there something missing in my f(x)? How do I do an 'IF' opposed to a filter that returns no value and gives an Nan?

  • 03-24-2010 04:21 AM In reply to

    Re: Sum non-repeating option buttons with condition

    Please try this formula:

    count((my:Math1 | my:Math2 | my:Math3 | my:Math4)[. = 1])

     

    As I'm sure you're aware, using a repeating field offers several benefits over this approach.  Is there any particular reason why your client wants the data source like this?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-24-2010 04:45 AM In reply to

    Re: Sum non-repeating option buttons with condition

    Thanks Jimmy, that works great! What does the '|' (pipe) symbol actually mean please, so I can better understand your expression?

    Actually, the client doesn't care about the data source, just the visible layout. I am assuming that I cannot get the layout to be on one view in a repeating field. Is this incorrect? It would be great if I could have the 10 questions on one view as 10 seperate fields but repeating... um, I'm not sure if that makes sense?

    Welcome all suggestions.

    PS: How do I insert a pic here, mine always come up with the red cross :P

  • 03-24-2010 05:25 AM In reply to

    Re: Sum non-repeating option buttons with condition

     http://www.w3.org/TR/xpath/#node-sets

     The pipe symbol produces the union of two node-sets.  You can chain these together on individual nodes to produce a single node-set from an assortment of unrelated nodes.

    If your form doesn't need to be browser-enabled, it should be possible to show different parts of a repeating node set by using conditional formatting (filtering) on the repeating section or repeating table control, but it may indeed not be worth the effort.

     You can insert an image from the internet using the icon on the toolbar that looks like a tree.  You can attach your own image by using the feature on the Options tab.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.