Showing posts with label expression. Show all posts
Showing posts with label expression. Show all posts

Monday, March 12, 2012

Nulls when summing a group in an expression

Hi guys,

I know this has been discussed before, but not in a way that solves this particular problem. I have some data in a table that is grouped by rows, but when i sum the fields in the group i am getting an error because one of the grouped rows contains a null.

Now when i have a one to one relationship between a dataset field and a table cell, checking for a null is easy. But how do you do it when you have several fields that are being summed for that table cell?

In this particular case, i have a work around - there are only two data rows per row group (paid revenue, and unpaid revenue), so i can check them individually for nulls by using First(Fields!Revenue.Value) and Last(Fields!Revenue.Value). This is the expression i used:

=IIf(

Not IsNothing( Fields!Revenue.Value) and isnumeric(Fields!Revenue.Value),

FormatCurrency(

IIf(

Not IsNothing( First(Fields!Revenue.Value)),

First(Fields!Revenue.Value),

0

)

+

IIf(

Not IsNothing( Last(Fields!Revenue.Value)),

Last(Fields!Revenue.Value),

0

),

0,

true,

false,

true

),

"-"

)

The first expression in the outer IIf is worthless, because using Fields!Revenue.Value only checks the first row in the group, and in my case it is always the second row that contains the null.

What is the best way to account for the null values?* It seems i can't access the .Value field like an array (i.e. Fields!Revenue.Value(1)). Should i be passing Fields!Revenue.Value through to a piece of custom code to sum it?

Thanks!

sluggy

*The data i am working with is sourced from a cube with an mdx query. The query uses a COALESCEEMPTY(<measure>, 0) function, but it seems the data provider being used is changing the fields that were coalesced back into nulls. Which is ok - at least i am getting the rows, prior to using the coalesce the rows were being dropped. I'd rather have nulls than have the row missing from the dataset.

Not sure if I understand your question completely, but you can use IIF inside of an aggregate function if you want to skip null values. For example, =Sum(IIF(IsNothing(Fields!Revenue.Value), 0, Fields!Revenue.Value)).

|||

Hi

can you try this out and check whether it is working or not.

=IIf(

Not IsNothing( Fields!Revenue.Value) and isnumeric(Fields!Revenue.Value),

FormatCurrency(

IIf(

Not IsNothing( Cint(First(Fields!Revenue.Value))),

Cint(First(Fields!Revenue.Value)),

0

)

+

IIf(

Not IsNothing( Cint(Last(Fields!Revenue.Value))),

Cint(Last(Fields!Revenue.Value)),

0

),

0,

true,

false,

true

),

"-"

)

Thanks,

Srinivas Reddy.

|||

Srinivas, Fang,

thanks for your answers, but neither work. In this case casting the fields has no effect, as they are already being returned as ints, and you can't typecast a field that is already null.

I have noticed something further, and consequently some of my original information was incorrect. What i have noticed is that nulls are NOT being returned - zeros are. So if i code this expression:

=First(Fields!Revenue.Value) + Last(Fields!Revenue.Value)

it gets evaluated no problem - i get the revenue from the first row plus zero from the second. But if i do any sort of aggregation type function on it, like Sum or Avg etc, then i get an error.Can anyone explain what is happening here, or suggest how i can determine exactly what error is occurring?

Thanks,

sluggy

|||

If you are designing and previewing the report in the report designer, you can check the error message in the task bar.

What's the data type of the Revenue field? One possible reason could be you are summing mixed types. Aggregate functions require all the values passed in are of the same type.

|||

Thanks Fang, i will check into that.

sluggy

Monday, February 20, 2012

Null Parameter

How do you pass a set a parameter null from an expression (i.e. drill
through report)? I've tried null, nothing, System.DBNull; none of these
work.
Thanks.I have the same question. Did you ever find a solution Elmer?
"Elmer Miller" wrote:
> How do you pass a set a parameter null from an expression (i.e. drill
> through report)? I've tried null, nothing, System.DBNull; none of these
> work.
> Thanks.
>
>|||No I haven't solved this one yet. I'm using a lame hack to work around. Set
the parameter to a special value that is then hard-coded to be treated like
null in the stored procedure. I'm glad I'm not the only one with the
problem. I'm sure there is a simple fix.
"Randy Howie" <RandyHowie@.discussions.microsoft.com> wrote in message
news:A94BBCDC-3021-4421-89A2-D791967765EE@.microsoft.com...
>I have the same question. Did you ever find a solution Elmer?
> "Elmer Miller" wrote:
>> How do you pass a set a parameter null from an expression (i.e. drill
>> through report)? I've tried null, nothing, System.DBNull; none of these
>> work.
>> Thanks.
>>|||Since I posted my question, I discovered that System.DBNull.Value does work
as a null (but System.DBNull alone does not).
This did not solve my problem, since null parameter value was not selected
in my target report, but I am convinced that is the correct method for
passing a null in an expression.
Randy Howie
"Elmer Miller" wrote:
> No I haven't solved this one yet. I'm using a lame hack to work around. Set
> the parameter to a special value that is then hard-coded to be treated like
> null in the stored procedure. I'm glad I'm not the only one with the
> problem. I'm sure there is a simple fix.
> "Randy Howie" <RandyHowie@.discussions.microsoft.com> wrote in message
> news:A94BBCDC-3021-4421-89A2-D791967765EE@.microsoft.com...
> >I have the same question. Did you ever find a solution Elmer?
> >
> > "Elmer Miller" wrote:
> >
> >> How do you pass a set a parameter null from an expression (i.e. drill
> >> through report)? I've tried null, nothing, System.DBNull; none of these
> >> work.
> >> Thanks.
> >>
> >>
> >>
>
>|||In the URL:
¶mname:isnull=true
--
Cheers,
'(' Jeff A. Stucker
\
Business Intelligence
www.criadvantage.com
---
"Elmer Miller" <millere@.empireco.nospam> wrote in message
news:%230KVJyB%23EHA.2112@.TK2MSFTNGP10.phx.gbl...
> No I haven't solved this one yet. I'm using a lame hack to work around.
> Set the parameter to a special value that is then hard-coded to be treated
> like null in the stored procedure. I'm glad I'm not the only one with the
> problem. I'm sure there is a simple fix.
> "Randy Howie" <RandyHowie@.discussions.microsoft.com> wrote in message
> news:A94BBCDC-3021-4421-89A2-D791967765EE@.microsoft.com...
>>I have the same question. Did you ever find a solution Elmer?
>> "Elmer Miller" wrote:
>> How do you pass a set a parameter null from an expression (i.e. drill
>> through report)? I've tried null, nothing, System.DBNull; none of these
>> work.
>> Thanks.
>>
>|||Jeff,
I have seen that tip for passing a null via a URL, but I was referring to
passing the parameter via a "jump to report" navigation expression
(drillthrough).
Randy Howie
--
"Jeff A. Stucker" wrote:
> In the URL:
> ¶mname:isnull=true
> --
> Cheers,
> '(' Jeff A. Stucker
> \
> Business Intelligence
> www.criadvantage.com
> ---
> "Elmer Miller" <millere@.empireco.nospam> wrote in message
> news:%230KVJyB%23EHA.2112@.TK2MSFTNGP10.phx.gbl...
> > No I haven't solved this one yet. I'm using a lame hack to work around.
> > Set the parameter to a special value that is then hard-coded to be treated
> > like null in the stored procedure. I'm glad I'm not the only one with the
> > problem. I'm sure there is a simple fix.
> >
> > "Randy Howie" <RandyHowie@.discussions.microsoft.com> wrote in message
> > news:A94BBCDC-3021-4421-89A2-D791967765EE@.microsoft.com...
> >>I have the same question. Did you ever find a solution Elmer?
> >>
> >> "Elmer Miller" wrote:
> >>
> >> How do you pass a set a parameter null from an expression (i.e. drill
> >> through report)? I've tried null, nothing, System.DBNull; none of these
> >> work.
> >> Thanks.
> >>
> >>
> >>
> >
> >
>
>|||I have also tried the System.DBNull.Value, but it doesn't work because
DBNull is of a different type. My parameter is a Date type and the
DBNull.Value causes an error:
The value you provided for the report parameter 'service_date' is not valid
for its type.
It should be this easy, but in this case type-checking is hurting us. I've
run into this situation before with Strong-typed datasets and in that case
you need to set a separate propterties and methods to handle nulls
(IsFieldNull() and SetFieldNull()). I'm sure there is something similar
going on here.
"Randy Howie" <RandyHowie@.discussions.microsoft.com> wrote in message
news:EFCD8BB2-5DA9-43FC-970B-33B7E20CA426@.microsoft.com...
> Since I posted my question, I discovered that System.DBNull.Value does
> work
> as a null (but System.DBNull alone does not).
> This did not solve my problem, since null parameter value was not selected
> in my target report, but I am convinced that is the correct method for
> passing a null in an expression.
> Randy Howie
> "Elmer Miller" wrote:
>> No I haven't solved this one yet. I'm using a lame hack to work around.
>> Set
>> the parameter to a special value that is then hard-coded to be treated
>> like
>> null in the stored procedure. I'm glad I'm not the only one with the
>> problem. I'm sure there is a simple fix.
>> "Randy Howie" <RandyHowie@.discussions.microsoft.com> wrote in message
>> news:A94BBCDC-3021-4421-89A2-D791967765EE@.microsoft.com...
>> >I have the same question. Did you ever find a solution Elmer?
>> >
>> > "Elmer Miller" wrote:
>> >
>> >> How do you pass a set a parameter null from an expression (i.e. drill
>> >> through report)? I've tried null, nothing, System.DBNull; none of
>> >> these
>> >> work.
>> >> Thanks.
>> >>
>> >>
>> >>
>>|||I found another workaround.
Instead of using 'Jump to report:' and setting parameters. Use 'Jump to URL'
and build the correct URL string with the param:null=true in it. It will
open up in a browser window (even when previewing)
"Randy Howie" <RandyHowie@.discussions.microsoft.com> wrote in message
news:A94BBCDC-3021-4421-89A2-D791967765EE@.microsoft.com...
>I have the same question. Did you ever find a solution Elmer?
> "Elmer Miller" wrote:
>> How do you pass a set a parameter null from an expression (i.e. drill
>> through report)? I've tried null, nothing, System.DBNull; none of these
>> work.
>> Thanks.
>>