Expression "lookup" logic function

Using an expression like the minute example below, consider expecting: 0-15 returns 1, 16-30 returns 2, 31-45 returns 3, and 46-59 returns 4. It’d be much nicer to reference the variable once like with a switch, than using many nested ifs.

dateExtract({[System]Client/System/CurrentDateTime}, "minute")

MS Excel uses LOOKUP. For example:

=LOOKUP(45,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"}) Assigns (F) =LOOKUP(90,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"}) Assigns (A-) =LOOKUP(78,{0,60,63,67,70,73,77,80,83,87,90,93,97},{"F","D-","D","D+","C-","C","C+","B-","B","B+","A-","A","A+"}) Assigns (C+)

We have a lookup expression that you could use - but you’d have to put the values in a dataset.

Or, for your example, you simply use this expression:

toInt(floor(max(0,dateExtract(now(), "minute")-1)/15))+1

The dataset lookup function works like a switch where it needs to find an exact match. What I’m looking for is a function that takes one input and compares it against an ordered range of numbers, like you might do with nested if statements. Imagine x is a long tag path or property.

if (x >= 100, 5, if (x >= 92, 4, if (x >= 80, 3, if (x >= 40, 2,1))))

or equivalently (you might support datasets or dataset columns for the 2 lists)

lookup(x, {100, 92, 80, 40}, {5, 4, 3, 2}, 1)

x=105 returns 5
x=93 returns 4
x=80 returns 3
x=25 returns 1

You could make your own function![code]def ranges(x, inputs, outputs, failover):
#error checking
if len(inputs) != len(outputs):
system.gui.warning(“Lists must be the same length”)
return failover

#loop through the inputs 
for i in range(len(inputs)):
	if x >= inputs[i]:
		return outputs[i]
return failover[/code]And call it with[code]runScript(", [100,92,80,40], [5,4,3,2], 1)")[/code]

Edit: woops, expression… Right: changed.