Using "IF' and "OR" in a formula for a calculated field - InfoPath Dev
in

InfoPath Dev

Using "IF' and "OR" in a formula for a calculated field

Last post 02-03-2015 01:49 PM by Aspo28. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 01-23-2015 11:59 AM

    • Aspo28
    • Not Ranked
    • Joined on 01-23-2015
    • Posts 5

    Using "IF' and "OR" in a formula for a calculated field

    I am fairly new to InfoPath and to this forum so please forgive me if this has already been asked and answered. 

    I am in need of some help as it pertains to formulas.  I have a dropdown field labeled "Currency".  Users pick a currency (field1) and provide amount of shares of stock to buy (field2).  Field 3 is the stock price which is hardcoded in the form and field 4 is an exchange rate that the user provides.  I have a simple calculated field:  field2 * field3 * field4.  This works fine.  No issues.

     However,  I now need to take into consideration the selected currency.  Specifically, if a particular currency (only 2 out of the entire list) is selected, the calculation must round the answer to the nearest whole number.  In Excel, such a formula would look like this:

     =IF(OR(field1="CUR1",field1="CUR2"),ROUND(field2*field3*field4),field2*field3*field4)

    Unfortunately, I am really struggling "translating" this into the appropriate syntax InfoPath expects.  Any guidance would be GREATLY appreciated!

    Thanks in advance!

    Filed under:
  • 01-23-2015 01:54 PM In reply to

    Re: Using "IF' and "OR" in a formula for a calculated field

     Hello Aspo28,

    Thanks for your question. Formulas can be tricky in InfoPath but once you get the hang of it you'll be on your way! In this instance you would want a rule copied to each field tat is changed or a button to calculate the value. The reason being is that conditions cannot be applied to a default value.

    The first part would be part of the condition for your action rule. Then you would want this formula to fire to calculate for != to CUR1 or CUR 2 to get the normal value. On the second part bould be a formula similar to this:

    substring-before((field2*field3*field4), ".") 

    Hope that helps!

    Bre 

  • 01-27-2015 05:25 AM In reply to

    • Aspo28
    • Not Ranked
    • Joined on 01-23-2015
    • Posts 5

    Re: Using "IF' and "OR" in a formula for a calculated field

    Thank you Bre for your quick reply.  I apologize for the delay in responding.  I am still trying to work through this.  What kind of rule would I place on each field?  Thanks again!

  • 01-28-2015 09:21 AM In reply to

    Re: Using "IF' and "OR" in a formula for a calculated field

    I beleive what Bre is refering to is a rule that would refigure the calculation when any of the other fields are changed. You want to make sure a rule is on each field that preforms the calculation so if a user needs to change one of the fields after the calculation has already been completed, it is recalculated.

     A button that does the calculation would also work but would only work if the user clicks it.

  • 02-03-2015 01:49 PM In reply to

    • Aspo28
    • Not Ranked
    • Joined on 01-23-2015
    • Posts 5

    Re: Using "IF' and "OR" in a formula for a calculated field

     Thanks Bre and snturner for leading me in the right direction.  I finally got this working with the use of Rules!  Works like a charm.  Part of my issue was that the fields were calculated fields - which don't work with Rules as needed (I didn't know that at first).  Converting these fields to Text type fields allowed me to add the right Rules to get it working as needed.  Thanks again! 

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