2012年3月19日星期一

Fixing a expression

Hi,
I have the following expression for one of the text boxes in my report:
=Sum(Fields!totallagtime.Value)/Sum(Fields!openduring.Value)
But now if division by 0 occurs, it shows up as 'NaN' when run, I would like
it to show up as 0 if division by zero occurs.
Any suggestions on how this expression can be modified to do this?
ThanksTry this:
= iif(Fields!openduring.Value = 0, 0, Sum(Fields!totallagtime.Value) /
iif(Fields!openduring.Value = 0, 1, Fields!openduring.Value))
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Spencer23" <Spencer23@.discussions.microsoft.com> wrote in message
news:3C67F551-06F3-4185-A3ED-74E56DD31FB9@.microsoft.com...
> Hi,
> I have the following expression for one of the text boxes in my report:
> =Sum(Fields!totallagtime.Value)/Sum(Fields!openduring.Value)
> But now if division by 0 occurs, it shows up as 'NaN' when run, I would
like
> it to show up as 0 if division by zero occurs.
> Any suggestions on how this expression can be modified to do this?
> Thanks
>|||=Iif(sum(Fields!openduring.Value)=0,0,Sum(Fields!totallagtime.Value)/Sum(Fie
lds!openduring.Value))
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)
I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org
"Spencer23" <Spencer23@.discussions.microsoft.com> wrote in message
news:3C67F551-06F3-4185-A3ED-74E56DD31FB9@.microsoft.com...
> Hi,
> I have the following expression for one of the text boxes in my report:
> =Sum(Fields!totallagtime.Value)/Sum(Fields!openduring.Value)
> But now if division by 0 occurs, it shows up as 'NaN' when run, I would
like
> it to show up as 0 if division by zero occurs.
> Any suggestions on how this expression can be modified to do this?
> Thanks
>|||Hey Rebert,
Could you explain to me what this is doing in english becaue I have never
used iff before and I am not sure what it is doing.
Thanks
"Robert Bruckner [MSFT]" wrote:
> Try this:
> = iif(Fields!openduring.Value = 0, 0, Sum(Fields!totallagtime.Value) /
> iif(Fields!openduring.Value = 0, 1, Fields!openduring.Value))
> --
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
> "Spencer23" <Spencer23@.discussions.microsoft.com> wrote in message
> news:3C67F551-06F3-4185-A3ED-74E56DD31FB9@.microsoft.com...
> > Hi,
> >
> > I have the following expression for one of the text boxes in my report:
> >
> > =Sum(Fields!totallagtime.Value)/Sum(Fields!openduring.Value)
> >
> > But now if division by 0 occurs, it shows up as 'NaN' when run, I would
> like
> > it to show up as 0 if division by zero occurs.
> >
> > Any suggestions on how this expression can be modified to do this?
> >
> > Thanks
> >
>
>|||Thanks Wayne
"Wayne Snyder" wrote:
> =Iif(sum(Fields!openduring.Value)=0,0,Sum(Fields!totallagtime.Value)/Sum(Fie
> lds!openduring.Value))
>
> --
> Wayne Snyder, MCDBA, SQL Server MVP
> Mariner, Charlotte, NC
> www.mariner-usa.com
> (Please respond only to the newsgroups.)
> I support the Professional Association of SQL Server (PASS) and it's
> community of SQL Server professionals.
> www.sqlpass.org
> "Spencer23" <Spencer23@.discussions.microsoft.com> wrote in message
> news:3C67F551-06F3-4185-A3ED-74E56DD31FB9@.microsoft.com...
> > Hi,
> >
> > I have the following expression for one of the text boxes in my report:
> >
> > =Sum(Fields!totallagtime.Value)/Sum(Fields!openduring.Value)
> >
> > But now if division by 0 occurs, it shows up as 'NaN' when run, I would
> like
> > it to show up as 0 if division by zero occurs.
> >
> > Any suggestions on how this expression can be modified to do this?
> >
> > Thanks
> >
>
>|||IIF is a function call which essentially gives you similar functionality as
an IF statement - however since IIF is a function it will evaluate all
arguments before it is invoked. Therefore you have to avoid divisions by
zero also in the arguments of the IIF function. This makes it necessary to
write the expression as shown in my previous posting.
More information on IIF is available on MSDN:
http://msdn.microsoft.com/library/en-us/vblr7/html/vafctiif.asp
Among others, all the following VB.NET runtime functions are available for
writing expression in Reporting Services:
http://msdn.microsoft.com/library/en-us/vblr7/html/vaoriVBRuntimeLibraryKeywords.asp
Hope this helps,
Robert
--
This posting is provided "AS IS" with no warranties, and confers no rights.
"Spencer23" <Spencer23@.discussions.microsoft.com> wrote in message
news:71BEBB45-521A-4FAC-8D3F-65245709A897@.microsoft.com...
> Hey Rebert,
> Could you explain to me what this is doing in english becaue I have never
> used iff before and I am not sure what it is doing.
> Thanks
> "Robert Bruckner [MSFT]" wrote:
> > Try this:
> > = iif(Fields!openduring.Value = 0, 0, Sum(Fields!totallagtime.Value) /
> > iif(Fields!openduring.Value = 0, 1, Fields!openduring.Value))
> >
> > --
> > This posting is provided "AS IS" with no warranties, and confers no
rights.
> >
> >
> > "Spencer23" <Spencer23@.discussions.microsoft.com> wrote in message
> > news:3C67F551-06F3-4185-A3ED-74E56DD31FB9@.microsoft.com...
> > > Hi,
> > >
> > > I have the following expression for one of the text boxes in my
report:
> > >
> > > =Sum(Fields!totallagtime.Value)/Sum(Fields!openduring.Value)
> > >
> > > But now if division by 0 occurs, it shows up as 'NaN' when run, I
would
> > like
> > > it to show up as 0 if division by zero occurs.
> > >
> > > Any suggestions on how this expression can be modified to do this?
> > >
> > > Thanks
> > >
> >
> >
> >

没有评论:

发表评论