IIF Statement Trouble

skumar14

New Member
Joined
Nov 7, 2014
Messages
10
Hello,

I was hoping someone could help me with this problem or let me know if it isn't possible. I have three fields Contract Number, Sustainable, and Total Amount. The sustainable field is a flag with 0 or 1. In my data set i keep on getting duplicates for the contract number because in some instances the flag is 0 and others its 1. I would like to create a new field "Final sustainable field" with the IIF statement that says if the contract number has the flag of 0 and 1 then make it 1 and leave all the other values as is. Is this possible, any help would be appreciated.

Thanks!
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I am not sure it is quite clear what you are trying to do. Could you post a small data sample, and then a sample of what your expected result from that sample data should look like?

Note that you can copy and paste from the query grid to get Access images here.

For example:

MainRejectReturnExpr1
8/27/201410/21/201410/22/20140
1/24/20151/25/2015

2/17/20154/18/2015


<tbody>
</tbody>
 
Upvote 0
Yes I'm sorry you're right that does sound confusing. As you can see in the bottom of the data set there are two identical contracts but one has the sustainable flag at 1 and the other at 0. I would like to create a new field "Final Sustainable" that says if the contract number's sustainable flag equals 1 and 0, then mark it as 1 and if not then mark it as 0.

Contract NumberSustainableFinal SustainableTotal Amount
79671 $287,453.30
81811 $61,953.78
82381 $4,318,130.33
82671 $276,700.94
82670 $3,621.32

<colgroup><col span="3"><col></colgroup><tbody>
</tbody>
 
Upvote 0
OK, that's the "before" picture. Can you show me you desired "after" picture?

And a few other questions:
- What do you want to happen with Contract Numbers only have one record, and it has a 0 is Sustainable?
- Can a given Contract Number have more than one record that has a 1 is Sustainable, or more than one record with 0 is Sustainable?
If so, how should those be handled?
 
Upvote 0
Afterwards i'd like it to look like this(below). For the contract number that has one record i'd like it to keep its original flag. For example at the end of the dataset the one contract with the zero flag I want its final sustainable to be zero as well. And a contract number wouldn't have more than one record that has a 1 and a 0. The contract would either have one record with 1 or 0 or it would have two records with 1 AND 0.

Contract NumberSustainableFinal SustainableTotal Amount
796711$287,453.30
818111$61,953.78
823811$4,318,130.33
826711$276,700.94
826701$3,621.32
794600$3,495.60

<colgroup><col span="3"><col></colgroup><tbody>
</tbody>

<tbody>
</tbody>
 
Upvote 0
You can create a calculated field in a query to get this. You can use the DMAX function to pull the maximum value of Sustainable for each Contract Number, i.e.
Code:
Final Sustainable: DMax("Sustainable","TableName","[Contract Number] =" & [Contract Number])
Here is a explanation of the DMAX function: MS Access: DMax Function
 
Upvote 0
I keep on trying but it just keeps running and either crashes or just won't stop querying. Maybe written it incorrectly?

Code: DMax("MfrContractSustainability","qSS0203SustainabilitySpendContactStatusRollupMFR","[Mfr_Contract_ID] =" & [MFR_CONTRACT_ID])
 
Upvote 0
Is your MFR_CONTRACT_ID field a text field or numeric field?
 
Upvote 0
OK, so I can duplicate your scenario, please do the following.
Create a basic query, where you just add your table and add the Contact Number, Sustainable, and Total Amount fields.
Then switch your query to SQL View, and copy and paste the SQL code from that query here.
 
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