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)
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 : - 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
- Sample SQL Statement:
- SELECT A.Miles, fCalcWhatever([Miles]) AS Expr
-
FROM A
-
WHERE A.Miles Is Not Null;
- Function Definition:
- Public Function fCalcWhatever(sngMiles As Single) As Variant
-
If sngMiles >= 150 Then
-
fCalcWhatever = (130 * 3.8)
-
ElseIf sngMiles > 19.9 And sngMiles < 150 Then
-
fCalcWhatever = ((sngMiles - 20) * 3.8)
-
Else 'sngMiles <= 19.9
-
fCalcWhatever = sngMiles 'Not sure
-
End If
-
End Function
- Sample Date:
- Miles
-
20.1
-
149
-
174
-
17
-
14.3
- Results based on Sample Data:
- Miles Expr
-
20.1 0.380001449584961
-
149 490.2
-
174 494
-
17 17
-
14.3 14.3
IT WORKS !!!
THANK YOU SOOOOOOO much to all who helped.
Regards
One very happy person
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
Try: - IIf(IsNull([Miles]),0,IIf([Miles]>150,130*3.8,IIf([Miles]>19.9 And [Miles]<150.1,([Miles]-20)*3.8)))
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 : - IIf(IsNull([Miles]),0,IIf([Miles]>150,130,IIf([Miles]<20,0,[Miles]-20))) * 3.8
Done and works perfect, you're all brilliant !
Thanks, Teresa
NeoPa 32,556
Expert Mod 16PB
A pleasure Teresa.
To be fair, I think ADezii's version would have worked well too.
Sign in to post your reply or Sign up for a free account.
Similar topics
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
| |