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

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.

1 Like

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?

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.

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?

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

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.
2 Likes

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.