# Formula calculations on the fly

I have a formula in a field of table say formula is X*Y/Z where x,y,z are other fields in the same or diffrent table. IS THERE ANYWAY to calculate the value of formula in form straightaway by putting the known values of x,y,z Paramjit

study table and form desing thorougly …

Just use a TextBox with a SourceExpr of “Field X” * “Field Y” / “Field Z”

Is the formula the same on all records ? Then suggested solution shold be ok. Otherwise you should create your own “formula parser”… This can be done by using recordref and fieldref…

This formla is dynamic in nature over the user may change formula in fact it is costing formula fro my customer who is into manufaturing of pnemutacis comp. Paramjit

How often is formula changed ? How many different formulas they have? Maybe a set of predefined formulas could cover all needs ? Then you can make an option field with all possible formulas (like “Price/Profit Calc” on Item card) or even code field with table relation to “Formulas” table (like “Payment terms”). Then you need a function that will calculate resulting value based on known formulas. But if you need totally dynamic formula, it will be much harder. You can write formula parser using RecordRef and FieldRef variables and allow only simple operations (±*/). But it will be still very hard to make it “bug free”, because you cannot ensure that formula inserted is correct and that your code covers all possible formulas… Forumula could look like: F15 * F22 / R32F5, meaning multiply field 15 and field 22 (both form current rec) an divide by field 5 form rec 32. (how do you know which rec?). Other way to do dynamics is to export to excel. Even formulas…

What about Codeunit 8 AccSchedManagement? There is a formula parser in it. Besides, are you sure you are taking the correct approach to the problem?

quote:

Originally posted by paramjit_pummi
I have a formula in a field of table say formula is X*Y/Z where x,y,z are other fields in the same or diffrent table. IS THERE ANYWAY to calculate the value of formula in form straightaway by putting the known values of x,y,z Paramjit

Yes, there are multiple ways of accomplishing this.