Skip to main content

I have a quite complex query to calculate a KPI and want to limits its result to a maximum value.

 

This max value is stored in a variable with an absolute value of e.g. 2.

If the actual result of the KPI is higher than 2 the PQL should return 2.

 

I set this up as an CASE WHEN but this is repetitive code which is badfor readability and maintainabilty.

 

Are there more consise approached possible with PQL? e.g. using a Max(KPIcode, Limit) Excels Max function works something like this. But PQL Max works only on a column.

 

just for reference my PQL looks something like this:

CASE WHEN (... 5 lines of code to calculate KPI) > <%= Limit %>

THEN <%= Limit %>

ELSE (... 5 lines of code to calculate KPI)

END

 

 

 

 

I think you are looking for the LEAST() function - LEAST("KPI logic", <%= limit %>) would give you the limit back when the KPI logic value exceeds the limit. For KPI logic values under the limit, the KPI value would return. I'm not sure what your KPI logic is and whether LEAST() will accept it, but give that a try!


I think you are looking for the LEAST() function - LEAST("KPI logic", <%= limit %>) would give you the limit back when the KPI logic value exceeds the limit. For KPI logic values under the limit, the KPI value would return. I'm not sure what your KPI logic is and whether LEAST() will accept it, but give that a try!

Thanks Chris, this is exactly what I was looking for. I wasn't aware of this PQL function.


Just for future reference there is also the opposite function GREATEST which helps doing it the other way around return the greatest value of columns or absolute default values.


Reply