4 Replies Latest reply on Jun 20, 2017 11:35 PM by Johan Hedman

    Calculation

    thekops

      Hi guys, I am currently writing a program where it will calculate the amount of remaining leave. So this is a rough idea on how i wrote it.
      1) the user will enter into a portal the total amount of leave they are taking.

      2) assuming, one year there are 14days of leave.

      3)one day, the user applied 2 days of leave

      4) Remaining 12days of leaves

      5)the next day, the user applied for another 4 days of leave

       

      However, the field (outside the portal)  showing the remaining amount of leave shows 12 days remaining instead of 8days. Some advice will be appreciated.

        • 1. Re: Calculation
          Johan Hedman

          Use the Sum ( ) function to get the total from your portal Sum ( YourRelatedLeaveDaysField ) . This will give you number of used days. Then have a field on the Users table that calculate

           

          Users available leave days - Sum ( YourRelatedLeaveDaysField )

           

          This will give you what is left to use

          • 2. Re: Calculation
            thekops

            I am using a repeating field (Numberofdays).

             

            and a formula,  TotalAvailableDays- Sum(Numberofdays) however my field(showing the availabledaysleft) only shows the subtraction of the first equation and remains the same even when the user applies for more leave.

            • 3. Re: Calculation
              Stephen Huston

              Off the top of my head, no computer at hand: I believe there is an extend() function to make repeating fields give corresponding values in repeating sum fields. Otherwise repeating fields don't work for this.

              • 4. Re: Calculation
                Johan Hedman

                Like Stephan wrote, you can use the Extend ( ) function to sum repeated fields, but I recommend you to have a portal towards another table. It is way more flexible and more up to date working with related records in a portal then repeated fields