0

Conditional Formatting Built into Formula Field

I have a formula field that calculates ending inventory balance. [units on hand] - [units to distribute]

I'd like to add in a conditional formula in the field background based on final balance. I've tried a number of attempts using the color() function and the styled() function. But I can't quite get it to work. I either get the value or the color, but not both. Here is my latest attempt. 

What am I doing wrong?

let xBal := sum('UN On Hand' - 'UN to Distrib');
if xBal = 0 then
styled(text(xBal), "green")

else if

xBal > 0 and xBal < 5 then

styled(text(xBal), "yellow")

else if xBal > 5 then

styled(text(xBal), "red")
end

end

end

10 replies

null
    • Nick
    • 3 yrs ago
    • Reported - view

    Try it this way:

     

    let xBal := sum('UN On Hand' - 'UN to Distrib');
    styled(text(xBal), if xBal = 0 then
    "green"
    else
    if xBal > 0 and xBal < 5 then
    "yellow"
    else
    if xBal > 5 then "red" end
    end
    end)

    • John_Halls
    • 3 yrs ago
    • Reported - view

    Sorry, I'm stumped! I can get the styled and color functions to work in form view but not in table view. All it shows is an unformatted 0. Is this correct?

     

    BTW your formula above doesn't check for the number 5 use xBal <= 5 to include in the yellow set or xBal >= 5 to include it in the red set

     

    Regards John

    • Nick
    • 3 yrs ago
    • Reported - view

    Screenshot 2021-04-22 at 11.18.12

    • John_Halls
    • 3 yrs ago
    • Reported - view

    Hi Nick

    That's wierd. I took a random table in my sandpit database and added a number and formula field, it displayed OK in form view but I had no joy whatsoever in table view. Created a new table and added the same fields and bingo it all worked.

     

    Thanks for that.

     

    Regards John

    • Nick
    • 3 yrs ago
    • Reported - view

    Hi John,

    ...outside the earth or its atmosphere 🤪

    • John_Halls
    • 3 yrs ago
    • Reported - view

    These two formula fields have the same formula!

     

    Formula

    • Chapel_of_Praise
    • 3 yrs ago
    • Reported - view

    You are both awesome in your help. I got it to work with your coaching. Thank you. And good catch on including the '5'. thanks.

    • John_Halls
    • 3 yrs ago
    • Reported - view

    Hi All

     

    When it comes to colouring a field according to its valuse I thought I would put something together that is more re-useable and have come up with the following

     

    let numberField := Number;
    let upperBounds := [0, 4, 10];
    let colourRange := ["red", "orange", "green", "blue"];
    if numberField = null then
    styled(text(numberField), "")
    else
    let colour := item(colourRange, 0);
    let i := 1;
    for a in upperBounds do
    if numberField > a then
    colour := item(colourRange, i)
    end;
    i := i + 1
    end;
    styled(text(numberField), colour)
    end

     

    You only have to amend the first three lines to accommodate your own needs.

    Line 1 - amend this to make numberField take the value of your own number field

    Line 2 - fill in the upper boundaries that you wish to use. These are inclusive boundaries so for my example its up to and including 0, up to and including 4, etc.

    Line 3 - fill in the colours you wish to use. Again the first one will be used up to and including the first upperBound. There is one more colour than upperBound and this is used for everything above that last upperBound

     

    Hope that makes sense.

     

    Regards John

    • Ninox partner
    • RoSoft_Steven.1
    • 3 yrs ago
    • Reported - view

    Thanks for sharing John. 

    • Nick
    • 3 yrs ago
    • Reported - view

    Thanks John

Content aside

  • 3 yrs agoLast active
  • 10Replies
  • 1072Views