IIF statment?

CThai

Active Member
Joined
Mar 18, 2007
Messages
295
Hello -

I'm not sure how to go about doing this --- I have a table and in the table i have a field name called "Type of useage" and there are 10 different type of usage (NNBC, OBD, IIS, IBSD,ORGIS, OTHER, etc..) 4 of these usage are for 5yrs time and the rest are for 10yrs time - is there a way i can create a new field and say IFF NNBC, and OBD and IIS put it in 5yrs time... and the rest put it in 10yrs time fields?


thank you!
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
In your table, go to the design view and add the new field. Save and close the table. Now create a new query. Start off with it being a simple select query using the table. Include the "Type of useage" field and your new field and in a blank column, type this:
ValueTest: iif([Type of useage] in ('NNBC','OBD','IIS'), 5,10)
Run the query and if you're happy with the results, change it to an update query putting the iif statement in the Update To line of the update query. Run this update query and your table will be updated.

Note: you'll need to put the exact 4 values you're wanting to repesent as 5 years.

Hope this helps...
Phil...
 
Upvote 0
Run the query and if you're happy with the results, change it to an update query putting the iif statement in the Update To line of the update query. Run this update query and your table will be updated.
Usually, it is not necessary to do this, and doing so can actually violate the rules of data normalization.

Typically, a field that is dependent upon another field (i.e. is calculated or can be determined by the value in another field) should NOT be stored in a table. It should be determined in the query, and left at that. There usually isn't a need to write it to a table (unless you are creating some sort of historical table).

If it can be determined in the query, there is usually no need to write it back to the table. Queries can be used as the sources of Forms, Reports, Exports, etc. The danger in writing it back to the table is that you can undermine the data intergrity and dynamic nature of the table and database.

For example, what happens if you write it back to the table, but then somewhere down the road, someone changes the "usage" field on one of the records, but doesn't update the corresponding calculated field? Now you have bad data in your system. If left as a query calculation, the data changes will automatically be reflected in the calculated value too.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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