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
  • You can create rule inputs for ratio1 and ratio2. 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    a!localVariables(
    local!ratio1: "3:1",
    local!ratio2: "2:1",
    local!ratio1Array: split(local!ratio1, ":"),
    local!ratio2Array: split(local!ratio2, ":"),
    local!lcm: lcm(
    local!ratio1Array[2],
    local!ratio2Array[2]
    ),
    concat(
    (
    local!ratio1Array[1] * (local!lcm / local!ratio1Array[2])
    ) - (
    local!ratio2Array[1] * (local!lcm / local!ratio2Array[2])
    ),
    "/",
    local!lcm
    )
    )
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • A more refined code for handling when the number is completely divisible. 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    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)
    )
    )
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Thanks it really helped.

  • 0
    Certified Lead Developer
    in reply to sid

    Cool! If this worked, please verify the answers to close this thread.

  • I have one more question,The question related to grid. is it possible to

  • 0
    Certified Lead Developer
    in reply to sid

    possible to?

    rid. is it possible to
Reply Children
  • is it possible to show entire grid row of data with these cases? if not is it possible to show for variance field(it a textfield)? 

  • 0
    Certified Lead Developer
    in reply to sid

    You can use the 'backgroundColor' in gridColumn to change the background color. 

  • Something like this. 

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    a!gridField(
    data: {
    {
    actual: 6,
    convenant: 3,
    variance: 3
    },
    {
    actual: 12,
    convenant: 6,
    variance: 6
    }
    },
    columns: {
    a!gridColumn(
    label: "Actual",
    value: fv!row.actual,
    backgroundColor: a!match(
    value:fv!row.variance,
    whenTrue: (fv!row.actual*0.5)<(fv!value*0.5),
    then: "WARN",
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • but i have gridRowlayout with add multiple rows and I dont see backgroundcolour in 22.4 version of appian which i am using now,Could you please suggest for this code and it would be more useful.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    {
    a!gridLayout(
    label: cons!CR_APP_LAB_FINANCIAL_COVENANTS,
    labelPosition: "COLLAPSED",
    spacing: "DENSE",
    headerCells: {
    a!forEach(
    items: {
    "",
    cons!CR_APP_TXT_FINANCIAL_COVENANTS_GRID_FIELDS,
    ""
    },
    expression: if(
    fv!item = cons!CR_APP_TXT_FINANCIAL_COVENANTS_GRID_FIELDS[9],
    a!gridLayoutHeaderCell(
    align: "LEFT",
    label: fv!item,
    helpTooltip: cons!CR_APP_SC_PRECEDENT_SUBSEQUENT_LAB_VAL[1] & " / " & cons!CR_APP_SC_PRECEDENT_SUBSEQUENT_LAB_VAL[2]
    ),
    a!gridLayoutHeaderCell(
    align: if(
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • 0
    Certified Lead Developer
    in reply to sid

    You can add richTextDisplayFields in your gridRowLayout and then add color to it using the same logic. 

  • 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