Ad Widget

Collapse

Absolute value in calculated item

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krysi
    Junior Member
    • Dec 2017
    • 2

    #1

    Absolute value in calculated item

    Hello everybody,

    I try to find a way to calculate an absolute value in the calculated item.
    For example I have two values x and y. It should calculate last(x) - last(y) but sometimes x is lower than y. What I need is only the difference between this two values, without a negative or positive sign in front of it. Could anyone help me with this topic?

    Thank you in advance.
  • Noobz
    Senior Member
    • Jun 2020
    • 105

    #2
    Did you get this to work? I'm running into the exact same issue.

    Comment

    • Semiadmin
      Senior Member
      • Oct 2014
      • 1625

      #3
      (last(x) > last(y)) * (last(x) - last(y)) + (last(x) < last(y)) * (last(y) - last(x))

      Comment

      • Noobz
        Senior Member
        • Jun 2020
        • 105

        #4
        Originally posted by Semiadmin
        (last(x) > last(y)) * (last(x) - last(y)) + (last(x) < last(y)) * (last(y) - last(x))
        Sure, but why does abs not work as a calculated item, it works fine as a trigger function.
        You may as well just sq then sqrt the value

        Comment

        • Semiadmin
          Senior Member
          • Oct 2014
          • 1625

          #5
          Depends on version.
          In 5.4 abs(last(//x) - last(//y)) works well.

          Comment

          • Noobz
            Senior Member
            • Jun 2020
            • 105

            #6
            Hmm, maybe I'm doing it wrong but I couldn't get that to work on 5.4.9 - however, I had no problem making it work as a trigger.

            Comment

            Working...