473,385 Members | 1,856 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,385 software developers and data experts.

How to turn Excel Formulas into an Access Query?

Can't for the life of me work these 2 formula into an Access query !

Any help would be much appreciated ....

L5 is [Miles]



=IF(L5>150,130*3.8,(IF((AND(L5>19.9,L5<150.1)),(L5-20)*3.8,)))

=IF(L5>150,(L5-150)*2.4,0)
Jan 17 '11 #1

✓ answered by NeoPa

Teresa, your formula doesn't specify any value for when [Miles] not greater than 19.9.

If we assume that you are intending to say 20 and above, and that less than 20 returns a value of zero too, then try :

Expand|Select|Wrap|Line Numbers
  1. IIf(IsNull([Miles]),0,IIf([Miles]>150,130,IIf([Miles]<20,0,[Miles]-20))) * 3.8

8 3017
Hi Teresa,

You may try the following solutions.

Also, you may change the names of Expr1 ,Expr2 and Table1 accordingly.

Fields Formula:
Expr1: IIf([Miles]>150,130*3.8,IIf([Miles]>19.9 And [Miles]<150.1,([Miles]-20)*3.8))

Expr2: IIf([Miles]>150,([Miles]-150)*2.4,0)


Access Query:
SELECT Table1.Miles, IIf([Miles]>150,130*3.8,IIf([Miles]>19.9 And [Miles]<150.1,([Miles]-20)*3.8)) AS Expr1, IIf([Miles]>150,([Miles]-150)*2.4,0) AS Expr2
FROM Table1;


Jonathan
Jan 17 '11 #2
ADezii
8,834 Expert 8TB
  1. Sample SQL Statement:
    Expand|Select|Wrap|Line Numbers
    1. SELECT A.Miles, fCalcWhatever([Miles]) AS Expr
    2. FROM A
    3. WHERE A.Miles Is Not Null;
  2. Function Definition:
    Expand|Select|Wrap|Line Numbers
    1. Public Function fCalcWhatever(sngMiles As Single) As Variant
    2. If sngMiles >= 150 Then
    3.   fCalcWhatever = (130 * 3.8)
    4. ElseIf sngMiles > 19.9 And sngMiles < 150 Then
    5.   fCalcWhatever = ((sngMiles - 20) * 3.8)
    6. Else        'sngMiles <= 19.9
    7.   fCalcWhatever = sngMiles      'Not sure
    8. End If
    9. End Function
  3. Sample Date:
    Expand|Select|Wrap|Line Numbers
    1. Miles
    2. 20.1
    3. 149
    4. 174
    5. 17
    6. 14.3
  4. Results based on Sample Data:
    Expand|Select|Wrap|Line Numbers
    1. Miles    Expr
    2. 20.1       0.380001449584961
    3. 149      490.2
    4. 174      494
    5. 17        17
    6. 14.3      14.3
Jan 17 '11 #3
IT WORKS !!!

THANK YOU SOOOOOOO much to all who helped.

Regards

One very happy person
Jan 18 '11 #4
Need help again,sorry

B: IIf([Miles]>150,130*3.8,IIf([Miles]>19.9 And [Miles]<150.1,([Miles]-20)*3.8))

How do I put in this "if null put me a 0 in" ?

My other sums don't work if I don't put a zero in, sometimes I could scream !

Regards, Teresa
Jan 23 '11 #5
ADezii
8,834 Expert 8TB
Try:
Expand|Select|Wrap|Line Numbers
  1. IIf(IsNull([Miles]),0,IIf([Miles]>150,130*3.8,IIf([Miles]>19.9 And [Miles]<150.1,([Miles]-20)*3.8)))
Jan 23 '11 #6
NeoPa
32,556 Expert Mod 16PB
Teresa, your formula doesn't specify any value for when [Miles] not greater than 19.9.

If we assume that you are intending to say 20 and above, and that less than 20 returns a value of zero too, then try :

Expand|Select|Wrap|Line Numbers
  1. IIf(IsNull([Miles]),0,IIf([Miles]>150,130,IIf([Miles]<20,0,[Miles]-20))) * 3.8
Jan 24 '11 #7
Done and works perfect, you're all brilliant !

Thanks, Teresa
Jan 24 '11 #8
NeoPa
32,556 Expert Mod 16PB
A pleasure Teresa.

To be fair, I think ADezii's version would have worked well too.
Jan 24 '11 #9

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

Similar topics

0
by: tag | last post by:
Hi, I have a problem in that I need to be able to parse excel formula's and evaluate them to get results. Python is very well suited for this as it has WONDERFUL data handling capabilities. ...
3
by: austin1539 | last post by:
I am trying to run an Access query from Excel. The query, called "ProdActs1" works in Access and is run from using information from a table called "Queries". When a button is clicked in Excel, data...
1
by: CoolFactor | last post by:
MY CODE IS NEAR THE BOTTOM I want to export this Access query into Excel using a command button on an Access form in the following way I describe below. Below you will find the simple query I am...
3
by: skiddle | last post by:
I've got an Excel formula that calculates the total business hours that a help desk ticket is open. As one would expect, it factors out holidays and non-work hours. What would be the corresponding...
16
by: Phil Stanton | last post by:
I have a form with a button which is supposed to open an Excel file (With lots of Macros /VBA) in it. The Excel file gets it's data from the Access program Here is the code Private Sub...
2
by: welshkaiboy | last post by:
Due to the size of the data I have to manipulate I need to apply a excel formula in access which determines date of manufacture from a serial number 716001 so I use...
15
by: OzNet | last post by:
I have a query (with calculated fields) in Access (2007) and the data changes depending on the dates and staff person selected. I need to produce a series of graphs based on the data in this query...
2
by: rtilson | last post by:
I am not sure why excel and access use the same method in formula. I am not access expert but been trying to figure it out. Here is the excel formula that I would like to use in access expression...
0
by: Lina Arraiz | last post by:
I'm trying to export an Excel 2003 spreadsheet to Access 2007. I need to calculate the time elapsed between column D (START) and column E (END) with the results appearing in column F (TIME). The...
3
by: david sherman | last post by:
Does software converting excel to access with financial functions exist? I need to take several fixed income portfolio run manually from excel and create a database. The excel relies heavily on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.