PC Review


Reply
Thread Tools Rate Thread

Coditional IIf with an AND/OR statement

 
 
theref147
Guest
Posts: n/a
 
      22nd May 2010
Trying to get a query to determine a tax rate based on the province on a
record.
It should look at the [Prov] field and based on what is in that field come
up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
Service]>2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
Service]>2010/06/30,.12,.05) or something of this nature. I am not sure how
to write the formula could someone help.
 
Reply With Quote
 
 
 
 
Douglas J. Steele
Guest
Posts: n/a
 
      22nd May 2010
You may find it easier to write a function and pass the Province and Date as
parameters to the function...

Reading between the lines, try something like:

Switch([Prov] = 'BC', IIf([Date of Service] > #2010-06-30#, .12, .05),
[Prov] = 'ON', IIf([Date of Service] > #2010-06-30#, .13, .05),

....
)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"theref147" <(E-Mail Removed)> wrote in message
news:B83D5C69-7F90-4B6C-ADFE-(E-Mail Removed)...
> Trying to get a query to determine a tax rate based on the province on a
> record.
> It should look at the [Prov] field and based on what is in that field come
> up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
> Service]>2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
> Service]>2010/06/30,.12,.05) or something of this nature. I am not sure
> how
> to write the formula could someone help.



 
Reply With Quote
 
KARL DEWEY
Guest
Posts: n/a
 
      22nd May 2010
I think your best and easiest method is to create a RateTable of criteria and
tax rate like this --
Prov RateStart RateEnd Rate
ON 6/30/2010 0.0415
BC 6/30/2010 0.049
ON 5/10/2010 6/30/2010 0.0415
BC 4/23/2010 6/30/2010 0.049

And then this IIF statement ---
IIF([YourTable].[Prov] = [RateTable].[Prov] AND [YourTable].[Date of
Service] Between [RateTable].[RateStart] AND Nz([RateTable].[RateEnd],
#12/31/9999#)


--
Build a little, test a little.


"theref147" wrote:

> Trying to get a query to determine a tax rate based on the province on a
> record.
> It should look at the [Prov] field and based on what is in that field come
> up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
> Service]>2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
> Service]>2010/06/30,.12,.05) or something of this nature. I am not sure how
> to write the formula could someone help.

 
Reply With Quote
 
theref147
Guest
Posts: n/a
 
      23rd May 2010
I tried to copy this into the query but kept comming up with invalide use of
] or !. Can this also do the other provinces within the same field? This
field name is TaxRate.

"Douglas J. Steele" wrote:

> You may find it easier to write a function and pass the Province and Date as
> parameters to the function...
>
> Reading between the lines, try something like:
>
> Switch([Prov] = 'BC', IIf([Date of Service] > #2010-06-30#, .12, .05),
> [Prov] = 'ON', IIf([Date of Service] > #2010-06-30#, .13, .05),
>
> ....
> )
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "theref147" <(E-Mail Removed)> wrote in message
> news:B83D5C69-7F90-4B6C-ADFE-(E-Mail Removed)...
> > Trying to get a query to determine a tax rate based on the province on a
> > record.
> > It should look at the [Prov] field and based on what is in that field come
> > up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
> > Service]>2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
> > Service]>2010/06/30,.12,.05) or something of this nature. I am not sure
> > how
> > to write the formula could someone help.

>
>
> .
>

 
Reply With Quote
 
theref147
Guest
Posts: n/a
 
      23rd May 2010
Thank you. But I need this in a query with 7 Provinces and each changeing
rates as of 2010/06/30. NO luck with trying to copy and paste the function
into the equation builder - I am a rookie at this so I need more help if
possible.

"Douglas J. Steele" wrote:

> You may find it easier to write a function and pass the Province and Date as
> parameters to the function...
>
> Reading between the lines, try something like:
>
> Switch([Prov] = 'BC', IIf([Date of Service] > #2010-06-30#, .12, .05),
> [Prov] = 'ON', IIf([Date of Service] > #2010-06-30#, .13, .05),
>
> ....
> )
>
> --
> Doug Steele, Microsoft Access MVP
> http://I.Am/DougSteele
> (no private e-mails, please)
>
>
> "theref147" <(E-Mail Removed)> wrote in message
> news:B83D5C69-7F90-4B6C-ADFE-(E-Mail Removed)...
> > Trying to get a query to determine a tax rate based on the province on a
> > record.
> > It should look at the [Prov] field and based on what is in that field come
> > up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
> > Service]>2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
> > Service]>2010/06/30,.12,.05) or something of this nature. I am not sure
> > how
> > to write the formula could someone help.

>
>
> .
>

 
Reply With Quote
 
Douglas J. Steele
Guest
Posts: n/a
 
      23rd May 2010
Hopefully you realize that the ... in there was to indicate it wasn't
complete.

Your Switch statement can be expanded for as many provinces as you like:

Switch([Prov] = 'BC', aaaa, [Prov] = 'AB', bbbb, [Prov] = 'SK', cccc, [Prov]
= 'MB', dddd, [Prov] = 'ON', eeee, [Prov] = 'QC', ffff, [Prov] = 'NB', gggg,
[Prov] = 'NS', hhhh, [Prov] = 'PE', iiii, [Prov] = 'NL', jjjj)

For those provinces that aren't getting HST, bbbb, cccc, etc can simply be
the PST rate. For those provinces that are getting HST, aaaa, eeee, etc will
be an IIf statement that decides whether to use the old PST rate or the new
HST rate.

On the other hand, having the data in a table (as Karl suggested) or calling
a function (as I originally suggested) is a far better approach.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


"theref147" <(E-Mail Removed)> wrote in message
news:80E08C1E-D0E9-4554-9761-(E-Mail Removed)...
> Thank you. But I need this in a query with 7 Provinces and each changeing
> rates as of 2010/06/30. NO luck with trying to copy and paste the
> function
> into the equation builder - I am a rookie at this so I need more help if
> possible.
>
> "Douglas J. Steele" wrote:
>
>> You may find it easier to write a function and pass the Province and Date
>> as
>> parameters to the function...
>>
>> Reading between the lines, try something like:
>>
>> Switch([Prov] = 'BC', IIf([Date of Service] > #2010-06-30#, .12, .05),
>> [Prov] = 'ON', IIf([Date of Service] > #2010-06-30#, .13, .05),
>>
>> ....
>> )
>>
>> --
>> Doug Steele, Microsoft Access MVP
>> http://I.Am/DougSteele
>> (no private e-mails, please)
>>
>>
>> "theref147" <(E-Mail Removed)> wrote in message
>> news:B83D5C69-7F90-4B6C-ADFE-(E-Mail Removed)...
>> > Trying to get a query to determine a tax rate based on the province on
>> > a
>> > record.
>> > It should look at the [Prov] field and based on what is in that field
>> > come
>> > up with the corresponding tax rate. eg IIf ([Prov]= "ON" and [Date of
>> > Service]>2010/06/30,.13,.05, OR IIf ([Prov]="BC" and [Date of
>> > Service]>2010/06/30,.12,.05) or something of this nature. I am not
>> > sure
>> > how
>> > to write the formula could someone help.

>>
>>
>> .
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Coditional Format John Moore Microsoft Excel Misc 4 23rd Jul 2008 01:24 PM
Coditional Formatting Matt Microsoft Access 3 2nd Feb 2007 04:20 AM
Coditional formatting Russ Kroeger Microsoft Access Reports 7 12th May 2005 05:38 PM
coditional formatting =?Utf-8?B?Sm9obiBLbm9rZQ==?= Microsoft Excel Worksheet Functions 5 17th Apr 2005 08:21 PM
CODITIONAL FORMATTING =?Utf-8?B?Q2hyaXM=?= Microsoft Excel Programming 2 10th Mar 2005 03:01 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:37 AM.