How do I replace the map with its equivalent expression?

How do I replace the map with its equivalent expression? I tried case, switch, if, and I got an error.

Please explain what's wrong with your map first!

Note that your map transform inputs don't cater for values between 114 - 115, 129 - 130, etc. You should be using,

[80, 115)
[115, 130)
[130, 140)
[140, 180)
[180, 200]

Note the [ (inclusive) and ) (exclusive).

Numeric Range : A range of values that the incoming value will fall between. Use brackets [x,y] to indicate values that are to be inclusive, or parenthesis for values that are exclusive (x,y), and you can mix them as needed. You can also omit start or end values to indicate no end to the range.
Map Transform | Ignition User Manual

1 Like

Using nested if statements within an expression transform:

if(({value} > 80) && ({value} < 114), 0.5316,
if(({value} > 115) && ({value} < 129), 0.545,
if(..., ...,
null
)))

You can use case instead:

case (true),
    80 <= x && x <= 114, 0.5316,
    115 <= x && x <= 129, 0.545,
    ...
)

Makes things a bit easier to maintain than nested ifs.

4 Likes

Don’t use a transform when you can just use an expression. No need for the extra processing step.

1 Like

Pascal, are you getting mixed up with C syntax? What's x in there?
(Your ( )s don't pair up properly either!)

I had wondered about case testing ranges before but thought it couldn't be done.

Assuming the OP has left out catering for values between 114 and 115 in error, this could become,

if({value} > 200, null,
if({value} > 180, 0.5712,
if({value} > 140, 0.5643,
if({value} > 130, 0.5543,
if({value} > 115, 0.545,
if({value} > 80, 0.5316,
null
))))))

Yes I was a bit careless with the example.
x is just a placeholder. The parenthesis are indeed misplaced. Kind of forgot expression syntax.

case (true,
    80 <= {value} && {value} <= 114, 0.5316,
    115 <= {value} && {value} <= 129, 0.545,
    [condition], [value],
    [some default if no case match]
)
6 Likes

If one of the motivations of the OP is to do this outside Perspective, where there aren't any transforms, my Integration Toolkit's functions can help. Like so:

transform(
    {path/to/x},
    case (true,
        80 <= value() && value() <= 114, 0.5316,
        115 <= value() && value() <= 129, 0.545,
        [some condition on value()], [some result],
        [some default result if no case match]
    )
)
4 Likes