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

  • 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 dont see parameter called background colour in 22.4 version of appian and also this is my code could you suggest for this please if possible.

    Now this image has positive and negativa value for variance column,So variance has to be colured green for positive value and red for negative value.Lets consider variance col is richtextdisplayfield

  • 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?

  • 0
    Certified Associate Developer
    in reply to JS0001

    Hi

    a!richTextDisplayField(
        labelPosition: "COLLAPSED",
        value: {
            a!richTextItem(
                text: {
                    a!richTextIcon(icon: "USER", caption: "Name"),
                    " Xavier Jones"
                },
                size: "MEDIUM",
                style: { "STRONG" }
            ),
        char(10),
        char(10),
        a!richTextItem(
            text: {
                a!richTextIcon(icon: "BUILDING-O", caption: "Location"),
                " Reston, VA"
            },
            color: "SECONDARY"
        )
        }
    )

    You need to try this way within the value field you can give the richtextItem

  • But I dont need icon in my case but that column has to be highlight,  Can u modify above code which I have sent.