How to calculate a percent of one known and one unknown value


#1

I am trying to get a design built where a dollar amount can be calculated based upon a fixed starting price and the user can enter a percentage. For example, the starting price of one item is .25 Different items have a different starting price. I have a blank text field for a percent to be manually entered and once it is, I need it to fill in the new dollar amount in a different field.

I also need to reverse this process by entering a new dollar amount and the percentage auto-filling.

Any help would be appreciated.


#2

Not sure if we understood your problem correctly. Let me elaborate it in the following way. Please correct if something is missing.

  1. Item A has a price of 0.25.
  2. The user will have an option to enter the percentage value. i.e. 8%
  3. You want to calculate the 8% of 0.25 and save that in a different field?

#3

That is correct. I built a repeater with different items in it and each has a different base price. When you select an item from the repeater, it lists the base price for the item and allows the user to enter a number in the percent field which I want to appropriately update the new price field or enter a number into the new price field and have the percent field automatically update.


#4

Hey @DCraig, are you trying to create something like that? Percent_repeater.rp (53.0 KB)
If it is not something you’re looking for, can you please tell us more about what should be added? Maybe you have a link where we can see a similar behavior?


#5

I’ve uploaded my project so you can see what I’m looking to do.Pharmacy Pricing 2.rp (212.5 KB)


#6

It looks like you are real close to a working solution. …It wasn’t that easy to understand what’s going on here, so let’s see if this is correct…

  • The "AWP/UOM" column is the starting price of a medication–yes?

  • If user clicks a row’s “Details” button it shows the “Edit CW” group, as a kind of popup modal.

  • So the "Edit AWP UOM" widget is the starting price from that row, and user can change the markup, either in the "Edit Percent" text field, or "Edit dollar" text field.

  • …and the "New CW" group is not used, but maybe your attempt to test some things?

    • Because both fields are editable and either field changes the other, you don’t really want to use the Text Changed event of the text field, because you’d risk a never-ending loop or inaccuracies due to rounding errors.

Here is an updated .rp file
Pharmacy Pricing 2.rp (290.5 KB)

  • I duplicated your Pharmacy Pricing page and made changes there.

  • I moved the “New CW” group down and unhid the “Edit CW” group to make it easier to work with.

    • I added a Loaded event to this group with “Hide This” action. I find this much easier to see and change things versus unhiding or clicking into things to see what they are.
  • I added an Update button for each Mark-up field.

    • Set up a selection group and selected style for these buttons.
    • For each text field I assigned the associated Update button as the Submit Button.
    • Fire the Update button’s Click or Tap upon Lost Focus (so a Tab or click away from the text field will update the other field.)
    • (You can hide these Update buttons if you don’t like the look/clutter, and things will still work the same.)
  • Here are the algorithms I use for each Update button:

    • Update% : [[ ((BASE * PERCENT / 100) + BASE).toFixed(2) ]]

    • Update$ : [[ (((DOLLAR - BASE) / BASE) * 100).toFixed(0) ]]

    • // where_BASE = text on “Edit AWP UOM” ; PERCENT = text on “Edit Percent” ;
      DOLLAR = text on “Edit Dollar” …and .toFixed(n) is a built-in function that forces rounding to specified decimals

  • For the Save button, your Edit Row Data action works, I just cleaned it up a bit.

    • I removed the AWP/UOM column because that never changes.
    • I also updated the names of [[LVAR1]] local variables to make things more readable.
    • You don’t need to change selection states for widgets in the repeater because when you edit row data it rebuilds the repeater, resetting all widgets to default states.
    • For good measure, I added a Set Text to update the "Last Modified" line and a brief Wait before hiding the popup.

#7

Awesome, thank you! I re-worked it a bit so the Update buttons would not be necessary and it works. I had the wrong formulas, though. I really appreciate the time and effort you put into this to help me.