RE: Difference of two ratio numbers

Hi ,

I need some calculation logic in appain that gives difference of ration numbers example shown below in the screenshot.

Can someone help me to write the logic for this on priority?

Here actual and threshold values are user inputs based on those inputs variance col data to be shown .

  Discussion posts and replies are publicly visible

Parents Reply Children
  • 0
    Certified Lead Developer
    in reply to JS0001

    I did not get your question. What do you want to achieve here?

  • so before the formula was like this ex: (2:3-4:5) result based on above code worked,Now How to achieve result using this formula

    case1 :(2:3-4:5)/2:3*100

    case2: (2:1-4:1)2:1*100 for above of the code?

  • 0
    Certified Lead Developer
    in reply to JS0001

    I am still not clear. Can you help me with just the inputs you would like to send and the output you want to get? And I will try to build the formula.

  • a!localVariables(
      local!ratio1: "3:4",
      local!ratio2: "5:6",
      local!ratio1Array: split(local!ratio1, ":"),
      local!ratio2Array: split(local!ratio2, ":"),
      local!lcm: lcm(
        local!ratio1Array[2],
        local!ratio2Array[2]
      ),
      local!numerator: (
        local!ratio1Array[1] * (local!lcm / local!ratio1Array[2])
      ) - (
        local!ratio2Array[1] * (local!lcm / local!ratio2Array[2])
      ),
      if(
        mod(local!numerator, local!lcm) = 0,
        local!numerator / local!lcm,
        concat(local!numerator, "/", local!lcm)
      )
    )

    Ok this code is giving difference of two numbers which is in ratios ,How to get the result by doing this calculation like the scenario difference of those numbers i.e (-1/12) and divided by local!ratio1 i.e 3:4 and multiply with 100.

    So formula would be like this(local!ratio1(3:4)-local!ratio2(5:6)/local!ratio1(3:4)*100

    I hole this makes more clear

  • 0
    Certified Lead Developer
    in reply to JS0001

    a!localVariables(
      local!ratio1: "3:4",
      local!ratio2: "5:6",
      local!ratio1Array: split(local!ratio1, ":"),
      local!ratio2Array: split(local!ratio2, ":"),
      local!lcm: lcm(
        local!ratio1Array[2],
        local!ratio2Array[2]
      ),
      local!numerator: (
        local!ratio1Array[1] * (local!lcm / local!ratio1Array[2])
      ) - (
        local!ratio2Array[1] * (local!lcm / local!ratio2Array[2])
      ),
      local!result: if(
        mod(local!numerator, local!lcm) = 0,
        local!numerator / local!lcm,
        concat(local!numerator, "/", local!lcm)
      ),
      local!resultArray: split(local!result,"/"),
      local!lcm2: ((local!ratio1Array[2]*local!resultArray[1])/(local!ratio1Array[1]*a!defaultValue(
        value: index(local!resultArray,2,1),
        default: 1
      ))),
      local!lcm2*100
    )

  • 0
    Certified Lead Developer
    in reply to JS0001

    Now that it has worked for you, Can you please accept the answers to close this thread?

  • I have one  query related to the richtextdisplayfield.Could you please suggest? 

     a!richTextDisplayField(
                  value: if(
                    fv!item.finCov_txt = "Other",
                    tointeger(fv!item.actualThreshold_txt) - tointeger(fv!item.covenentThreshold_txt),
                    if(
                      rule!CR_APP_DSC_displayFinCovPlaceholder(
                        finCovType_txt: displayvalue(
                          fv!item.finCov_txt,
                          ri!crRefFinCov_cdt.finCov_txt,
                          ri!crRefFinCov_cdt.valueType_txt,
                          ""
                        )
                      ) = "m:n",
                      rule!CR_APP_FinCovCalculationmn(
                        valueType1_txt: fv!item.actualThreshold_txt,
                        valueType2_txt: fv!item.covenentThreshold_txt
                      ),
                      if(
                        rule!CR_APP_DSC_displayFinCovPlaceholder(
                          finCovType_txt: displayvalue(
                            fv!item.finCov_txt,
                            ri!crRefFinCov_cdt.finCov_txt,
                            ri!crRefFinCov_cdt.valueType_txt,
                            ""
                          )
                        ) = "m:1",
                        rule!CR_APP_FinCovCalculationm1(
                          valueType1_txt: fv!item.actualThreshold_txt,
                          valueType2_txt: fv!item.covenentThreshold_txt
                        ),
                        if(
                          rule!CR_APP_DSC_displayFinCovPlaceholder(
                            finCovType_txt: displayvalue(
                              fv!item.finCov_txt,
                              ri!crRefFinCov_cdt.finCov_txt,
                              ri!crRefFinCov_cdt.valueType_txt,
                              ""
                            )
                          ) = "Amount",
                          (
                            fv!item.actualThreshold_txt - fv!item.covenentThreshold_txt
                          ) / fv!item.actualThreshold_txt * 100,
                          if(
                            rule!CR_APP_DSC_displayFinCovPlaceholder(
                              finCovType_txt: displayvalue(
                                fv!item.finCov_txt,
                                ri!crRefFinCov_cdt.finCov_txt,
                                ri!crRefFinCov_cdt.valueType_txt,
                                ""
                              )
                            ) = "Percentage",
                            (
                              (fv!item.actualThreshold_txt / 100) - (fv!item.covenentThreshold_txt / 100)
                            ) / (fv!item.actualThreshold_txt / 100) * 100,
                            null
                          )
                        )
                      )
                    )
                  ),
                  style: if(
                    fv!item.varience_txt > 0,
                    "color: green;",
                    if(
                      fv!item.varience_txt < 0,
                      "color: red;",
                      {}
                    )
                  )
                ),

    I have used richTextDisplayfield to write some colour logic.Since I would need green colour if the varience returns positive otherwise red .Since in 22.4.660.0 version doesn't have style parameter in richtextdisplayfield, How could I achieve this?