Tuesday, March 20, 2012
Compound IIF Statement
=Iif(DateDiff("d", Fields!TranDate.Value, Parameters!AgeDate.Value) > 30 &
DateDiff("d", Fields!TranDate.Value, Parameters!AgeDate.Value) < 61,
Fields!Amount.Value, "")
The purpose of the above statement is to print the "Amount.Value" if the #
of days is greater than 30 and less than 61. The problem is that it prints
the value "Amount.Value" and ignores the actual # of days. IE, if the
difference in the dates is 15, "Amount.Value" is printed. Is this syntax
correct? Can you have compound statements using DateDiff?
Thanks,
JohnYou are using & instead of AND. & is appending the two values together
instead of doing a boolean compare.
Oh, you can definitely have compound iif statements but you are not doing
that. A compound iif would be iif(some boolean expression, true value,
iif(blah, blah, blah))
--
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"John Joslin" <JohnJoslin@.discussions.microsoft.com> wrote in message
news:945474CD-1373-43E4-AD35-01DBCF3671FF@.microsoft.com...
> The compound statement:
> =Iif(DateDiff("d", Fields!TranDate.Value, Parameters!AgeDate.Value) > 30 &
> DateDiff("d", Fields!TranDate.Value, Parameters!AgeDate.Value) < 61,
> Fields!Amount.Value, "")
> The purpose of the above statement is to print the "Amount.Value" if the #
> of days is greater than 30 and less than 61. The problem is that it prints
> the value "Amount.Value" and ignores the actual # of days. IE, if the
> difference in the dates is 15, "Amount.Value" is printed. Is this syntax
> correct? Can you have compound statements using DateDiff?
> Thanks,
> John|||Thanks Bruce! It works very nicely now...
"Bruce L-C [MVP]" wrote:
> You are using & instead of AND. & is appending the two values together
> instead of doing a boolean compare.
> Oh, you can definitely have compound iif statements but you are not doing
> that. A compound iif would be iif(some boolean expression, true value,
> iif(blah, blah, blah))
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "John Joslin" <JohnJoslin@.discussions.microsoft.com> wrote in message
> news:945474CD-1373-43E4-AD35-01DBCF3671FF@.microsoft.com...
> > The compound statement:
> >
> > =Iif(DateDiff("d", Fields!TranDate.Value, Parameters!AgeDate.Value) > 30 &
> > DateDiff("d", Fields!TranDate.Value, Parameters!AgeDate.Value) < 61,
> > Fields!Amount.Value, "")
> >
> > The purpose of the above statement is to print the "Amount.Value" if the #
> > of days is greater than 30 and less than 61. The problem is that it prints
> > the value "Amount.Value" and ignores the actual # of days. IE, if the
> > difference in the dates is 15, "Amount.Value" is printed. Is this syntax
> > correct? Can you have compound statements using DateDiff?
> >
> > Thanks,
> >
> > John
>
>
compound iif query
= "SELECT * FROM "
& IIf(Parameters!ar.Value = "renewal", "vwRenewal", "vwOPL"
& " Where 0=0 "
& IIf(Parameters!ar.value = "renewal", "AND (IIf(boolExtension = 1),
(dateEXTENSIONDATE >= '" & Parameters!begindate.Value & "') AND
(dateEXTENSIONDATE <= '" & Parameters!enddate.Value & "'), "")", "")
There is a lot more to this query, but basicaly everything works except the
above line. I want to say that if the ar=renewal and the boolextension is 1
then choose those dates, ortherwise choose everything as it should be. what
is wrong with this line I am getting an incorrect syntax error.The best way to track this down is to assign this to a textbox and see what
you get (I sometimes create a barebones report with only the parameters and
the textbox, no datasets). That is how I handle the problem.
Bruce L-C
"MallTLC" <MallTLC@.discussions.microsoft.com> wrote in message
news:FBC8D622-F1FD-40E2-AE97-12D9CB0EB608@.microsoft.com...
> I have the following query
> = "SELECT * FROM "
> & IIf(Parameters!ar.Value = "renewal", "vwRenewal", "vwOPL"
> & " Where 0=0 "
> & IIf(Parameters!ar.value = "renewal", "AND (IIf(boolExtension = 1),
> (dateEXTENSIONDATE >= '" & Parameters!begindate.Value & "') AND
> (dateEXTENSIONDATE <= '" & Parameters!enddate.Value & "'), "")", "")
> There is a lot more to this query, but basicaly everything works except
the
> above line. I want to say that if the ar=renewal and the boolextension is
1
> then choose those dates, ortherwise choose everything as it should be.
what
> is wrong with this line I am getting an incorrect syntax error.|||So I should be able to create compound iifs on the query page, correct.
"Bruce Loehle-Conger" wrote:
> The best way to track this down is to assign this to a textbox and see what
> you get (I sometimes create a barebones report with only the parameters and
> the textbox, no datasets). That is how I handle the problem.
> Bruce L-C
> "MallTLC" <MallTLC@.discussions.microsoft.com> wrote in message
> news:FBC8D622-F1FD-40E2-AE97-12D9CB0EB608@.microsoft.com...
> > I have the following query
> >
> > = "SELECT * FROM "
> >
> > & IIf(Parameters!ar.Value = "renewal", "vwRenewal", "vwOPL"
> >
> > & " Where 0=0 "
> >
> > & IIf(Parameters!ar.value = "renewal", "AND (IIf(boolExtension = 1),
> > (dateEXTENSIONDATE >= '" & Parameters!begindate.Value & "') AND
> > (dateEXTENSIONDATE <= '" & Parameters!enddate.Value & "'), "")", "")
> >
> > There is a lot more to this query, but basicaly everything works except
> the
> > above line. I want to say that if the ar=renewal and the boolextension is
> 1
> > then choose those dates, ortherwise choose everything as it should be.
> what
> > is wrong with this line I am getting an incorrect syntax error.
>
>|||Anything you can do with an expression you can do anywhere an expression is
used. Compounded iif's are 100% fine to do. They are confusing but fine. The
expression evaluation is no different if you are using it for the source of
a dataset or you are using it as the source of a textbox. So you can cut and
paste your expression into the source for a textbox. Right mouse click on
textbox, expression. Then paste the expression into the right side.
Bruce L-C
"MallTLC" <MallTLC@.discussions.microsoft.com> wrote in message
news:52404738-D383-4E63-B36A-23BE6E6B4EFB@.microsoft.com...
> So I should be able to create compound iifs on the query page, correct.
> "Bruce Loehle-Conger" wrote:
> > The best way to track this down is to assign this to a textbox and see
what
> > you get (I sometimes create a barebones report with only the parameters
and
> > the textbox, no datasets). That is how I handle the problem.
> >
> > Bruce L-C
> >
> > "MallTLC" <MallTLC@.discussions.microsoft.com> wrote in message
> > news:FBC8D622-F1FD-40E2-AE97-12D9CB0EB608@.microsoft.com...
> > > I have the following query
> > >
> > > = "SELECT * FROM "
> > >
> > > & IIf(Parameters!ar.Value = "renewal", "vwRenewal", "vwOPL"
> > >
> > > & " Where 0=0 "
> > >
> > > & IIf(Parameters!ar.value = "renewal", "AND (IIf(boolExtension = 1),
> > > (dateEXTENSIONDATE >= '" & Parameters!begindate.Value & "') AND
> > > (dateEXTENSIONDATE <= '" & Parameters!enddate.Value & "'), "")", "")
> > >
> > > There is a lot more to this query, but basicaly everything works
except
> > the
> > > above line. I want to say that if the ar=renewal and the
boolextension is
> > 1
> > > then choose those dates, ortherwise choose everything as it should be.
> > what
> > > is wrong with this line I am getting an incorrect syntax error.
> >
> >
> >
Sunday, March 11, 2012
Complicated IIF statements
We have some conditions that are required to be met to process the calculations. For the IIF , we have two conditions that are required to be true and also for two different fields.
There is a field called MEASURE which should be either "Discharges" OR "Panel Discharges".
There is another field called fiscal year which should be "TFY"
If the above conditions are met, then we want to SUM(Fields!Value.Numerator) but if the test fails then we want (Fields!Numerator.Value)/(Fields!NDenominator.Value)
I have tried :
=IIF(Fields!MEASURE.Value ="Panel Discharges", SUM(IIF(Fields!FiscalYear IS "TFY", Fields!Numerator.Value),(Fields!Numerator.Value)/(Fields!NDenominator.Value))
I tried other style of writing but failed.
Any help is appreciated!
I think there are two issues:
1. the outer IIF function call has only two arguments instead of the required three arguments
2. the conditional SUM aggregate can trigger a division by zero
I recommend to add a custom code function for the division (in Report -> Report Properties -> Code):
Public Function Divide(ByVal first As Double, ByVal second As Double) As Double
If second = 0 Then
Return 0
Else
Return first / second
End If
End Function
Then, modify the expression accordingly:
=IIF( (Fields!MEASURE.Value="Panel Discharges") OR (Fields!MEASURE.Value="Discharges"), SUM(IIF(Fields!FiscalYear="TFY", Fields!Numerator.Value, Code.Divide(Fields!Numerator.Value, Fields!NDenominator.Value))), 0)
-- Robert
Friday, February 24, 2012
Complex IIF statement not working
returned from the dataset in Data view, but when I attempt to show a table
based on at least one value being true (from several) it says:
"The hidden expression for the table 'table1' refers to the field
'SSFLunchRegular'. Report item expressions can only refer to fields within
the current data set scope..."
I can turn right around and show/hide a row of the table based on the exact
same field name and it works. The structure of my IIF statment appears to be
fine because the same structure works in another report. Is it the number of
conditions? Is there a limit?
Here are the conditions placed on the Hidden statement:
=IIF(
(FIELDS!SLPLunchRegular.Value <> 0) and
(FIELDS!SLPLunchProv1.Value <> 0) and
(FIELDS!SLPLunchProv2.Value <> 0) and
(FIELDS!SLPLunchProv3.Value <> 0) and
(FIELDS!SLPBkfstRegular.Value <> 0) and
(FIELDS!SLPBkfstProv1.Value <> 0) and
(FIELDS!SLPBkfstProv2.Value <> 0) and
(FIELDS!SLPBkfstProv3.Value <> 0) and
(FIELDS!SLPSevereRegular.Value <> 0) and
(FIELDS!SLPSevereProv1.Value <> 0) and
(FIELDS!SLPSevereProv2.Value <> 0) and
(FIELDS!SLPSevereProv3.Value <> 0) and
(FIELDS!SLPSnackArea.Value <> 0) and
(FIELDS!SLPSnackNonArea.Value <> 0), False, True
)
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200511/1oops, I wrote 'SSFLunchRegular', it should have been 'SLPLunchRegular'. The
misspelling was in this thread, not my code so the problem is not solved..
Rick wrote:
>I am not understanding what my issue is on this one! I can look at the data
>returned from the dataset in Data view, but when I attempt to show a table
>based on at least one value being true (from several) it says:
>"The hidden expression for the table 'table1' refers to the field
>'SSFLunchRegular'. Report item expressions can only refer to fields within
>the current data set scope..."
>I can turn right around and show/hide a row of the table based on the exact
>same field name and it works. The structure of my IIF statment appears to be
>fine because the same structure works in another report. Is it the number of
>conditions? Is there a limit?
>Here are the conditions placed on the Hidden statement:
>=IIF(
>(FIELDS!SLPLunchRegular.Value <> 0) and
>(FIELDS!SLPLunchProv1.Value <> 0) and
>(FIELDS!SLPLunchProv2.Value <> 0) and
>(FIELDS!SLPLunchProv3.Value <> 0) and
>(FIELDS!SLPBkfstRegular.Value <> 0) and
>(FIELDS!SLPBkfstProv1.Value <> 0) and
>(FIELDS!SLPBkfstProv2.Value <> 0) and
>(FIELDS!SLPBkfstProv3.Value <> 0) and
>(FIELDS!SLPSevereRegular.Value <> 0) and
>(FIELDS!SLPSevereProv1.Value <> 0) and
>(FIELDS!SLPSevereProv2.Value <> 0) and
>(FIELDS!SLPSevereProv3.Value <> 0) and
>(FIELDS!SLPSnackArea.Value <> 0) and
>(FIELDS!SLPSnackNonArea.Value <> 0), False, True
>)
--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200511/1|||The problem seems to be that you're attempting to hide a whole table based
on one single record. That wouldn't be logical. You'd need to aggregate the
values somehow, something like
=IIF(
(Sum(FIELDS!SLPLunchRegular.Value) <> 0) and
(Sum(FIELDS!SLPLunchProv1.Value) <> 0) and
...
...
Hope this helps.
--
Robert Jeppesen
Durius
http://www.durius.com/
"Rick via SQLMonster.com" <u15024@.uwe> wrote in message
news:5773f7edc9ca2@.uwe...
>I am not understanding what my issue is on this one! I can look at the
>data
> returned from the dataset in Data view, but when I attempt to show a table
> based on at least one value being true (from several) it says:
> "The hidden expression for the table 'table1' refers to the field
> 'SSFLunchRegular'. Report item expressions can only refer to fields
> within
> the current data set scope..."
> I can turn right around and show/hide a row of the table based on the
> exact
> same field name and it works. The structure of my IIF statment appears to
> be
> fine because the same structure works in another report. Is it the number
> of
> conditions? Is there a limit?
> Here are the conditions placed on the Hidden statement:
> =IIF(
> (FIELDS!SLPLunchRegular.Value <> 0) and
> (FIELDS!SLPLunchProv1.Value <> 0) and
> (FIELDS!SLPLunchProv2.Value <> 0) and
> (FIELDS!SLPLunchProv3.Value <> 0) and
> (FIELDS!SLPBkfstRegular.Value <> 0) and
> (FIELDS!SLPBkfstProv1.Value <> 0) and
> (FIELDS!SLPBkfstProv2.Value <> 0) and
> (FIELDS!SLPBkfstProv3.Value <> 0) and
> (FIELDS!SLPSevereRegular.Value <> 0) and
> (FIELDS!SLPSevereProv1.Value <> 0) and
> (FIELDS!SLPSevereProv2.Value <> 0) and
> (FIELDS!SLPSevereProv3.Value <> 0) and
> (FIELDS!SLPSnackArea.Value <> 0) and
> (FIELDS!SLPSnackNonArea.Value <> 0), False, True
> )
> --
> Message posted via SQLMonster.com
> http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-reporting/200511/1