473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

building an expression in ms access

11
I want to build an expression for House Rent (HR) in MS Access.

If Basic Salary (BS) is =>5000, HR is 50% of BS but not less than 2250,

if BS is between 5001 and 10800, HR is 45% of BS but not less than 2500 and

if BS is between 10801 and 21600, HR is 40% of BS but not less than 4800
Aug 11 '10 #1

✓ answered by Jerry Maiapu

I assume that calculation is done on a query. (In query Design View)

After a analysis (go through). I think this will work try it out:
copy&paste
Expand|Select|Wrap|Line Numbers
  1. HRent: IIf([BS]<=5000,IIf([BS]*0.5<2250,2250,[BS]*0.5),
  2. IIf([BS]<=10800,IIf([BS]*0.45<2500,2500,[BS]*0.45),
  3. IIf([BS]<=21600,IIf([BS]*0.4<4800,4800,[BS]*0.4))))

Sampe Output
Expand|Select|Wrap|Line Numbers
  1. BS    HRent
  2. 4000    2250
  3. 5000    2500
  4. 6000    2700
  5. 7000    3150
  6. 8000    3600
  7. 9000    4050
  8. 10000    4500
  9. 11000    4800
  10. 12000    4800
  11. 13000    5200
  12. 14000    5600
  13. 15000    6000
  14. 16000    6400
  15. .............
NB:You can change column Name HR and give your own name.

Hope it helps:

Jerry

14 2846
jimatqsi
1,271 Expert 1GB
Is this appearing in a query, or in code on a form?

It appears you made a mistake in your criteria, I think you mean if BS is less than or = 5000 then HR is 50%

On a form you could build a series of if tests
Expand|Select|Wrap|Line Numbers
  1. if BS >21600 then
  2. ' something happens here?
  3. elseif BS >= 10801 then
  4. HR = BS *.4
  5. if HR < 4800 then HR=4800
  6. Elseif BS >=5001 then
  7. HR=BS*.45
  8. if HR<2500 then HR=2500
  9. elseif BS <=5000 then
  10. HR=BS * .5
  11. if HR<2250 then HR=2250
  12. endif
  13.  
You might want to add some rounding, like this
Expand|Select|Wrap|Line Numbers
  1. HR=Round(BS*.45,0) ' whole dollars only
Jim
Aug 11 '10 #2
AbbasBD
11
Sorry, my knowledge is quite basic, I want to build expression for HR in design view something like:

HR:
IIf([BS]<=5000,[BS]*0.5,But if[BS]*0.5<2250,"2250",
IIf([BS]>5000 And [BS]<=10800,[BS]*0.45,But if[BS]*0.45<2500,"2500",
IIf([BS]>10800 And [BS]<=21600,[BS]*0.4,But if[BS]*0.4<4800,"4800")))

Here, I do not know what may be correct expression for 'But if'... pl help. thanks.
Aug 11 '10 #3
Jerry Maiapu
259 100+
I assume that calculation is done on a query. (In query Design View)

After a analysis (go through). I think this will work try it out:
copy&paste
Expand|Select|Wrap|Line Numbers
  1. HRent: IIf([BS]<=5000,IIf([BS]*0.5<2250,2250,[BS]*0.5),
  2. IIf([BS]<=10800,IIf([BS]*0.45<2500,2500,[BS]*0.45),
  3. IIf([BS]<=21600,IIf([BS]*0.4<4800,4800,[BS]*0.4))))

Sampe Output
Expand|Select|Wrap|Line Numbers
  1. BS    HRent
  2. 4000    2250
  3. 5000    2500
  4. 6000    2700
  5. 7000    3150
  6. 8000    3600
  7. 9000    4050
  8. 10000    4500
  9. 11000    4800
  10. 12000    4800
  11. 13000    5200
  12. 14000    5600
  13. 15000    6000
  14. 16000    6400
  15. .............
NB:You can change column Name HR and give your own name.

Hope it helps:

Jerry
Aug 12 '10 #4
AbbasBD
11
dear jerry

thank u very much for your prompt reply, it worked greatly!

AbbasBD
Aug 12 '10 #5
Jerry Maiapu
259 100+
Please select as best Answer.

Glad I could help
Aug 12 '10 #6
AbbasBD
11
I want to build an expression in MS Access Design View for ‘Personal Basic’ [PB] where [PB] is equal or immediate greater than ‘New Basic Minimum’ [NBM] by adding one or more ‘Increment Rate’ [IR] to ‘Basic Start’ [BS] ie,

[PB]=[BS]+([IR]*x) {where [BS]+([IR]*x)>=[NBM]}

For example:

[PB]=4500+(240*2) {here [NBM]=4890<4500+(240*2) ie, x=2 but Not x=1 or x=3}

[PB]=4980 {where 4980>=4890}

Thanks
Aug 28 '10 #7
Jerry Maiapu
259 100+
Hi AbbasBD, before I post suggestions to your question, please write a new question for this threat.

Your Question Title would be something like: Query Criteria not Working.
Thanks
Aug 29 '10 #8
AbbasBD
11
Jerry Maiapu

Thanks for your concern. Sorry for not being able to make you understand... however, just few hours back i’ve found out a solution that works for me:

PB:
(((([NBM]-[BS])\[IR])+1)*[IR])+[BS]

However, i welcome you, should you have anything better.

Thanks.
Aug 29 '10 #9
Jerry Maiapu
259 100+
If the calculation of PB is based on a condition, then you should have a IIF clause.

For example:
Expand|Select|Wrap|Line Numbers
  1. If NB>=NBM then BS+IR
  2. else
  3. something else';;;This part is missing
Though the syntax of IIF is
Expand|Select|Wrap|Line Numbers
  1. IIF (condition,True Part,False Part)
the latter is an example.

According to your solution:

Expand|Select|Wrap|Line Numbers
  1. (((([NBM]-[BS])\[IR])+1)*[IR])+[BS]
You're simply doing some straight forward calculation.

It is not doing what you expected it to do. ie. it is NOT checking if [PB] is equal or immediate greater than ‘New Basic Minimum’ [NBM] by adding one or more ‘Increment Rate’ [IR] to ‘Basic Start’ [BS].

If it follows a sequence then hope your solution is a sequence formula
like 2n + 1 where n is the term in the sequence. (Maths you know)

Hope am clear.
Aug 30 '10 #10
AbbasBD
11
Dear Maiapu

I failed to apply iif function, i've no idea about 2n+1 sequence formula... however, i tried the following that didn't work:

PB:
IIf([NBM]>=(1*[IR])+[BS],(1*[IR])+[BS],
IIf([NBM]>=(2*[IR])+[BS],(2*[IR])+[BS],
IIf([NBM]>=(3*[IR])+[BS],(3*[IR])+[BS],
IIf([NBM]>=(4*[IR])+[BS],(4*[IR])+[BS],
IIf([NBM]>=(5*[IR])+[BS],(5*[IR])+[BS]
)))))

Sure i've something wrong with the formula that i cannot sovle... waiting ur suggestion.

thanks
Sep 8 '10 #11
Jerry Maiapu
259 100+
AbbasBD,


Can u explain a bit more on on what you are trying to achieve. I might by then help you.

From what you posted, the query expression is confusing itself in terms of evaluating the parts in the IIF clause.

Try and change all the > to < like this; run it and see if it meet your expectations:
Expand|Select|Wrap|Line Numbers
  1. PB:
  2. IIf([NBM]<=(1*[IR])+[BS],(1*[IR])+[BS],
  3. IIf([NBM]<=(2*[IR])+[BS],(2*[IR])+[BS],
  4. IIf([NBM]<=(3*[IR])+[BS],(3*[IR])+[BS],
  5. IIf([NBM]<=(4*[IR])+[BS],(4*[IR])+[BS],
  6. IIf([NBM]<=(5*[IR])+[BS],(5*[IR])+[BS]
  7. )))))
Looks like numbers 1 to 5 are not constant ie will not stop to increment by one. Is that correct.?

What is that you are really trying to do?
Tell me.

Try the above and post back any query.
Cheers
Sep 8 '10 #12
NeoPa
32,556 Expert Mod 16PB
AbbasBD:
If Basic Salary (BS) is =>5000, HR is 50% of BS but not less than 2250,
This is a strange question considering 50% of the lowest qualifying value (5,000) is 2,500 anyway. If the lowest possible value is 2,500 why would you want to check that it's greater than 2,250?

** Edit **
Forget that. I see it's been covered already, but the same is true of the next one down. These simple details should be checked and corrected before posting the question, otherwise it just wastes people's time.
Sep 9 '10 #13
AbbasBD
11
@Jerry Maiapu

Yes right you are! 1, 2, 3, 4, 5 are not constant.

I want to find expression for Personal Basic [PB] that will be equal or greater than New Basic Min [NBM] by adding Increments [IR] to Basic Start [BS] (Here, always BS<NBM).

If [NBM]>=[BS]+1*[IR], its OK, but if by adding one IR doesn't make it, than should add two IR, ie, [NBM]>=[BS]+2*[IR]... Here, IR is incremental, may be nine IR need to be added... something like this.

Well, changing all > to < is not helping. May be I could clear... waiting for your reply.

Thanks.
Sep 9 '10 #14
AbbasBD
11
NeoPa

Thanks for your observation. I'll be careful... next time. However, correct one should be:

If BS<=5000, HR=BS*50% but not less than 2250,

Stay fine.
Sep 9 '10 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: crispy | last post by:
This is something that I am never completely sure about: When building an Access db to be accessed by ASP, do I need to worry about setting the Relationships between the tables and the Join Types...
2
by: bissatch | last post by:
I am trying to compare two variable but using regular expression: $access = "glasgow" $areaid = "glasgow-westend-byers_rd" using the two variables, I would like the areaid variable to be...
0
by: Rolan | last post by:
I'm using Access 97 and need some assistance in sorting out a proper DSum expression, or maybe even DCount might be an alternative. I have tried numerous combinations, but with no apparent success....
2
by: Jimi Ffondu | last post by:
Hi there - it's pretty simple, and I'm an idiot. I'm not a developer, I just seem to have landed in this job building this Access database - I've got two days to make it work... aaahh! 1) ...
5
by: Bec | last post by:
I'm in desperate need of your help.. I need to build an access database and have NO idea how to do this.. Not even where to start.. It IS for school, and am not asking anyone to do my...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
1
by: nmeyer | last post by:
Hi, I'm trying to scope a MS Access project and was looking for some advise. Will VB programming/ experience be required to build out something like the Northwinds sample database? We'd like a...
6
by: dafinder | last post by:
Hello all, I am a new user of Access and have run into some problems. I am building an access form that uses multiple tables. This is what I want to do in lay mans terms. I have a form with...
0
by: JamieWilks | last post by:
Hi I'm currently building an access db in MS Access 2000, having not touched acces for about 10 years. I need to conditionally hide / display a combobox (specfically a pop up calendar) depending on...
2
by: melodyrae | last post by:
Initial disclosure: I took 1 accounting with access class in undergrad 6 yrs ago, where we were offered step-by-step instructions to follow. Currently, I am interning (grad-school) for a small...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.