Number function logic - InfoPath Dev
in

InfoPath Dev

Number function logic

Last post 03-16-2012 08:07 AM by rdrnnr. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 03-15-2012 01:04 PM

    Number function logic

    I now have gray hair! ha

    I've been trying to create a checklist to conduct inspections.  I need to come up with a way to add all the number of "discrepancy" and "findings" (chosen from a drop down list) into a final overall score.  I have each of these "values" to read as "discrepancy" and "findings" in their drop down boxes.  In my "score" control, I have the following under function:

    number(resp1[. = "Discrepancy" or . = "Finding"] = 1) + number(resp2[. = "Discrepancy" or . = "Finding"] = 1) + number(resp3[. = "Discrepancy" or . = "Finding"] = 1) + number(resp4[. = "Discrepancy" or . = "Finding"] = 1) / 4

    so each time either "discrepancy" or "finding" is clicked, it should count as one and the final total be divided by the number of questions.  The score box is set up for a double decimal, percentage but regardless of what is checked on the drop down boxes, a zero displays in the score box.

    What am I missing?  Please help! 

    Thank you in advance.

  • 03-15-2012 01:35 PM In reply to

    The expression resp1[. = "Discrepancy" or . = "Finding"] = 1 will evaluate to 1 if resp1 is equal to 1 and 0 if resp1 is equal to 0, but since resp1 will never have the value "1", this will always evaluate to 0.

     How about this expression:

    count((resp1 | resp2 | resp3 | resp4)[. = 'Discrepancy' or . = 'Finding']) / 4

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-15-2012 02:11 PM In reply to

    I tried your expression and came back with an error:  Node-test expected.   I tried substituting "sum" and came back with same error

    doesn't resp = 1 because I'm telling it to after the ] ? 

     

  • 03-16-2012 07:25 AM In reply to

    No, resp will only equal the value it has.  You can't assign it a new one mid-formula.  This would work for obtaining a 1 when resp has one of those values and 0 if not:

       number(boolean(resp1[. = "Discrepancy" or . = "Finding"]))

    but that's pretty verbose.  The approach in my previous post is probably the concisest and should work.  Could you post the exact formula that's giving you the error (with Show XPath selected)?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 03-16-2012 08:07 AM In reply to

    Actually, your previous post logic worked (I missed a bracket) however, the end result didn't work.  If they have 4 discrepancies, their inspection score shouldn't equal 100%.  So, instead of them equaling Discrepancy or Finding, I switched it to Compliant and works like a charm!  Thank you!

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