Calculated Field

Parra

Well-known Member
Joined
Feb 21, 2002
Messages
752
I have a field in a query called "Frequency" and the result is a number.

What I need is a calculated field that gets the result of "Frequency" and groups it into one of the following.

1
2
3-6
7-13
14-29
30 +

Almost like an IF functions, but I don't know if Access can do IF unctions. So if the result in Frequency is 10, then the calculated field would read 7-13.

Any suggestions, Thanks.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi,

You can use IIF like Excel's If in an expression.

But I think you might need to do this through a UDF, like:

Code:
Function ranger(ByVal Numb As Integer)

Select Case Numb
    Case 1
        ranger = 1
    Case 2
        ranger = 2
    Case 3 To 6
        ranger = "3-6"
    Case 7 To 13
        ranger = "7-13"
    Case 14 To 29
        ranger = "14-29"
    Case Is >= 30
        ranger = "30+"
End Select

End Function

Insert this code in a standard module and use like any other function in Access, ie create query, add field you need to perform expression on, and in the next field in the query, put
Code:
Range: ranger([MyField])

HTH,
 
Upvote 0
Hi Corticus,
I did as you wrote and added the code to a module. And added the calculated field next to the field I am looking up, but it did not work. I followed your post to the T.

Am I suppose to name the module any particular name and the field in the ranger([myrange]), is "[my range]" supposed to be re-named to Frequency.

Thanks
 
Upvote 0
ranger() is a new function. You use it like any other function in Access. If you would like to perform a calculation on a field, make a query with the table the field is in, create a new field in the query and type in this:

Range: ranger([Frequency])

You do not need to name the module anything special.

If you need more help, pm me you e-mail and I'll send you an example.

HTH,
 
Upvote 0
Hi Corticus,

Thanks for your help. What I ended up doing was using an if function, but I forgot that in access you have to write it "IIF".

Thanks
 
Upvote 0
That is awesome!

This is about the coolest little trick I've seen in a while. That ranger function works great!
 
Upvote 0

Forum statistics

Threads
1,221,876
Messages
6,162,567
Members
451,775
Latest member
Aiden Jenner

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