Sunday, March 25, 2012
Calling sp in an expression
Is it possible to call a stored procedure (or a dataset that is based on an
sp) from the expression property in a report?
Can the "Code" tab be used to call the stored procedure and that "code" be
referred to from the expression property in a report (if the above is not
possible)?
This is what I am doing (or want to do):
I have a custom assembly that I don't want to put in the
MsSql\ReportServer\Bin folder. I want the custom assembly (DLL) to be in the
folder of my choice and under my control since the folder structure of
Microsoft for SQL Server 2005 (CTP July version) has changed.
So I created an Assembly in SQL Server 2005 by referring to this DLL. I
created a stored procedure that calls the assembly. Now I want to call this
stored procedure from the expression property of the report since I will be
passing the arguments from here.
Any help is appreciated. Thanks.No. The only place that a stored procedure can be called (unless you use a
custom assembly which is what you are trying to get away from) from is by
creating a dataset. The dataset query parameter mapping can use an
expression. If you have just a single record coming back then you can use
First aggregate to refer to it in your report. I do this all the time. Not
sure if that solves your problem or not.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"KMP" <KMP@.discussions.microsoft.com> wrote in message
news:4626D487-0E50-4F89-892C-59D33DB800C3@.microsoft.com...
> Hi All,
> Is it possible to call a stored procedure (or a dataset that is based on
> an
> sp) from the expression property in a report?
> Can the "Code" tab be used to call the stored procedure and that "code" be
> referred to from the expression property in a report (if the above is not
> possible)?
> This is what I am doing (or want to do):
> I have a custom assembly that I don't want to put in the
> MsSql\ReportServer\Bin folder. I want the custom assembly (DLL) to be in
> the
> folder of my choice and under my control since the folder structure of
> Microsoft for SQL Server 2005 (CTP July version) has changed.
> So I created an Assembly in SQL Server 2005 by referring to this DLL. I
> created a stored procedure that calls the assembly. Now I want to call
> this
> stored procedure from the expression property of the report since I will
> be
> passing the arguments from here.
> Any help is appreciated. Thanks.|||Thanks for you prompt reply.
Can you please explain with an example - may be this will work.
"Bruce L-C [MVP]" wrote:
> No. The only place that a stored procedure can be called (unless you use a
> custom assembly which is what you are trying to get away from) from is by
> creating a dataset. The dataset query parameter mapping can use an
> expression. If you have just a single record coming back then you can use
> First aggregate to refer to it in your report. I do this all the time. Not
> sure if that solves your problem or not.
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "KMP" <KMP@.discussions.microsoft.com> wrote in message
> news:4626D487-0E50-4F89-892C-59D33DB800C3@.microsoft.com...
> > Hi All,
> > Is it possible to call a stored procedure (or a dataset that is based on
> > an
> > sp) from the expression property in a report?
> >
> > Can the "Code" tab be used to call the stored procedure and that "code" be
> > referred to from the expression property in a report (if the above is not
> > possible)?
> >
> > This is what I am doing (or want to do):
> > I have a custom assembly that I don't want to put in the
> > MsSql\ReportServer\Bin folder. I want the custom assembly (DLL) to be in
> > the
> > folder of my choice and under my control since the folder structure of
> > Microsoft for SQL Server 2005 (CTP July version) has changed.
> >
> > So I created an Assembly in SQL Server 2005 by referring to this DLL. I
> > created a stored procedure that calls the assembly. Now I want to call
> > this
> > stored procedure from the expression property of the report since I will
> > be
> > passing the arguments from here.
> >
> > Any help is appreciated. Thanks.
>
>|||Which part is confusing to you? Mapping a query parameter to an expression?
Using the First aggragate?
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"KMP" <KMP@.discussions.microsoft.com> wrote in message
news:1C743F5A-368F-4F98-9EC5-42FA3F8860CB@.microsoft.com...
> Thanks for you prompt reply.
> Can you please explain with an example - may be this will work.
> "Bruce L-C [MVP]" wrote:
>> No. The only place that a stored procedure can be called (unless you use
>> a
>> custom assembly which is what you are trying to get away from) from is by
>> creating a dataset. The dataset query parameter mapping can use an
>> expression. If you have just a single record coming back then you can use
>> First aggregate to refer to it in your report. I do this all the time.
>> Not
>> sure if that solves your problem or not.
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "KMP" <KMP@.discussions.microsoft.com> wrote in message
>> news:4626D487-0E50-4F89-892C-59D33DB800C3@.microsoft.com...
>> > Hi All,
>> > Is it possible to call a stored procedure (or a dataset that is based
>> > on
>> > an
>> > sp) from the expression property in a report?
>> >
>> > Can the "Code" tab be used to call the stored procedure and that "code"
>> > be
>> > referred to from the expression property in a report (if the above is
>> > not
>> > possible)?
>> >
>> > This is what I am doing (or want to do):
>> > I have a custom assembly that I don't want to put in the
>> > MsSql\ReportServer\Bin folder. I want the custom assembly (DLL) to be
>> > in
>> > the
>> > folder of my choice and under my control since the folder structure of
>> > Microsoft for SQL Server 2005 (CTP July version) has changed.
>> >
>> > So I created an Assembly in SQL Server 2005 by referring to this DLL. I
>> > created a stored procedure that calls the assembly. Now I want to call
>> > this
>> > stored procedure from the expression property of the report since I
>> > will
>> > be
>> > passing the arguments from here.
>> >
>> > Any help is appreciated. Thanks.
>>|||Mapping a query parameter to an expression.
"Bruce L-C [MVP]" wrote:
> Which part is confusing to you? Mapping a query parameter to an expression?
> Using the First aggragate?
>
> --
> Bruce Loehle-Conger
> MVP SQL Server Reporting Services
> "KMP" <KMP@.discussions.microsoft.com> wrote in message
> news:1C743F5A-368F-4F98-9EC5-42FA3F8860CB@.microsoft.com...
> > Thanks for you prompt reply.
> >
> > Can you please explain with an example - may be this will work.
> >
> > "Bruce L-C [MVP]" wrote:
> >
> >> No. The only place that a stored procedure can be called (unless you use
> >> a
> >> custom assembly which is what you are trying to get away from) from is by
> >> creating a dataset. The dataset query parameter mapping can use an
> >> expression. If you have just a single record coming back then you can use
> >> First aggregate to refer to it in your report. I do this all the time.
> >> Not
> >> sure if that solves your problem or not.
> >>
> >>
> >> --
> >> Bruce Loehle-Conger
> >> MVP SQL Server Reporting Services
> >>
> >> "KMP" <KMP@.discussions.microsoft.com> wrote in message
> >> news:4626D487-0E50-4F89-892C-59D33DB800C3@.microsoft.com...
> >> > Hi All,
> >> > Is it possible to call a stored procedure (or a dataset that is based
> >> > on
> >> > an
> >> > sp) from the expression property in a report?
> >> >
> >> > Can the "Code" tab be used to call the stored procedure and that "code"
> >> > be
> >> > referred to from the expression property in a report (if the above is
> >> > not
> >> > possible)?
> >> >
> >> > This is what I am doing (or want to do):
> >> > I have a custom assembly that I don't want to put in the
> >> > MsSql\ReportServer\Bin folder. I want the custom assembly (DLL) to be
> >> > in
> >> > the
> >> > folder of my choice and under my control since the folder structure of
> >> > Microsoft for SQL Server 2005 (CTP July version) has changed.
> >> >
> >> > So I created an Assembly in SQL Server 2005 by referring to this DLL. I
> >> > created a stored procedure that calls the assembly. Now I want to call
> >> > this
> >> > stored procedure from the expression property of the report since I
> >> > will
> >> > be
> >> > passing the arguments from here.
> >> >
> >> > Any help is appreciated. Thanks.
> >>
> >>
> >>
>
>|||RS makes this concept murky because it automatically creates a Report
Parameter for every query parameter. However, you can map query parameters
to the same report parameter or to an expression. For instance, let's say I
have two datasets, they both need from and to dates. Let's further say that
the query parameters are named differently. For instance @.FromDate and
@.StartDate. Reporting services will create two report parameters. However
you can map both @.FromDate and @.StartDate to the same report parameter.
Click on the ... in the dataset tab, Parameters tab. On the left is the
query parameter on the right is what it is mapped to. That is where you
would map both to the same report parameter. OK, now, mapping to an
expression, you can click on the combo box and set expression.
For instance this calls some code behind report:
=Code.SomecodeOfMine(Parameters!Param1.Value)
This sets to the current day/time
=Now
Etc. Your expression can be pretty much anything.
When you pick expression you go to the expression builder.
Bruce Loehle-Conger
MVP SQL Server Reporting Services
"KMP" <KMP@.discussions.microsoft.com> wrote in message
news:74430973-4547-419F-AFFC-29CA4CE68667@.microsoft.com...
> Mapping a query parameter to an expression.
> "Bruce L-C [MVP]" wrote:
>> Which part is confusing to you? Mapping a query parameter to an
>> expression?
>> Using the First aggragate?
>>
>> --
>> Bruce Loehle-Conger
>> MVP SQL Server Reporting Services
>> "KMP" <KMP@.discussions.microsoft.com> wrote in message
>> news:1C743F5A-368F-4F98-9EC5-42FA3F8860CB@.microsoft.com...
>> > Thanks for you prompt reply.
>> >
>> > Can you please explain with an example - may be this will work.
>> >
>> > "Bruce L-C [MVP]" wrote:
>> >
>> >> No. The only place that a stored procedure can be called (unless you
>> >> use
>> >> a
>> >> custom assembly which is what you are trying to get away from) from is
>> >> by
>> >> creating a dataset. The dataset query parameter mapping can use an
>> >> expression. If you have just a single record coming back then you can
>> >> use
>> >> First aggregate to refer to it in your report. I do this all the time.
>> >> Not
>> >> sure if that solves your problem or not.
>> >>
>> >>
>> >> --
>> >> Bruce Loehle-Conger
>> >> MVP SQL Server Reporting Services
>> >>
>> >> "KMP" <KMP@.discussions.microsoft.com> wrote in message
>> >> news:4626D487-0E50-4F89-892C-59D33DB800C3@.microsoft.com...
>> >> > Hi All,
>> >> > Is it possible to call a stored procedure (or a dataset that is
>> >> > based
>> >> > on
>> >> > an
>> >> > sp) from the expression property in a report?
>> >> >
>> >> > Can the "Code" tab be used to call the stored procedure and that
>> >> > "code"
>> >> > be
>> >> > referred to from the expression property in a report (if the above
>> >> > is
>> >> > not
>> >> > possible)?
>> >> >
>> >> > This is what I am doing (or want to do):
>> >> > I have a custom assembly that I don't want to put in the
>> >> > MsSql\ReportServer\Bin folder. I want the custom assembly (DLL) to
>> >> > be
>> >> > in
>> >> > the
>> >> > folder of my choice and under my control since the folder structure
>> >> > of
>> >> > Microsoft for SQL Server 2005 (CTP July version) has changed.
>> >> >
>> >> > So I created an Assembly in SQL Server 2005 by referring to this
>> >> > DLL. I
>> >> > created a stored procedure that calls the assembly. Now I want to
>> >> > call
>> >> > this
>> >> > stored procedure from the expression property of the report since I
>> >> > will
>> >> > be
>> >> > passing the arguments from here.
>> >> >
>> >> > Any help is appreciated. Thanks.
>> >>
>> >>
>> >>
>>
Thursday, March 22, 2012
Calling functions in an expression
that references it. Here is the expression that is in the details row:
=Iif(Code.Check(Fields!fullname.Value), 0,
Code.AddClient(Fields!fullname.Value))
The Check function basically looks in an array to see if the name is in the
array already. If it is, the expression should return 0. If it is not in the
array, it should call AddClient() to add the client and increment the
variable Total (Which is also declared in the Report Code). However, whenever
this expression runs, Total gets incrememnted no matter what. Even if the IIf
condition is false.
Is there something wrong with the way I am doing this?It is ok, is there any error in that case what exactly is the error?
Amarnath
"Matt M" wrote:
> I have a function in the Report Code of one of my reports and an expression
> that references it. Here is the expression that is in the details row:
> =Iif(Code.Check(Fields!fullname.Value), 0,
> Code.AddClient(Fields!fullname.Value))
> The Check function basically looks in an array to see if the name is in the
> array already. If it is, the expression should return 0. If it is not in the
> array, it should call AddClient() to add the client and increment the
> variable Total (Which is also declared in the Report Code). However, whenever
> this expression runs, Total gets incrememnted no matter what. Even if the IIf
> condition is false.
> Is there something wrong with the way I am doing this?|||There is no error, but rather this is what is being displayed in the report:
0 Case1
1 Case2
2 Case3
3 Case4
4 Case5
The first column displays the Total variable that gets incremented by the
AddClient() function. It should only be incremented if the Check() returns
true in any of the Cases. But instead, it gets incremented every row.
"Amarnath" wrote:
> It is ok, is there any error in that case what exactly is the error?
> Amarnath
> "Matt M" wrote:
> > I have a function in the Report Code of one of my reports and an expression
> > that references it. Here is the expression that is in the details row:
> >
> > =Iif(Code.Check(Fields!fullname.Value), 0,
> > Code.AddClient(Fields!fullname.Value))
> >
> > The Check function basically looks in an array to see if the name is in the
> > array already. If it is, the expression should return 0. If it is not in the
> > array, it should call AddClient() to add the client and increment the
> > variable Total (Which is also declared in the Report Code). However, whenever
> > this expression runs, Total gets incrememnted no matter what. Even if the IIf
> > condition is false.
> >
> > Is there something wrong with the way I am doing this?|||You still need to evaluate the expression... (i.e. you need an = sign)
change it to:
=Iif(Code.Check(Fields!fullname.Value) = 1, 0,
Code.AddClient(Fields!fullname.Value))
and I am assuming that you are returning a zero for false and 1 for true...
=-Chris
"Matt M" <MattM@.discussions.microsoft.com> wrote in message
news:2FE6A608-EE89-407D-AAED-A17385D6952F@.microsoft.com...
>I have a function in the Report Code of one of my reports and an expression
> that references it. Here is the expression that is in the details row:
> =Iif(Code.Check(Fields!fullname.Value), 0,
> Code.AddClient(Fields!fullname.Value))
> The Check function basically looks in an array to see if the name is in
> the
> array already. If it is, the expression should return 0. If it is not in
> the
> array, it should call AddClient() to add the client and increment the
> variable Total (Which is also declared in the Report Code). However,
> whenever
> this expression runs, Total gets incrememnted no matter what. Even if the
> IIf
> condition is false.
> Is there something wrong with the way I am doing this?|||I'm actually returning a boolean true or false with it. I tried returning a 0
or a 1 and still does the same thing.
"Chris Conner" wrote:
> You still need to evaluate the expression... (i.e. you need an = sign)
> change it to:
> =Iif(Code.Check(Fields!fullname.Value) = 1, 0,
> Code.AddClient(Fields!fullname.Value))
> and I am assuming that you are returning a zero for false and 1 for true...
> =-Chris
> "Matt M" <MattM@.discussions.microsoft.com> wrote in message
> news:2FE6A608-EE89-407D-AAED-A17385D6952F@.microsoft.com...
> >I have a function in the Report Code of one of my reports and an expression
> > that references it. Here is the expression that is in the details row:
> >
> > =Iif(Code.Check(Fields!fullname.Value), 0,
> > Code.AddClient(Fields!fullname.Value))
> >
> > The Check function basically looks in an array to see if the name is in
> > the
> > array already. If it is, the expression should return 0. If it is not in
> > the
> > array, it should call AddClient() to add the client and increment the
> > variable Total (Which is also declared in the Report Code). However,
> > whenever
> > this expression runs, Total gets incrememnted no matter what. Even if the
> > IIf
> > condition is false.
> >
> > Is there something wrong with the way I am doing this?
>
>|||It means it is always returning true... Try hard code just for testing
purpose. hard code it to false and see whether it increments.
Amarnath
"Matt M" wrote:
> There is no error, but rather this is what is being displayed in the report:
> 0 Case1
> 1 Case2
> 2 Case3
> 3 Case4
> 4 Case5
> The first column displays the Total variable that gets incremented by the
> AddClient() function. It should only be incremented if the Check() returns
> true in any of the Cases. But instead, it gets incremented every row.
>
> "Amarnath" wrote:
> > It is ok, is there any error in that case what exactly is the error?
> >
> > Amarnath
> >
> > "Matt M" wrote:
> >
> > > I have a function in the Report Code of one of my reports and an expression
> > > that references it. Here is the expression that is in the details row:
> > >
> > > =Iif(Code.Check(Fields!fullname.Value), 0,
> > > Code.AddClient(Fields!fullname.Value))
> > >
> > > The Check function basically looks in an array to see if the name is in the
> > > array already. If it is, the expression should return 0. If it is not in the
> > > array, it should call AddClient() to add the client and increment the
> > > variable Total (Which is also declared in the Report Code). However, whenever
> > > this expression runs, Total gets incrememnted no matter what. Even if the IIf
> > > condition is false.
> > >
> > > Is there something wrong with the way I am doing this?
Thursday, March 8, 2012
Calling .Net Assembly
I create a KPI with the following expression:
([Measures].[TDV Result],
StrToMember("[TDV Result Date].[Year - Quarter - Month - Date]
.[Month].&[" + MdxFunctions.MdxFunctions.Timeframe.GetCurrentMonth() + "]"),
[Entities].[EntityType].[Site],
[TDVs].[Parameter - Material].&[Coal])
MdxFunctions.MdxFunctions.Timeframe.GetCurrentMonth() is a .Net assembly and returns a string like 2007-02-01. I deploy and look at the Browser View but there is an error stating that "The '2007-02-01' string cannont be converted to the date type". How do I convert the date string?
You are passing 2007-02-01 as a key, are you sure that key of the time dimension is a string and not a date? You should either pass a key or remote &: ("[TDV Result Date].[Year - Quarter - Month - Date].[Month].["|||
I'm not entirely sure, but if I had to guess I would try adding the time component. If you are using a date datatype for the key of your month attribute, it might be expecting a value in the form of "yyyy-mm-dd hh:mm:ss"
A couple of other observations:
I think you should be able to write your .Net function to return an actual member instead of a string, which mean you would not need the StrToMember Call everytime you used GetCurrentMonth (You could look at the LinkMember function from http://www.codeplex.com/ASStoredProcedures )|||Thanks, I did notice I was missing the time part after I sent this post. I would like to just use VBA but the problem is I have other functions to get the current week, quarter, and other functions that require lengthy VBA code. If I put it in a calculation then I need to duplicate it for every cube. I tried the Time Intelligence but only get NA.|||
That's cool, I realise that there are more considerations than pure speed. :)
I just thought you should be aware that there is a performance impact, particularly if you had queries that displayed the KPI for a large number of members. But if you are now up and running and the performance is acceptable then there is no need to worry.
Friday, February 24, 2012
Calculations at Run Time
I am writting a report & want to calculate %age difference in last year &
current year's sales.
how do I write the expression or will have to write it in the SP I'm using
to run the report.
The problem is, I need to check the previous years sales value only if it is
greater than 0, then calculate the %age difference so it is something like
this
if prevYearSales > 0 then
currYearSales - prevYearSales / prevYearSales.
ThanksYou do it in an SP or as the following report expression
=IIF(Fields!prevYearSales.Value > 0,
Fields!currYearSales.Value - FIelds!prevYearSales.Value /
Fields!prevYearSales.Value,0)
It sets other values to 0 (the last expression)
--
Wayne Snyder MCDBA, SQL Server MVP
Mariner, Charlotte, NC
I support the Professional Association for SQL Server ( PASS) and it''s
community of SQL Professionals.
"Vishal" wrote:
> Hi,
> I am writting a report & want to calculate %age difference in last year &
> current year's sales.
> how do I write the expression or will have to write it in the SP I'm using
> to run the report.
> The problem is, I need to check the previous years sales value only if it is
> greater than 0, then calculate the %age difference so it is something like
> this
> if prevYearSales > 0 then
> currYearSales - prevYearSales / prevYearSales.
> Thanks
>
>
Sunday, February 19, 2012
Calculation Error
in the row. Here is my expression;
"=iif(Fields!Hours.Value > 0 and Fields!SUM.Value > 0,
Fields!SUM.Value/Fields!Hours.Value,0)"
Basically, I am doing a divide calculation of two columns, but sometimes
there is a zero in the columns which causes an error. In my expression
above, I am saying if column A and column B are >0, then divide, if not, then
0.
Any ideas on what I am doing wrong? I have about 100 reports that I am
cranking out, so learning a lot.
Thanks in advance,
RyanOn Oct 19, 10:11 am, Ryan Mcbee <RyanMc...@.discussions.microsoft.com>
wrote:
> I am designing a report and am getting an error when I run this calculation
> in the row. Here is my expression;
> "=iif(Fields!Hours.Value > 0 and Fields!SUM.Value > 0,
> Fields!SUM.Value/Fields!Hours.Value,0)"
> Basically, I am doing a divide calculation of two columns, but sometimes
> there is a zero in the columns which causes an error. In my expression
> above, I am saying if column A and column B are >0, then divide, if not, then
> 0.
> Any ideas on what I am doing wrong? I have about 100 reports that I am
> cranking out, so learning a lot.
> Thanks in advance,
> Ryan
If I remember correctly, > 0 does not exclude null; so, you might want
to change your expression to something like:
=iif(Fields!Hours.Value > 0 and Fields!Hours.Value <> Nothing and
Fields!SUM.Value > 0 and Fields!SUM.Value <> Nothing , Fields!
SUM.Value/Fields!Hours.Value, 0)
Hope this helps.
Regards,
Enrique Martinez
Sr. Software Consultant|||Check the article here for expression examples using the IIF statement:
http://msdn2.microsoft.com/en-us/library/ms157328.aspx
All of the examples I've seen have involved using one expression in each
IIF so if you are doing Fields!Hours.Value > 0 and Fields!SUM.Value > 0
then you would need two nested IIFs. Also, Enrique is correct. You should
check for NULL before doing any comparisions to make sure you're getting
valid data.
Here is an example expression you can try:
=iif(Fields!Hours.Value > 0, IIF(Fields!SUM.Value > 0,
Fields!SUM.Value/Fields!Hours.Value,0),0)
If you do think you'll have NULLs in your data use:
=iif(IsNothing(Fields!Hours.Value), 0,
iif(IsNothing(Fields!SUM.Value),0,iif(Fields!Hours.Value > 0,
IIF(Fields!SUM.Value > 0, Fields!SUM.Value/Fields!Hours.Value,0),0))
Didn't test the above so don't hammer me for any mistakes I may have put in
there :)
--
Chris Alton, Microsoft Corp.
SQL Server Developer Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
--
> Thread-Topic: Calculation Error
> thread-index: AcgSYkRUoT7qoNO7S9WCFbXNnevQBA==> X-WBNR-Posting-Host: 207.46.19.168
> From: =?Utf-8?B?UnlhbiBNY2JlZQ==?= <RyanMcbee@.discussions.microsoft.com>
> Subject: Calculation Error
> Date: Fri, 19 Oct 2007 08:11:04 -0700
> Lines: 15
> Message-ID: <562C6023-A07E-4FA8-83B4-2B486EDDE038@.microsoft.com>
> MIME-Version: 1.0
> I am designing a report and am getting an error when I run this
calculation
> in the row. Here is my expression;
> "=iif(Fields!Hours.Value > 0 and Fields!SUM.Value > 0,
> Fields!SUM.Value/Fields!Hours.Value,0)"
> Basically, I am doing a divide calculation of two columns, but sometimes
> there is a zero in the columns which causes an error. In my expression
> above, I am saying if column A and column B are >0, then divide, if not,
then
> 0.
> Any ideas on what I am doing wrong? I have about 100 reports that I am
> cranking out, so learning a lot.
> Thanks in advance,
> Ryan
>|||On Oct 22, 2:08 pm, cal...@.online.microsoft.com (Chris Alton [MSFT])
wrote:
> Check the article here for expression examples using the IIF statement:http://msdn2.microsoft.com/en-us/library/ms157328.aspx
> All of the examples I've seen have involved using one expression in each
> IIF so if you are doing Fields!Hours.Value > 0 and Fields!SUM.Value > 0
> then you would need two nested IIFs. Also, Enrique is correct. You should
> check for NULL before doing any comparisions to make sure you're getting
> valid data.
> Here is an example expression you can try:
> =iif(Fields!Hours.Value > 0, IIF(Fields!SUM.Value > 0,
> Fields!SUM.Value/Fields!Hours.Value,0),0)
> If you do think you'll have NULLs in your data use:
> =iif(IsNothing(Fields!Hours.Value), 0,
> iif(IsNothing(Fields!SUM.Value),0,iif(Fields!Hours.Value > 0,
> IIF(Fields!SUM.Value > 0, Fields!SUM.Value/Fields!Hours.Value,0),0))
> Didn't test the above so don't hammer me for any mistakes I may have put in
> there :)
> --
> Chris Alton, Microsoft Corp.
> SQL Server Developer Support Engineer
> This posting is provided "AS IS" with no warranties, and confers no rights.
> --
>
> > Thread-Topic: Calculation Error
> > thread-index: AcgSYkRUoT7qoNO7S9WCFbXNnevQBA==> > X-WBNR-Posting-Host: 207.46.19.168
> > From: =?Utf-8?B?UnlhbiBNY2JlZQ==?= <RyanMc...@.discussions.microsoft.com>
> > Subject: Calculation Error
> > Date: Fri, 19 Oct 2007 08:11:04 -0700
> > Lines: 15
> > Message-ID: <562C6023-A07E-4FA8-83B4-2B486EDDE...@.microsoft.com>
> > MIME-Version: 1.0
> > I am designing a report and am getting an error when I run this
> calculation
> > in the row. Here is my expression;
> > "=iif(Fields!Hours.Value > 0 and Fields!SUM.Value > 0,
> > Fields!SUM.Value/Fields!Hours.Value,0)"
> > Basically, I am doing a divide calculation of two columns, but sometimes
> > there is a zero in the columns which causes an error. In my expression
> > above, I am saying if column A and column B are >0, then divide, if not,
> then
> > 0.
> > Any ideas on what I am doing wrong? I have about 100 reports that I am
> > cranking out, so learning a lot.
> > Thanks in advance,
> > Ryan- Hide quoted text -
> - Show quoted text -
Another way to work around this is with a custom code function.
In Layout mode, click Report > Report Properties > Code to open the
Custom Code editor.
In the editor, type:
Public Function DivideBy(exp1, exp2)
If exp2 = 0 Then
DivideBy = Nothing
Else DivideBy = exp1/exp2
End If
End Function
Now whereever you need to divide (with the potential for divide by
zero errors) insert this expression:
=code.divideby(exp1,exp2)
For you it would be:
"=code.divideby(Fields!SUM.Value,Fields!Hours.Value)"
If your shop has SQL 2005 enterprise edition, you can create a custom
assembly out of the function.|||On Oct 23, 11:55 am, toolman <t...@.infocision.com> wrote:
> On Oct 22, 2:08 pm, cal...@.online.microsoft.com (Chris Alton [MSFT])
> wrote:
>
>
> > Check the article here for expression examples using the IIF statement:http://msdn2.microsoft.com/en-us/library/ms157328.aspx
> > All of the examples I've seen have involved using one expression in each
> > IIF so if you are doing Fields!Hours.Value > 0 and Fields!SUM.Value > 0
> > then you would need two nested IIFs. Also, Enrique is correct. You should
> > check for NULL before doing any comparisions to make sure you're getting
> > valid data.
> > Here is an example expression you can try:
> > =iif(Fields!Hours.Value > 0, IIF(Fields!SUM.Value > 0,
> > Fields!SUM.Value/Fields!Hours.Value,0),0)
> > If you do think you'll have NULLs in your data use:
> > =iif(IsNothing(Fields!Hours.Value), 0,
> > iif(IsNothing(Fields!SUM.Value),0,iif(Fields!Hours.Value > 0,
> > IIF(Fields!SUM.Value > 0, Fields!SUM.Value/Fields!Hours.Value,0),0))
> > Didn't test the above so don't hammer me for any mistakes I may have put in
> > there :)
> > --
> > Chris Alton, Microsoft Corp.
> > SQL Server Developer Support Engineer
> > This posting is provided "AS IS" with no warranties, and confers no rights.
> > --
> > > Thread-Topic: Calculation Error
> > > thread-index: AcgSYkRUoT7qoNO7S9WCFbXNnevQBA==> > > X-WBNR-Posting-Host: 207.46.19.168
> > > From: =?Utf-8?B?UnlhbiBNY2JlZQ==?= <RyanMc...@.discussions.microsoft.com>
> > > Subject: Calculation Error
> > > Date: Fri, 19 Oct 2007 08:11:04 -0700
> > > Lines: 15
> > > Message-ID: <562C6023-A07E-4FA8-83B4-2B486EDDE...@.microsoft.com>
> > > MIME-Version: 1.0
> > > I am designing a report and am getting an error when I run this
> > calculation
> > > in the row. Here is my expression;
> > > "=iif(Fields!Hours.Value > 0 and Fields!SUM.Value > 0,
> > > Fields!SUM.Value/Fields!Hours.Value,0)"
> > > Basically, I am doing a divide calculation of two columns, but sometimes
> > > there is a zero in the columns which causes an error. In my expression
> > > above, I am saying if column A and column B are >0, then divide, if not,
> > then
> > > 0.
> > > Any ideas on what I am doing wrong? I have about 100 reports that I am
> > > cranking out, so learning a lot.
> > > Thanks in advance,
> > > Ryan- Hide quoted text -
> > - Show quoted text -
> Another way to work around this is with a custom code function.
> In Layout mode, click Report > Report Properties > Code to open the
> Custom Code editor.
> In the editor, type:
> Public Function DivideBy(exp1, exp2)
> If exp2 = 0 Then
> DivideBy = Nothing
> Else DivideBy = exp1/exp2
> End If
> End Function
> Now whereever you need to divide (with the potential for divide by
> zero errors) insert this expression:
> =code.divideby(exp1,exp2)
> For you it would be:
> "=code.divideby(Fields!SUM.Value,Fields!Hours.Value)"
> If your shop has SQL 2005 enterprise edition, you can create a custom
> assembly out of the function.- Hide quoted text -
> - Show quoted text -
Actually,
Public Function DivideBy(exp1, exp2)
If exp2 = 0 Then
DivideBy = 0
Else DivideBy = exp1/exp2
End If
End Function
is better so you get the zero as output.
Friday, February 10, 2012
calculated members WHERE statement?
i am trying to figure out how to use MDX and a WHERE statement in the calculated member expression textbox. Every time i try i get a syntax error, and can't seem to find an example anywhere. Is it even possible?
I am trying to make a calculated member (measure) but I need to filter on only a few values of a DIM. I have seen how to write an MDX query and do this, but I need a permenant calculated measure.
Any insights? Thanks
Please keep in mind the difference between an MDX expression (used in defining a calculated member) and an MDX query (which can include a WHERE clause). You can try using Filter() in your MDX expression instead.|||i could never get that to work, i went down the road of making a named calculation and using that in my calculated measure