nested iif

L

lmw

trying to use iif and between...something is wrong..

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
= -120 And <-90, "(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
<-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And <-30,"(60)-(31)â€,
iif([DaysBetwSt-Rpt] >= -30 And< -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt] >=
-15 And 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And <16,"0-15â€,
iif([DaysBetwSt-Rpt] >=16 And <31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31 And <=
61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And <91,"61-90â€,
iif([DaysBetwSt-Rpt] >= 91 And <121,"91-120â€, iif([DaysBetwSt-Rpt] >= 121
And <151,"121-150â€, iif([DaysBetwSt-Rpt]>= 151 And <181,"151-180â€,
iif([DaysBetwSt-Rpt] >= 181 And <211,"181-210â€, "211+")))))))))))))))))
 
K

KARL DEWEY

I did not go over the whole thing but I see error in first part --
=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
<-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And < -150,"(180)-(151)â€,

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
[DaysBetwSt-Rpt] <-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€,

Get the drift?

--
KARL DEWEY
Build a little - Test a little


lmw said:
trying to use iif and between...something is wrong..

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
= -120 And <-90, "(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
<-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And <-30,"(60)-(31)â€,
iif([DaysBetwSt-Rpt] >= -30 And< -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt] >=
-15 And 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And <16,"0-15â€,
iif([DaysBetwSt-Rpt] >=16 And <31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31 And <=
61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And <91,"61-90â€,
iif([DaysBetwSt-Rpt] >= 91 And <121,"91-120â€, iif([DaysBetwSt-Rpt] >= 121
And <151,"121-150â€, iif([DaysBetwSt-Rpt]>= 151 And <181,"151-180â€,
iif([DaysBetwSt-Rpt] >= 181 And <211,"181-210â€, "211+")))))))))))))))))
 
L

lmw

I get it...thanks! But I'm still getting an invalid syntax error:

=iif([DaysBetwSt-Rpt] < -180, “<-180â€, iif([DaysBetwSt-Rpt] >= -180 And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€, iif([DaysBetwSt-Rpt] >= -150 And
[DaysBetwSt-Rpt] <-120,"(150)-(121)â€, iif([DaysBetwSt-Rpt] >= -120 And
[DaysBetwSt-Rpt] <-90,"(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
[DaysBetwSt-Rpt] <-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And
[DaysBetwSt-Rpt] <-30,"(60)-(31)â€, iif([DaysBetwSt-Rpt] >= -30 And
[DaysBetwSt-Rpt] < -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt] >= -15 And
[DaysBetwSt-Rpt] < 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And
[DaysBetwSt-Rpt] < 16,"0-15â€, iif([DaysBetwSt-Rpt] >=16 And
[DaysBetwSt-Rpt] < 31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31 And
[DaysBetwSt-Rpt] < 61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And
[DaysBetwSt-Rpt] < 91,"61-90â€, iif([DaysBetwSt-Rpt] >= 91 And
[DaysBetwSt-Rpt] <121,"91-120â€, iif([DaysBetwSt-Rpt] >= 121 And
[DaysBetwSt-Rpt] <151,"121-150â€, iif([DaysBetwSt-Rpt] >= 151 And
[DaysBetwSt-Rpt] <181,"151-180â€, "181+")))))))))))))))

Thanks!!

KARL DEWEY said:
I did not go over the whole thing but I see error in first part --
=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
<-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And < -150,"(180)-(151)â€,

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
[DaysBetwSt-Rpt] <-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€,

Get the drift?

--
KARL DEWEY
Build a little - Test a little


lmw said:
trying to use iif and between...something is wrong..

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
= -120 And <-90, "(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
<-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And <-30,"(60)-(31)â€,
iif([DaysBetwSt-Rpt] >= -30 And< -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt] >=
-15 And 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And <16,"0-15â€,
iif([DaysBetwSt-Rpt] >=16 And <31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31 And <=
61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And <91,"61-90â€,
iif([DaysBetwSt-Rpt] >= 91 And <121,"91-120â€, iif([DaysBetwSt-Rpt] >= 121
And <151,"121-150â€, iif([DaysBetwSt-Rpt]>= 151 And <181,"151-180â€,
iif([DaysBetwSt-Rpt] >= 181 And <211,"181-210â€, "211+")))))))))))))))))
 
B

BruceM

I don't think you need all of those "ANDs". As soon as a value passes the
logical test the text is returned. Maybe something like this will work.

=iif([DaysBetwSt-Rpt] < -180, “<-180â€,
iif([DaysBetwSt-Rpt] < -150,"(180)-(151)â€,
iif([DaysBetwSt-Rpt] <-120,"(150)-(121)â€, etc.

If this expression is in a query or a text box control source, be sure there
are no line breaks. If the expression is in VBA, line breaks need an
underscore character. If you are in VBA you would probably do better with
Select Case.

Another option may be the Switch function. Help has more information, but
in general it's something like:
=Switch([DaysBetwSt-Rpt] < -180,"<-180)",[DaysBetwSt-Rpt]
< -150,"(180)-(151)",
[DaysBetwSt-Rpt] < -120,"(150)-(121)â€, [DaysBetwSt-Rpt] > -121,"-121+")

If you are still having troubles with this, test for one value (-180) with a
single IIf. If that works as intended, add another value, and test again.
Build the expression in this way and any difficulties will be easier to
pinpoint.

lmw said:
I get it...thanks! But I'm still getting an invalid syntax error:

=iif([DaysBetwSt-Rpt] < -180, “<-180â€, iif([DaysBetwSt-Rpt] >= -180 And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€, iif([DaysBetwSt-Rpt] >= -150 And
[DaysBetwSt-Rpt] <-120,"(150)-(121)â€, iif([DaysBetwSt-Rpt] >= -120 And
[DaysBetwSt-Rpt] <-90,"(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
[DaysBetwSt-Rpt] <-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And
[DaysBetwSt-Rpt] <-30,"(60)-(31)â€, iif([DaysBetwSt-Rpt] >= -30 And
[DaysBetwSt-Rpt] < -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt] >= -15 And
[DaysBetwSt-Rpt] < 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And
[DaysBetwSt-Rpt] < 16,"0-15â€, iif([DaysBetwSt-Rpt] >=16 And
[DaysBetwSt-Rpt] < 31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31 And
[DaysBetwSt-Rpt] < 61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And
[DaysBetwSt-Rpt] < 91,"61-90â€, iif([DaysBetwSt-Rpt] >= 91 And
[DaysBetwSt-Rpt] <121,"91-120â€, iif([DaysBetwSt-Rpt] >= 121 And
[DaysBetwSt-Rpt] <151,"121-150â€, iif([DaysBetwSt-Rpt] >= 151 And
[DaysBetwSt-Rpt] <181,"151-180â€, "181+")))))))))))))))

Thanks!!

KARL DEWEY said:
I did not go over the whole thing but I see error in first part --
=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
<-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
< -150,"(180)-(151)â€,

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
[DaysBetwSt-Rpt] <-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€,

Get the drift?

--
KARL DEWEY
Build a little - Test a little


lmw said:
trying to use iif and between...something is wrong..

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
<-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
< -150,"(180)-(151)â€,
iif([DaysBetwSt-Rpt] >= -150 And <-120,"(150)-(121)â€,
iif([DaysBetwSt-Rpt]
= -120 And <-90, "(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
<-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And <-30,"(60)-(31)â€,
iif([DaysBetwSt-Rpt] >= -30 And< -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt]
=
-15 And 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And <16,"0-15â€,
iif([DaysBetwSt-Rpt] >=16 And <31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31
And <=
61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And <91,"61-90â€,
iif([DaysBetwSt-Rpt] >= 91 And <121,"91-120â€, iif([DaysBetwSt-Rpt] >=
121
And <151,"121-150â€, iif([DaysBetwSt-Rpt]>= 151 And <181,"151-180â€,
iif([DaysBetwSt-Rpt] >= 181 And <211,"181-210â€,
"211+")))))))))))))))))
 
K

KARL DEWEY

With a very large set of IIF nested like this I use a translation table.
Low High Display
-9999999 -180 <-180
-180 -150 <180-151
-150 -120 <150-121
-120 -90 <120-91
-90 -60 <90-61
-60 -30 <60-31
-30 -15 <30-16
-15 0 <15 -1
0 16 0-15
16 31 16-30
31 61 31-60
61 91 61-90
91 121 91-120
121 151 121-150
151 181 151-180
180 9999999 181+

Then in the query add the translation table. Add field DaysBetw: [Display]
and in the field row below DaysBetwSt-Rpt enter criteria like this --
=[Low] AND <[High]

--
KARL DEWEY
Build a little - Test a little


BruceM said:
I don't think you need all of those "ANDs". As soon as a value passes the
logical test the text is returned. Maybe something like this will work.

=iif([DaysBetwSt-Rpt] < -180, “<-180â€,
iif([DaysBetwSt-Rpt] < -150,"(180)-(151)â€,
iif([DaysBetwSt-Rpt] <-120,"(150)-(121)â€, etc.

If this expression is in a query or a text box control source, be sure there
are no line breaks. If the expression is in VBA, line breaks need an
underscore character. If you are in VBA you would probably do better with
Select Case.

Another option may be the Switch function. Help has more information, but
in general it's something like:
=Switch([DaysBetwSt-Rpt] < -180,"<-180)",[DaysBetwSt-Rpt]
< -150,"(180)-(151)",
[DaysBetwSt-Rpt] < -120,"(150)-(121)â€, [DaysBetwSt-Rpt] > -121,"-121+")

If you are still having troubles with this, test for one value (-180) with a
single IIf. If that works as intended, add another value, and test again.
Build the expression in this way and any difficulties will be easier to
pinpoint.

lmw said:
I get it...thanks! But I'm still getting an invalid syntax error:

=iif([DaysBetwSt-Rpt] < -180, “<-180â€, iif([DaysBetwSt-Rpt] >= -180 And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€, iif([DaysBetwSt-Rpt] >= -150 And
[DaysBetwSt-Rpt] <-120,"(150)-(121)â€, iif([DaysBetwSt-Rpt] >= -120 And
[DaysBetwSt-Rpt] <-90,"(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
[DaysBetwSt-Rpt] <-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And
[DaysBetwSt-Rpt] <-30,"(60)-(31)â€, iif([DaysBetwSt-Rpt] >= -30 And
[DaysBetwSt-Rpt] < -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt] >= -15 And
[DaysBetwSt-Rpt] < 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And
[DaysBetwSt-Rpt] < 16,"0-15â€, iif([DaysBetwSt-Rpt] >=16 And
[DaysBetwSt-Rpt] < 31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31 And
[DaysBetwSt-Rpt] < 61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And
[DaysBetwSt-Rpt] < 91,"61-90â€, iif([DaysBetwSt-Rpt] >= 91 And
[DaysBetwSt-Rpt] <121,"91-120â€, iif([DaysBetwSt-Rpt] >= 121 And
[DaysBetwSt-Rpt] <151,"121-150â€, iif([DaysBetwSt-Rpt] >= 151 And
[DaysBetwSt-Rpt] <181,"151-180â€, "181+")))))))))))))))

Thanks!!

KARL DEWEY said:
I did not go over the whole thing but I see error in first part --
=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
<-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
< -150,"(180)-(151)â€,

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
[DaysBetwSt-Rpt] <-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€,

Get the drift?

--
KARL DEWEY
Build a little - Test a little


:

trying to use iif and between...something is wrong..

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210 And
<-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
< -150,"(180)-(151)â€,
iif([DaysBetwSt-Rpt] >= -150 And <-120,"(150)-(121)â€,
iif([DaysBetwSt-Rpt]
= -120 And <-90, "(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
<-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And <-30,"(60)-(31)â€,
iif([DaysBetwSt-Rpt] >= -30 And< -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt]
=
-15 And 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And <16,"0-15â€,
iif([DaysBetwSt-Rpt] >=16 And <31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31
And <=
61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And <91,"61-90â€,
iif([DaysBetwSt-Rpt] >= 91 And <121,"91-120â€, iif([DaysBetwSt-Rpt] >=
121
And <151,"121-150â€, iif([DaysBetwSt-Rpt]>= 151 And <181,"151-180â€,
iif([DaysBetwSt-Rpt] >= 181 And <211,"181-210â€,
"211+")))))))))))))))))
 
B

BruceM

That's pretty cool. I can foresee uses for this approach. Select Case
often is better than IIf for complex statements, but can get clunky and
complex when there are a lot of choices.

KARL DEWEY said:
With a very large set of IIF nested like this I use a translation table.
Low High Display
-9999999 -180 <-180
-180 -150 <180-151
-150 -120 <150-121
-120 -90 <120-91
-90 -60 <90-61
-60 -30 <60-31
-30 -15 <30-16
-15 0 <15 -1
0 16 0-15
16 31 16-30
31 61 31-60
61 91 61-90
91 121 91-120
121 151 121-150
151 181 151-180
180 9999999 181+

Then in the query add the translation table. Add field DaysBetw:
[Display]
and in the field row below DaysBetwSt-Rpt enter criteria like this --
=[Low] AND <[High]

--
KARL DEWEY
Build a little - Test a little


BruceM said:
I don't think you need all of those "ANDs". As soon as a value passes
the
logical test the text is returned. Maybe something like this will work.

=iif([DaysBetwSt-Rpt] < -180, “<-180â€,
iif([DaysBetwSt-Rpt] < -150,"(180)-(151)â€,
iif([DaysBetwSt-Rpt] <-120,"(150)-(121)â€, etc.

If this expression is in a query or a text box control source, be sure
there
are no line breaks. If the expression is in VBA, line breaks need an
underscore character. If you are in VBA you would probably do better
with
Select Case.

Another option may be the Switch function. Help has more information,
but
in general it's something like:
=Switch([DaysBetwSt-Rpt] < -180,"<-180)",[DaysBetwSt-Rpt]
< -150,"(180)-(151)",
[DaysBetwSt-Rpt] < -120,"(150)-(121)â€, [DaysBetwSt-Rpt] > -121,"-121+")

If you are still having troubles with this, test for one value (-180)
with a
single IIf. If that works as intended, add another value, and test
again.
Build the expression in this way and any difficulties will be easier to
pinpoint.

lmw said:
I get it...thanks! But I'm still getting an invalid syntax error:

=iif([DaysBetwSt-Rpt] < -180, “<-180â€, iif([DaysBetwSt-Rpt] >= -180 And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€, iif([DaysBetwSt-Rpt] >= -150
And
[DaysBetwSt-Rpt] <-120,"(150)-(121)â€, iif([DaysBetwSt-Rpt] >= -120 And
[DaysBetwSt-Rpt] <-90,"(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
[DaysBetwSt-Rpt] <-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And
[DaysBetwSt-Rpt] <-30,"(60)-(31)â€, iif([DaysBetwSt-Rpt] >= -30 And
[DaysBetwSt-Rpt] < -15,"(30)-(16)â€, iif([DaysBetwSt-Rpt] >= -15 And
[DaysBetwSt-Rpt] < 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And
[DaysBetwSt-Rpt] < 16,"0-15â€, iif([DaysBetwSt-Rpt] >=16 And
[DaysBetwSt-Rpt] < 31,"16-30â€, iif([DaysBetwSt-Rpt] >= 31 And
[DaysBetwSt-Rpt] < 61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And
[DaysBetwSt-Rpt] < 91,"61-90â€, iif([DaysBetwSt-Rpt] >= 91 And
[DaysBetwSt-Rpt] <121,"91-120â€, iif([DaysBetwSt-Rpt] >= 121 And
[DaysBetwSt-Rpt] <151,"121-150â€, iif([DaysBetwSt-Rpt] >= 151 And
[DaysBetwSt-Rpt] <181,"151-180â€, "181+")))))))))))))))

Thanks!!

:

I did not go over the whole thing but I see error in first part --
=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210
And
<-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
< -150,"(180)-(151)â€,

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210
And
[DaysBetwSt-Rpt] <-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180
And
[DaysBetwSt-Rpt] < -150,"(180)-(151)â€,

Get the drift?

--
KARL DEWEY
Build a little - Test a little


:

trying to use iif and between...something is wrong..

=iif([DaysBetwSt-Rpt] < -210, “<-210â€, iif([DaysBetwSt-Rpt] >= -210
And
<-180, "(210)-(181)", iif([DaysBetwSt-Rpt] >= -180 And
< -150,"(180)-(151)â€,
iif([DaysBetwSt-Rpt] >= -150 And <-120,"(150)-(121)â€,
iif([DaysBetwSt-Rpt]
= -120 And <-90, "(120)-(91)â€, iif([DaysBetwSt-Rpt] >= -90 And
<-60,"(90)-(61)â€, iif([DaysBetwSt-Rpt] >= -60 And <-30,"(60)-(31)â€,
iif([DaysBetwSt-Rpt] >= -30 And< -15,"(30)-(16)â€,
iif([DaysBetwSt-Rpt]
=
-15 And 0, "(15)-(1)â€, iif([DaysBetwSt-Rpt] >= 0 And <16,"0-15â€,
iif([DaysBetwSt-Rpt] >=16 And <31,"16-30â€, iif([DaysBetwSt-Rpt] >=
31
And <=
61,"31-60â€, iif([DaysBetwSt-Rpt] >= 61 And <91,"61-90â€,
iif([DaysBetwSt-Rpt] >= 91 And <121,"91-120â€, iif([DaysBetwSt-Rpt]
=
121
And <151,"121-150â€, iif([DaysBetwSt-Rpt]>= 151 And <181,"151-180â€,
iif([DaysBetwSt-Rpt] >= 181 And <211,"181-210â€,
"211+")))))))))))))))))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top