Query

mardimus

New Member
Joined
Feb 2, 2015
Messages
21
I have a query that has three columns, Date1, Date2, and Date3. What I want to do is use an IF statement to create a new column based on the greater value of two of those dates out of the three. In my query design would I use a "display text", IIF, etc. Please share your knowledge.

Here is the logic....

IF(Date2="",IF(Date1="",Date3,Date1),Date2)

So the output of the statement would create a new column. Column 1 - Date1, Column 2 - Date2, Column 3 - Date3, Column 4 - output of statement!

Thanks for looking.
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
This is the statement I first used in the builder...
Past Due RFU: IF([Cur RFU]="",IF([Pla RFU]="",[Act RFU],[Pla RFU]),[Cur RFU])

I got an error that the If expression is not defined.

So I changed the statement to: Past Due RFU: IIF([Cur RFU]="",IIF([Pla RFU]="",[Act RFU],[Pla RFU]),[Cur RFU])

And it runs but I have errors in the fields or blank fields.
 
Upvote 0
And it runs but I have errors in the fields or blank fields.
Note that Null and blank values are handled differently in Access.
But I think that would just return unexpected results and not errors.
Can you post some data examples and expected results?
 
Upvote 0
Thanks for the response. I am still a little new to access but so far its been great learning. Here is a pic of the query output.

6X7OpjwkPm2kvHIwaKMVTs9bgh0gvw4xdgrlxqgPMlQ=w663-h699-no




Note that Null and blank values are handled differently in Access.
But I think that would just return unexpected results and not errors.
Can you post some data examples and expected results?
 
Upvote 0
Try this instead:
Code:
Past Due RFU: IIf(IsNull([Cur RFU]),IIf(IsNull([Pla RFU]),[Act RFU],[Pla RFU]),[Cur RFU])
 
Upvote 0
Glad to help!

I think "" works with String (Text) values, but not dates and numbers. That is where ISNULL comes in handy.
 
Upvote 0
Yes, and this is where I am learning. I even tried Null, but not IsNull. Thanks for the help again. Saved me a lot of time and I learned something very useful. Cheers.


Glad to help!

I think "" works with String (Text) values, but not dates and numbers. That is where ISNULL comes in handy.
 
Upvote 0
Another little tip while we are on the topic of Nulls. A real helpful function is NZ, which you can use to convert a Null to a value. If the field is not Null, it just returns the value. See: MS Access: Nz Function
 
Upvote 0
Thank you for the link, it is most helpful. I will play with it or use it on the cells where I do not have a value. There were a few in the DB. Thanks



Another little tip while we are on the topic of Nulls. A real helpful function is NZ, which you can use to convert a Null to a value. If the field is not Null, it just returns the value. See: MS Access: Nz Function
 
Upvote 0

Forum statistics

Threads
1,221,893
Messages
6,162,659
Members
451,780
Latest member
Blake86

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