web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

percentage calculation in form

(0) ShareShare
ReportReport
Posted on by 327

Hi all i have a three fields in my form

1.current salary

2.expected salary

3.hike percentage

i will create create and ill enter current and expected salary once i enter a expected salary hike percentage should calculate automatically  how can i achieve it ,which method i need to write.

Thanks in advance.............. 

*This post is locked for comments

I have the same question (0)
  • Sathish Sivakumar Profile Picture
    3,732 on at
    RE: percentage calculation in form

    Hi Karthik,

    You have to write code on both "Salary" fields modified method.

    Thanks,

    Sathish

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: percentage calculation in form

    First of all, are your fields bound to a datasource? If yes, is it the same table/datasource? In that case you could write a display method on the Table with the calculation, add a new field to your form where you set the Datasource property on the form control to your datasource, and the Data method property to the display method. That will automatically take care of showing your calculation. Also consider caching the display method. You can find all the details for this on MSDN in the AX documentation.

    If your fields are not bound controls, in that case you could have your calculation on the Form's methods directly. Override the modified() method on each of your form controls, and call your new method from the modified(), which does the calculation and assigns the value to your summary field.

  • karthik143 Profile Picture
    327 on at
    RE: percentage calculation in form

    pkg.png

    hanks for reply mr.Vilmos Kintera

    i have tried already display method

    just look in to my code

    Display Percent hike()

    {

       PackageTbl pkg;

       real   c,;

       select * from pkg where pkg.Name == this.Name;

       c=((this.ExpectedCTC-this.CurrentCTC)/this.CurrentCTC)*100;

       return c;

    }

    if compile that code i am not getting any errors if open my form i am getting error please find the above image.

  • Suggested answer
    Rohin Profile Picture
    4,624 on at
    RE: percentage calculation in form

    try to write code in formDataSource modifed() method of expected CTC field :

    public void modified()

    {

       Amount    increase;

       if(table.ExpectedSalary != 0)

       {

           increase = table.ExpectedSalary - table.CurrentSalary;

           table.HikePercentage = (increase/table.CurrentSalary)*100;

       }

       super();

    }

  • Verified answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: percentage calculation in form

    Division by zero means your dividend is zero, meaning you would get a result of infinite in your equation.

    Make sure you handle that if this.currentCTC = 0, then return c as 0 too.

    Something like:

    c = this.CurrentCTC != 0 ? ((this.ExpectedCTC-this.CurrentCTC)/this.CurrentCTC)*100 : 0;


  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: percentage calculation in form

    Please make helpful answers as Verified instead of pressing Like, to resolve the topic. It is on the right of each post. Thank you

  • karthik143 Profile Picture
    327 on at
    RE: percentage calculation in form

    Display Percent hike()

    {

       PackageTbl pkg;

       real   c;

       select * from pkg where pkg.Name == this.Name;

       if(this.CurrentCTC != 0)

       {

          c=(((this.ExpectedCTC-this.CurrentCTC)/this.CurrentCTC)*100);

       }

       return c;

    }

    final code thanks for suggetion mr.Vilmos Kintera

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: percentage calculation in form

    One question, why do you make a select on PackageTbl, if you are not using the buffer afterwards? You can remove the variable and the select statement from your code. this keyword refers to the current buffer, based on which you are doing your calculation.

  • TacticalKarma Profile Picture
    15 on at
    RE: percentage calculation in form

    so can this calculator calculate for exemple loans?

  • Tillhasky Profile Picture
    5 on at
    RE: percentage calculation in form

    I think yes, but I wonder how it works? Because I think that you need to use a calculator that can calculate with different options that simple calculator can work. Since usually I have a situation, when I tried to calculate my salary with my family and simple calculator is taking too much time to do that and that's why I started to find different calculators on different topics, where I found an article about "percentage calculator" that was pretty useful for me (since it has a simple interface) which I am very happy about.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 3

#3
Scott_itD Profile Picture

Scott_itD 2 Community Manager

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans