Custom Expressions


#1

Hi, I’m analysing the compliance of bartenders who have to serve a beer in 5 steps.

Each Step can be Compliant (True) or Not-compliant (False).

I would like to compute a ‘Compliance score’ for each bartender.

The formula to compute the score would be this:

Compliance score = X
If(Step1=true) And If (2 other Steps = true) Then X = True

In other words, the bartender MUST be compliant on Step 1 and Must be compliant on at least 2 other steps to be fully compliant.

How can I write this with the Query Builder?

If it’s not possible, is it possible to count the number of compliant Steps for each bartender and say If equal or larger than 3, then the bartender is compliant?

Also, where can I find a guide on how to write Custom Expressions?

Thank you very much for your help.


#2

Hi,
I hope I understand you right - but I believe you can build that with SQL? (not with the query builder though I think). But in SQL you can build cases that contain each possibility:

select
(case when step 1 = true and step 2 = true then X
when step 1 = true and step 2 = false then Y
end)

I guess there might be a better syntax where you don´t have to enter every single possible journey, thats above my mysql knowledge :slight_smile:
Some readings to case syntax: https://dev.mysql.com/doc/refman/5.7/en/case.html

Hope that helps!
Eva