Multiple IIf and AND in a query

mdmahfuzcse

New Member
Joined
Nov 26, 2013
Messages
1
Hi, I am working in a factory as a HR officer. Recently I have made a database on Employee Salary. There is a query of yearly bonus based on Employee’s Job duration. The query is:
Bonus: IIf([JobDuration]>=12,[Main_Salary]*0.4,IIf([JobDuration]>=7,[Main_Salary]*0.3,IIf([JobDuration]>=4,[Main_Salary]*0.2,IIf([JobDuration]>=2,[Main_Salary]*0.1,[Main_Salary]*0))))
And it works nicely. The problem is if I want to add more condition such as JobDuration>=12 AND Department=Admin then it doesn’t run. My Required Condition is:
If ([JobDuration]>=12 and [Department] =”Admin” then [Main_Salary]*1.0 Otherwise [Main_Salary]*0.6
If ([JobDuration]>=7 and [Department] =”Admin” then [Main_Salary]*0.8 Otherwise [Main_Salary]*0.3
If ([JobDuration]>=4 and [Department] =”Admin” then [Main_Salary]*0.6 Otherwise [Main_Salary]*0.2
If ([JobDuration]>=2 and [Department] =”Admin” then [Main_Salary]*0.4 Otherwise [Main_Salary]*0.1
Otherwise [Main_Salary]*0
In this situation what is the solution? What should be the query on the mentioned condition?
It would be highly helpful for me if someone help me.
Thanks in advanced.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Welcome to the Board!

You can only nest up to 7 levels in an IIF statement. Instead of trying to build all of this into a single, long, convoluted formula, I would recommend creating a User Defined Function (UDF) instead. Just feed the formula the two variables, and have it do the calculations and return the result you need.

Here are some link that show you how to do that:
Creating and Using User Defined Functions in Access » Bacon Bits
Creating Access UDFs that Accept Arguments » Bacon Bits
MS Access: Creating a custom round function
 
Upvote 0

Forum statistics

Threads
1,215,264
Messages
6,123,960
Members
449,135
Latest member
jcschafer209

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top