Multiple conditions on Salary Structure with a single formula

HI i wanted to know how to put multiple conditions with a single formula on ERPNEXT version 12.

Example:

Component 1: if base is greater than or equal to 5,000 but less than or equal to 10,000 then base * 0.01

Component 2 if base is greater or equal to than 10,001 but less than or equal to 15,0000 then base * 0.02

How can i express these condition on the salary structure? Kindly assist.

Maybe relate what you have found and learned from your experiments to achieve this?

@clarkej I have created a salary structure with those 2 components but i have noticed that ones i generate my salary slip, the conditions are not being processed as i expected.

Example:

For this i put the condition as 10000<=base>=5000 and formula as base*0.01

For this i put the condition as 15000<=base>=10,001 and formula as base*0.02

From the above example if the base salary is 12,000 i dont expect component 1 to be processed as the condition is not met, only component 2 should be processed. Unfortunately this is not happening.It actually processes component 1 and leaves out component 2.

Are my conditions in the examples correct or is there something am missing. also am using base to be my basic salary.

Maybe try this approach?

“adding multiple rows of the same component, but different condition.”

Reference Salary Structure Multiple Condition

edit: For ideas try a search like this "@Tufan_Kaynak2 salary conditions"

@clarkej Thanks. This makes more sense. In the example i have shared with you, how can i break component 1 into different components. Kindly give me a sample example. I will highly appreciate

Short of doing this trial and error myself, perhaps someone is willing to share…

@ben

Try this if it works:
base * 0.01 if (base >= 5000 and <= 10000) else base * 0.02 if (base >= 10001 and <= 15000)

You don’t need to create 2 different components if the salary component is the same.

Regards,
Reema

Hi @Reema_Mehta

I have done exact formula and I got error.
Syntax error in formula or condition: invalid syntax (, line 1)
what else should I set up to get this done? I am missing something?

I guess that the condition is expecting one last else.
my solution was like this.
base * 0.01 if (base >= 5000 and <= 10000) else base * 0.02 if (base >= 10001 and <= 15000) else 0

This worked for me:

frappe@ubuntu:~/frappe-bench$ bench console

In [1]: base = 5001

In [2]: base * 0.01 if (base >= 5000 and <= 10000) else base * 0.02 if (base >= 10001 and <= 15000) else 0
File “”, line 1
base * 0.01 if (base >= 5000 and <= 10000) else base * 0.02 if (base >= 10001 and <= 15000) else 0
^
SyntaxError: invalid syntax

In [3]: base * 0.01 if (base >= 5000 and base <= 10000) else base * 0.02 if (base >= 10001 and base <= 15000) else 0
Out[3]: 50.01

3 Likes

Yes, you are right it requires one more else. Did this work for you?

this one worked, as @clarkej wrote.

This also worked for me.

base * 0.01 if (base >= 5000 and base <= 10000) else base * 0.02 if (base >= 10001 and base <= 15000) else 0

Thanks alot guys. So much appreciated.

2 Likes

See also Salary Component Formula