Showing posts with label calculations. Show all posts
Showing posts with label calculations. Show all posts

Friday, February 24, 2012

Calculations: Division calculation is returning incorrect results

Hi everyone,

I created the following simple MDX query containing a Division calculation (listed below):

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

CREATE MEMBER [Adventure Works].[Employee].[Employee].[All Employees].[BDA13F64-E5D5-418B-A4,A6,1F,C5,B8,44,2,54] AS ( [Employee].[Employee].[All Employees] ) / ( [Employee].[Employee].&[290] ) , SOLVE_ORDER = 1
GO
SELECT
[Delivery Date].[Date].MEMBERS DIMENSION PROPERTIES MEMBER_NAME, MEMBER_TYPE, DESCRIPTION, PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME ON COLUMNS ,
{[Employee].[Employee].[All Employees].[BDA13F64-E5D5-418B-A4,A6,1F,C5,B8,44,2,54],[Employee].[Employee].MEMBERS} DIMENSION PROPERTIES MEMBER_NAME, MEMBER_TYPE, DESCRIPTION, PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME ON ROWS
FROM [Adventure Works]
GO
DROP MEMBER [Adventure Works].[Employee].[Employee].[All Employees].[BDA13F64-E5D5-418B-A4,A6,1F,C5,B8,44,2,54]

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

When executing the query, I noticed that some of the values of the calculation were incorrect (which I verified by hand calculating the expected result). I noticed that the value becomes wrong starting at the "July 13, 2002" column until the end of the row. Oddly enough, though, when I add the "NON EMPTY" keywords to remove nulls from both axes and explicitly specify each hierarchy's default members for the slice, the calculation then returns the correct value:

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

CREATE MEMBER [Adventure Works].[Employee].[Employee].[All Employees].[BDA13F64-E5D5-418B-A4,A6,1F,C5,B8,44,2,54] AS ( [Employee].[Employee].[All Employees] ) / ( [Employee].[Employee].&[290] ) , SOLVE_ORDER = 1
GO
SELECT
NON EMPTY [Delivery Date].[Date].MEMBERS DIMENSION PROPERTIES MEMBER_NAME, MEMBER_TYPE, DESCRIPTION, PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME ON COLUMNS ,
NON EMPTY {[Employee].[Employee].[All Employees].[BDA13F64-E5D5-418B-A4,A6,1F,C5,B8,44,2,54],[Employee].[Employee].MEMBERS} DIMENSION PROPERTIES MEMBER_NAME, MEMBER_TYPE, DESCRIPTION, PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME ON ROWS
FROM [Adventure Works]
WHERE
( [Account].[Account].defaultmember, [Account].[Account Number].defaultmember, [Account].[Account Type].defaultmember, [Account].[Accounts].defaultmember, [Customer].[Address].defaultmember, [Customer].[City].defaultmember, [Customer].[Commute Distance].defaultmember, [Customer].[Country].defaultmember, [Customer].[Customer].defaultmember, [Customer].[Customer Geography].defaultmember, [Customer].[Education].defaultmember, [Customer].[Email Address].defaultmember, [Customer].[Gender].defaultmember, [Customer].[Home Owner].defaultmember, [Customer].[Marital Status].defaultmember, [Customer].[Number of Cars Owned].defaultmember, [Customer].[Number of Children At Home].defaultmember, [Customer].[Occupation].defaultmember, [Customer].[Phone].defaultmember, [Customer].[Postal Code].defaultmember, [Customer].[State-Province].defaultmember, [Customer].[Total Children].defaultmember, [Customer].[Yearly Income].defaultmember, [Date].[Calendar].defaultmember, [Date].[Calendar Quarter of Year].defaultmember, [Date].[Calendar Semester of Year].defaultmember, [Date].[Calendar Year].defaultmember, [Date].[Date].defaultmember, [Date].[Day Name].defaultmember, [Date].[Day of Month].defaultmember, [Date].[Day of Week].defaultmember, [Date].[Day of Year].defaultmember, [Date].[Fiscal].defaultmember, [Date].[Fiscal Quarter of Year].defaultmember, [Date].[Fiscal Semester of Year].defaultmember, [Date].[Fiscal Year].defaultmember, [Date].[Month of Year].defaultmember, [Date].[Week of Year].defaultmember, [Delivery Date].[Calendar].defaultmember, [Delivery Date].[Calendar Quarter of Year].defaultmember, [Delivery Date].[Calendar Semester of Year].defaultmember, [Delivery Date].[Calendar Year].defaultmember, [Delivery Date].[Day Name].defaultmember, [Delivery Date].[Day of Month].defaultmember, [Delivery Date].[Day of Week].defaultmember, [Delivery Date].[Day of Year].defaultmember, [Delivery Date].[Fiscal].defaultmember, [Delivery Date].[Fiscal Quarter of Year].defaultmember, [Delivery Date].[Fiscal Semester of Year].defaultmember, [Delivery Date].[Fiscal Year].defaultmember, [Delivery Date].[Month of Year].defaultmember, [Delivery Date].[Week of Year].defaultmember, [Department].[Departments].defaultmember, [Destination Currency].[Destination Currency].defaultmember, [Destination Currency].[Destination Currency Code].defaultmember, [Employee].[Department Name].defaultmember, [Employee].[Email Address].defaultmember, [Employee].[Emergency Contact Name].defaultmember, [Employee].[Emergency Contact Phone].defaultmember, [Employee].[Employee Department].defaultmember, [Employee].[Employees].defaultmember, [Employee].[End Date].defaultmember, [Employee].[Gender].defaultmember, [Employee].[Hire Date].defaultmember, [Employee].[Hire Year].defaultmember, [Employee].[Marital Status].defaultmember, [Employee].[Pay Frequency].defaultmember, [Employee].[Phone].defaultmember, [Employee].[Salaried Flag].defaultmember, [Employee].[Sales Person Flag].defaultmember, [Employee].[Sick Leave Hours].defaultmember, [Employee].[Start Date].defaultmember, [Employee].[Status].defaultmember, [Employee].[Title].defaultmember, [Employee].[Vacation Hours].defaultmember, [Geography].[City].defaultmember, [Geography].[Country].defaultmember, [Geography].[Geography].defaultmember, [Geography].[Postal Code].defaultmember, [Geography].[State-Province].defaultmember, [Internet Sales Order Details].[Carrier Tracking Number].defaultmember, [Internet Sales Order Details].[Customer PO Number].defaultmember, [Internet Sales Order Details].[Internet Sales Orders].defaultmember, [Internet Sales Order Details].[Sales Order Line].defaultmember, [Internet Sales Order Details].[Sales Order Number].defaultmember, [Measures].defaultmember, [Organization].[Currency Code].defaultmember, [Organization].[Organizations].defaultmember, [Product].[Category].defaultmember, [Product].[Class].defaultmember, [Product].[Color].defaultmember, [Product].[Days to Manufacture].defaultmember, [Product].[Dealer Price].defaultmember, [Product].[End Date].defaultmember, [Product].[Large Photo].defaultmember, [Product].[List Price].defaultmember, [Product].[Manufacture Time].defaultmember, [Product].[Model Name].defaultmember, [Product].[Product].defaultmember, [Product].[Product Categories].defaultmember, [Product].[Product Key].defaultmember, [Product].[Product Line].defaultmember, [Product].[Product Model Categories].defaultmember, [Product].[Product Model Lines].defaultmember, [Product].[Reorder Point].defaultmember, [Product].[Safety Stock Level].defaultmember, [Product].[Size].defaultmember, [Product].[Size Range].defaultmember, [Product].[Standard Cost].defaultmember, [Product].[Start Date].defaultmember, [Product].[Status].defaultmember, [Product].[Stock Level].defaultmember, [Product].[Style].defaultmember, [Product].[Subcategory].defaultmember, [Product].[Weight].defaultmember, [Promotion].[Discount Percent].defaultmember, [Promotion].[End Date].defaultmember, [Promotion].[Max Quantity].defaultmember, [Promotion].[Min Quantity].defaultmember, [Promotion].[Promotion].defaultmember, [Promotion].[Promotion Category].defaultmember, [Promotion].[Promotion Type].defaultmember, [Promotion].[Promotions].defaultmember, [Promotion].[Start Date].defaultmember, [Reseller].[Address].defaultmember, [Reseller].[Annual Revenue].defaultmember, [Reseller].[Annual Sales].defaultmember, [Reseller].[Bank Name].defaultmember, [Reseller].[Business Type].defaultmember, [Reseller].[First Order Year].defaultmember, [Reseller].[Last Order Year].defaultmember, [Reseller].[Min Payment Amount].defaultmember, [Reseller].[Min Payment Type].defaultmember, [Reseller].[Number of Employees].defaultmember, [Reseller].[Order Frequency].defaultmember, [Reseller].[Order Month].defaultmember, [Reseller].[Phone].defaultmember, [Reseller].[Product Line].defaultmember, [Reseller].[Reseller].defaultmember, [Reseller].[Reseller Bank].defaultmember, [Reseller].[Reseller Order Frequency].defaultmember, [Reseller].[Reseller Order Month].defaultmember, [Reseller].[Reseller Type].defaultmember, [Reseller].[Year Opened].defaultmember, [Reseller Sales Order Details].[Carrier Tracking Number].defaultmember, [Reseller Sales Order Details].[Customer PO Number].defaultmember, [Reseller Sales Order Details].[Reseller Sales Orders].defaultmember, [Reseller Sales Order Details].[Sales Order Line].defaultmember, [Reseller Sales Order Details].[Sales Order Number].defaultmember, [Sales Channel].[Sales Channel].defaultmember, [Sales Reason].[Sales Reason].defaultmember, [Sales Reason].[Sales Reason Type].defaultmember, [Sales Reason].[Sales Reasons].defaultmember, [Sales Summary Order Details].[Carrier Tracking Number].defaultmember, [Sales Summary Order Details].[Customer PO Number].defaultmember, [Sales Summary Order Details].[Sales Order Line].defaultmember, [Sales Summary Order Details].[Sales Order Number].defaultmember, [Sales Summary Order Details].[Sales Orders].defaultmember, [Sales Territory].[Sales Territory].defaultmember, [Sales Territory].[Sales Territory Country].defaultmember, [Sales Territory].[Sales Territory Group].defaultmember, [Sales Territory].[Sales Territory Region].defaultmember, [Scenario].[Scenario].defaultmember, [Ship Date].[Calendar].defaultmember, [Ship Date].[Calendar Quarter of Year].defaultmember, [Ship Date].[Calendar Semester of Year].defaultmember, [Ship Date].[Calendar Year].defaultmember, [Ship Date].[Date].defaultmember, [Ship Date].[Day Name].defaultmember, [Ship Date].[Day of Month].defaultmember, [Ship Date].[Day of Week].defaultmember, [Ship Date].[Day of Year].defaultmember, [Ship Date].[Fiscal].defaultmember, [Ship Date].[Fiscal Quarter of Year].defaultmember, [Ship Date].[Fiscal Semester of Year].defaultmember, [Ship Date].[Fiscal Year].defaultmember, [Ship Date].[Month of Year].defaultmember, [Ship Date].[Week of Year].defaultmember, [Source Currency].[Source Currency].defaultmember, [Source Currency].[Source Currency Code].defaultmember )
GO
DROP MEMBER [Adventure Works].[Employee].[Employee].[All Employees].[BDA13F64-E5D5-418B-A4,A6,1F,C5,B8,44,2,54]

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Any insight into this problem would be much appreciated.

Jon

Do you think that we dont have nothing to do?!

...

|||Sorry, just trying to not leave out any details that would be helpful The
second (longer) MDX query is just to show how I managed to get correct results.

Jon

Calculations tab - MSAS 2005

Hi

Pretty new to this so bear with me:)

I have created a cube which has atm a single value measure and 5 dimensions which enable me to look at totals of the value measure in various ways - quite pleased I've managed to get this far without too many headaches.

I now need to create a new measure which will be the existing value measure didvided by a subset of the existing value measure. So lets say each value belongs to a group numbered 1-10. I need to have a new value which is 'value' divided by the total of values belonging to group 1. Hope thats clear :)

1. I think I need to create a new calculated member in the calculations tab of MSAS 2005, is that right?

2. Can I have an example of syntax how to do this? I know SQL very well but MDX not at all so knowing what I want but not how to get at it is very frustrating.

Thanks for any help you can give.

Wayne

Hi

Ad 1) Yes

Ad 2) Assuming that your "group" is an attribute in one of your dimensions, the following should work.

CASE WHEN ([Measures].[Value],[Dimension 1].[Group].[Group 1]) = 0
THEN NULL
ELSE [Measures].[Value]/([Measures].[Value],[Dimension 1].[Group].[Group 1])
END

And also you should set the "Non empty behavior" of the new calculated measure to [Measures].[Value].

|||

Couple of comments:

1) IIF is often preferable to CASE for performance reasons

2) For this calculation it is not possible to set NON_EMPTY_BEHAVIOR correctly in general case. Setting it to [Measures].[Value] will cause wrong results when [Measures].[Value] is 0 (as opposed to NULL). If you are sure it is never 0, then probably it will work.

|||

Thanks for those replies.

I've created a calculation but I'm not quite getting what I want yet. I'll flesh out my scenario a bit & maybe you can help some more :)

I am working with accounts data & each value in my cube is held against an accounting code. Each accounting code belongs to a hierarchy of groups which is 3 deep - I call them lvl1, lvl2 and lvl3.

I have data for many businesses which spans several years.

In order to compare one business' performance to another I need to divide each value in the cube by each £1000 of income for that business in that year. The income values have a lvl3 code of 'INCOME'. This is the bit I am having trouble with.

So my calculation as it stands atm is:

CALCULATE;

CREATE MEMBER CURRENTCUBE.[MEASURES].RatioVal

AS

CASE WHEN ([Measures].[Val],[Tbl Acc Codes].[Acc Lvl3 Code].[INCOME]) = 0

THEN 0

ELSE [Measures].[Val] /(([Measures].[Val],[Tbl Acc Codes].[Acc Lvl3 Code].[INCOME]) / -1000)

END

,

VISIBLE = 1 ;

When I look at the cube browser this seems to be giving me a ratioval on most of my group total lines but not for every value in the cube as I would like. I'm thinking that the income total is perhaps being calculated depinding on the position of each Val within the cube, when what I need is for the calculation to use the same income total for each business/year every time. So if a business has a total income of £25,000 for 2005 I want to divide every value in my cube for that business/year by 25.

Any help you can offer much appreciated & sorely needed :)

Thanks

Calculations Script Order and Formatting

I have a parent-child dimension for Accounts with a calculated member drapped off of the top level that figures Net Earnings % using a measure called Amount. As described by the name of the member, I need this expressed as a percentage. I am using this calc in the same view as a (Shell/Utility) Time Calculations dim that figures Year-to-date, Prior Year-to-date, YTD % Change, etc.... Depending on the order of the calculations in the calculations script I get different results. If I put the formula for the Net Earnings % before the MDX for the Time Calculations the results comes out correct but the formating gets overidden by the formating applied when the Time Calulations are applied. So the Net Earnings % for [YTD] and [YTD PY] are expressed as decimals and [YTD % Change] is expressed as a percentage. If I flip the order in the calculations script the formating gets corrected because the formatting of the Net Earnings % get applied last but my results for Net Earnings % are incorrect for [YTD % Change] because they were applied after the Time Calculations and end up applying the formula using the reults (the percentages) of the [YTD % Change] calc instead of the numbers used to make up that percentage.

Is there a way to put the Net Earnings % MDX before the Time Calculations MDX so that the results are correct for [YTD % Change] and reapply the formating of percent to [YTD] and [YTD PY] after the formatting of the Time Calculations get applied?

Nevermind, I figured it out. I placed the Net Earnings % MDX before the Time Calculations MDX and placed the following MDX after the Time Calculations MDX:

Code Snippet

Scope({[Account].[Account Hierarchy].[Net Earnings%]});

FORMAT_STRING(THIS) = "Percent";

End Scope;

|||

Nevermind, I figured it out. I placed the Net Earnings % MDX before the Time Calculations MDX and placed the following MDX after the Time Calculations MDX:

Code Snippet

Scope({[Account].[Account Hierarchy].[Net Earnings%]});

FORMAT_STRING(THIS) = "Percent";

End Scope;

Calculations Question

Hello,

Is there a way to make a Calculated Member aggregatable? I want to create a Calculated Member that performs a certain formula at the leaf level only. On the upper levels of the hierarchy I want the value aggregated, not the formula re-applied. Is there a way to achieve this?

Another question, is there a way to apply a special formula for a measure? and what is the "MeasureExpression" Property of a measure to be used for?

Thanks

For the first part:

You could create real measure that has all values as NULL. This will not take any space in database. Then you assign calculations in your calculated area and this measure will behave like real measure. This is based on Mosha Pasumansky suggestion here:

http://sqljunkies.com/WebLog/mosha/archive/2006/11/16/sqlpass_udm_presentation.aspx

Quote:

6. It isn't a problem that calculated measures don't aggregate up. If the designer need to add calculated measure which has aggregation semantics of a real measure, than there is very simple way to do it. Add a real measure to the measure group, and specify NULL as its column binding. It will cost nothing during processing, the partition size is going to be exactly the same, because AS will easily detect that measure value is constant and will compress it to 0 bits. But then in MDX Script, when expressions are assigned to that measure - they will aggregate up using measure's aggregation function - and it should work very efficiently too.

Some info about "MeasureExpression" property can be found in this thread: http://forums.microsoft.com/TechNet/ShowPost.aspx?PostID=768757&SiteID=17

Vidas Matelis

Calculations on members and aggregation

I'm designing a Profit And Loss report dimension that has the following attributes: Report Line, Cost Center and Account. Attribute relationships are defined between the attributes so that Report Line->Cost Center->Account.

A Report line is either A) A combination ofcost centers and accounts like:

Report Line A

- Cost Center 1

--Account 3000

--Account 3001

-Cost Center B

.. And so on

Or B) A calculation

I'm trying to handle calculations through mdx scripts by overwriting the value for those report lines that are calculations like:
scope (Report Line B);

this = Report Line A - Report Line C;

end scope

The problem is that the calculation report lines mess up the aggregation of the cube. I guess what I am really asking is wether its possible to turn off the members that are calculations in the aggregation of the cube. I realize i could use calculated measures for this but this doesnt fit my need for two reasons: Ease of use of the dimension and inability to drill down in reporting services on drillable members when calculated members are included.

Anyone have any ideas on this?

You can use the Freeze MDX statement to prevent changes to "Report Line B" from effecting the totals. To do this add simply apply Freeze to the all member of the hierarchy that contains Report Line B prior to updating Report Line B.

|||

Thanks!

Works like a charm, and as a bonus it helped me understand freeze

Calculations not working

I'm having a problem with my calculations not showing any data. I did delete the calculate script in my original cube so I created a new cube and recreated calculations but still get no data when I browse, any ideas?

Cheers,

Derek

I would guess you have a proble with calc script in your new cube.

Try first browsing your cube with default calc script and see if you got data for the real measures. Then start working your way and add more calculated measures to the point where you find a real culprit ;)

Edward.
--
This posting is provided "AS IS" with no warranties, and confers no rights.

calculations memory error

Deleted the measure part of a cube (by mistake) and put them back again (the same measures).

It works fine. All measures were there and all calculations when browsing the cube.

but I cannot change the calculations. "internal memory error corruption" (or like),

They don't show up in the calculations.

How can I get back my calculations?

Process the cube : no errors but still no calculations

There was a known bug in the BI Dev Studio in the calculation tab which caused this error. Upgrading to SP2 should solve this.

Calculations involving NULLs

I have a Calulated Member that is calculating an average.
[Measures].[Overall Satisfaction]/[Measures].[Count Of Survey]
The problem is that for some of the items there are no surveys, so there are
NULL values in the database for these.
When I view the cube as a pivot table in Excel I am getting #NUM! for any
dimentions that do not have actual numbers.
How can I change my calculation so it will just return NULL instead of the
dreaded #NUM! value that drives managers so crazy?
Thank you!
:-J
Jeremy
Use COALESCE or ISNULL function to change a NULL to a valid value or a
space.
Anith
|||REGARDS MY EXAMPLE
[Measures].[Average] AS ' IIF(ISNULL([Measures].[Count Of Survey]), NULL, [Measures].[Overall Satisfaction]/[Measures].[Count Of Survey]) '
You colud use ISNULL() with a tuple, for example ISNULL(([Time].[2004].CURRENTMEMBER, [Measures].[Overall Sastisfaction))
I hope it would help you
Agustin
|||Thank you for the help it got me going on the right track.
What I ended up with was:
IIF([Measures].[Count Of Survey]=0, NULL, [Measures].[Overall
Satisfaction]/[Measures].[Count Of Survey])
This seems to work perfectly!
Thanks agian!
-Jeremy
"Agustin Brau" <anonymous@.discussions.microsoft.com> wrote in message
news:759562E4-29AE-4697-AEE4-4290AF5A524D@.microsoft.com...
> REGARDS MY EXAMPLE
> --
> [Measures].[Average] AS ' IIF(ISNULL([Measures].[Count Of Survey]), NULL,
[Measures].[Overall Satisfaction]/[Measures].[Count Of Survey]) '
> --
> You colud use ISNULL() with a tuple, for example
ISNULL(([Time].[2004].CURRENTMEMBER, [Measures].[Overall Sastisfaction))
> I hope it would help you
> Agustin

Calculations involving NULLs

I have a Calulated Member that is calculating an average.
[Measures].[Overall Satisfaction]/[Measures].[Count Of Surve
y]
The problem is that for some of the items there are no surveys, so there are
NULL values in the database for these.
When I view the cube as a pivot table in Excel I am getting #NUM! for any
dimentions that do not have actual numbers.
How can I change my calculation so it will just return NULL instead of the
dreaded #NUM! value that drives managers so crazy?
Thank you!
:-J
JeremyUse COALESCE or ISNULL function to change a NULL to a valid value or a
space.
Anith|||REGARDS MY EXAMPLE
--
[Measures].[Average] AS ' IIF(ISNULL([Measures].[Count Of Su
rvey]), NULL, [Measures].[Overall Satisfaction]/[Measures].[
Count Of Survey]) '
--
You colud use ISNULL() with a tuple, for example ISNULL(([Time].[200
4].CURRENTMEMBER, [Measures].[Overall Sastisfaction))
I hope it would help you
Agustin|||Thank you for the help it got me going on the right track.
What I ended up with was:
IIF([Measures].[Count Of Survey]=0, NULL, [Measures].[Overal
l
Satisfaction]/[Measures].[Count Of Survey])
This seems to work perfectly!
Thanks agian!
-Jeremy
"Agustin Brau" <anonymous@.discussions.microsoft.com> wrote in message
news:759562E4-29AE-4697-AEE4-4290AF5A524D@.microsoft.com...
> REGARDS MY EXAMPLE
> --
> [Measures].[Average] AS ' IIF(ISNULL([Measures].[Count Of Survey])
, NULL,
[Measures].[Overall Satisfaction]/[Measures].[Count Of Survey]) 'reen">
> --
> You colud use ISNULL() with a tuple, for example
ISNULL(([Time].[2004].CURRENTMEMBER, [Measures].[Overall Sastisfaction))[vbc
ol=seagreen]
> I hope it would help you
> Agustin[/vbcol]

Calculations involving fields from different tables

Is it possible to perform a calculation with fields from different tables on
the same report? If so, what syntax is used to reference each field?
DavidYou need to reference the scope in the field. so, like
First(Fields!FieldName.Value, "DatasetName") or Sum(Fields!
FieldName.Value, "DataSetName")
>--Original Message--
>Is it possible to perform a calculation with fields from
different tables on
>the same report? If so, what syntax is used to reference
each field?
>David
>.
>

Calculations in the SQL Server

Hi All,
I am converting database from Access 2000 to SQL Server 2000.
I have very long calculations written in Access.
eg.
A+B as C, C+D as E, E + F as G and so on...
In SQL I created views, and they refer to each other. From my query
with calculation I created 5 views, where view 2 use calculations from
view 1, view 3 from view 2 and 1... and view 5 use view 1 to view 4. I
use those views in Stored Procedures with sum, average and LAST which
doesn't exist in SQL. (So that is another view)
All of that works but very slow.
Is there any better way to handle this kind of calulations?
Thank you
Schapopa
Deeply nested views can be slow. It might be better to simply create a
single view with all of the calcs you need...
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
"schapopa" <areklubinski@.hotmail.com> wrote in message
news:1112614187.922629.116440@.z14g2000cwz.googlegr oups.com...
> Hi All,
> I am converting database from Access 2000 to SQL Server 2000.
> I have very long calculations written in Access.
> eg.
> A+B as C, C+D as E, E + F as G and so on...
> In SQL I created views, and they refer to each other. From my query
> with calculation I created 5 views, where view 2 use calculations from
> view 1, view 3 from view 2 and 1... and view 5 use view 1 to view 4. I
> use those views in Stored Procedures with sum, average and LAST which
> doesn't exist in SQL. (So that is another view)
> All of that works but very slow.
> Is there any better way to handle this kind of calulations?
> Thank you
> Schapopa
>
|||Is there any other way. Those calculation are really big, and often
contain divisions. (where I am checking if value = 0) I would say that
it is impossible to create one view from those 5 views.
Wayne Snyder wrote:
> Deeply nested views can be slow. It might be better to simply create
a[vbcol=seagreen]
> single view with all of the calcs you need...
from[vbcol=seagreen]
4. I[vbcol=seagreen]
which[vbcol=seagreen]
|||On 4 Apr 2005 07:32:33 -0700, schapopa wrote:

>Is there any other way. Those calculation are really big, and often
>contain divisions. (where I am checking if value = 0) I would say that
>it is impossible to create one view from those 5 views.
Hi schapopa,
I'm not sure if it helps in your case, but you could consider using
derived tables. Something like this:
SELECT Expr1, Expr2, Expr1 + Expr2 AS Expr3
FROM (SELECT Col1 - Col2 AS Expr1, Col3 * Col4 AS Expr2, Col7
FROM SomeTable
WHERE Col5 > Col6) AS x
WHERE Expr1 <> Expr2
AND Expr2 + Col7 > 500
You can even nest them. The example below ussees two levels of nesting,
but you can add more.
SELECT Expr1, Expr2, Expr3,
COALESCE(Expr3 / NULLIF(Expr1 - Expr2, 0), 0) AS Expr4
FROM (SELECT Expr1, Expr2, Expr1 + Expr2 AS Expr3
FROM (SELECT Col1 - Col2 AS Expr1, Col3 * Col4 AS Expr2, Col7
FROM SomeTable
WHERE Col5 > Col6) AS x
WHERE Expr1 <> Expr2
AND Expr2 + Col7 > 500) AS y
WHERE Expr3 = 18
Best, Hugo
(Remove _NO_ and _SPAM_ to get my e-mail address)
|||Look at using scalar user-defined functions.
Without seeing the calculations you are trying to perform, you should still
be able to build a base set of functions that you can nest. Then, create
one VIEW that puts them all together.
Sincerely,
Anthony Thomas

"schapopa" <areklubinski@.hotmail.com> wrote in message
news:1112625153.408751.17040@.g14g2000cwa.googlegro ups.com...
Is there any other way. Those calculation are really big, and often
contain divisions. (where I am checking if value = 0) I would say that
it is impossible to create one view from those 5 views.
Wayne Snyder wrote:
> Deeply nested views can be slow. It might be better to simply create
a[vbcol=seagreen]
> single view with all of the calcs you need...
from[vbcol=seagreen]
4. I[vbcol=seagreen]
which[vbcol=seagreen]

Calculations in the SQL Server

Hi All,
I am converting database from Access 2000 to SQL Server 2000.
I have very long calculations written in Access.
eg.
A+B as C, C+D as E, E + F as G and so on...
In SQL I created views, and they refer to each other. From my query
with calculation I created 5 views, where view 2 use calculations from
view 1, view 3 from view 2 and 1... and view 5 use view 1 to view 4. I
use those views in Stored Procedures with sum, average and LAST which
doesn't exist in SQL. (So that is another view)
All of that works but very slow.
Is there any better way to handle this kind of calulations?
Thank you
SchapopaDeeply nested views can be slow. It might be better to simply create a
single view with all of the calcs you need...
--
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
"schapopa" <areklubinski@.hotmail.com> wrote in message
news:1112614187.922629.116440@.z14g2000cwz.googlegroups.com...
> Hi All,
> I am converting database from Access 2000 to SQL Server 2000.
> I have very long calculations written in Access.
> eg.
> A+B as C, C+D as E, E + F as G and so on...
> In SQL I created views, and they refer to each other. From my query
> with calculation I created 5 views, where view 2 use calculations from
> view 1, view 3 from view 2 and 1... and view 5 use view 1 to view 4. I
> use those views in Stored Procedures with sum, average and LAST which
> doesn't exist in SQL. (So that is another view)
> All of that works but very slow.
> Is there any better way to handle this kind of calulations?
> Thank you
> Schapopa
>|||Is there any other way. Those calculation are really big, and often
contain divisions. (where I am checking if value = 0) I would say that
it is impossible to create one view from those 5 views.
Wayne Snyder wrote:
> Deeply nested views can be slow. It might be better to simply create
a
> single view with all of the calcs you need...
> > Hi All,
> >
> > I am converting database from Access 2000 to SQL Server 2000.
> > I have very long calculations written in Access.
> > eg.
> > A+B as C, C+D as E, E + F as G and so on...
> >
> > In SQL I created views, and they refer to each other. From my query
> > with calculation I created 5 views, where view 2 use calculations
from
> > view 1, view 3 from view 2 and 1... and view 5 use view 1 to view
4. I
> > use those views in Stored Procedures with sum, average and LAST
which
> > doesn't exist in SQL. (So that is another view)
> >
> > All of that works but very slow.
> >
> > Is there any better way to handle this kind of calulations?|||On 4 Apr 2005 07:32:33 -0700, schapopa wrote:
>Is there any other way. Those calculation are really big, and often
>contain divisions. (where I am checking if value = 0) I would say that
>it is impossible to create one view from those 5 views.
Hi schapopa,
I'm not sure if it helps in your case, but you could consider using
derived tables. Something like this:
SELECT Expr1, Expr2, Expr1 + Expr2 AS Expr3
FROM (SELECT Col1 - Col2 AS Expr1, Col3 * Col4 AS Expr2, Col7
FROM SomeTable
WHERE Col5 > Col6) AS x
WHERE Expr1 <> Expr2
AND Expr2 + Col7 > 500
You can even nest them. The example below ussees two levels of nesting,
but you can add more.
SELECT Expr1, Expr2, Expr3,
COALESCE(Expr3 / NULLIF(Expr1 - Expr2, 0), 0) AS Expr4
FROM (SELECT Expr1, Expr2, Expr1 + Expr2 AS Expr3
FROM (SELECT Col1 - Col2 AS Expr1, Col3 * Col4 AS Expr2, Col7
FROM SomeTable
WHERE Col5 > Col6) AS x
WHERE Expr1 <> Expr2
AND Expr2 + Col7 > 500) AS y
WHERE Expr3 = 18
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Look at using scalar user-defined functions.
Without seeing the calculations you are trying to perform, you should still
be able to build a base set of functions that you can nest. Then, create
one VIEW that puts them all together.
Sincerely,
Anthony Thomas
"schapopa" <areklubinski@.hotmail.com> wrote in message
news:1112625153.408751.17040@.g14g2000cwa.googlegroups.com...
Is there any other way. Those calculation are really big, and often
contain divisions. (where I am checking if value = 0) I would say that
it is impossible to create one view from those 5 views.
Wayne Snyder wrote:
> Deeply nested views can be slow. It might be better to simply create
a
> single view with all of the calcs you need...
> > Hi All,
> >
> > I am converting database from Access 2000 to SQL Server 2000.
> > I have very long calculations written in Access.
> > eg.
> > A+B as C, C+D as E, E + F as G and so on...
> >
> > In SQL I created views, and they refer to each other. From my query
> > with calculation I created 5 views, where view 2 use calculations
from
> > view 1, view 3 from view 2 and 1... and view 5 use view 1 to view
4. I
> > use those views in Stored Procedures with sum, average and LAST
which
> > doesn't exist in SQL. (So that is another view)
> >
> > All of that works but very slow.
> >
> > Is there any better way to handle this kind of calulations?

Calculations in the SQL Server

Hi All,
I am converting database from Access 2000 to SQL Server 2000.
I have very long calculations written in Access.
eg.
A+B as C, C+D as E, E + F as G and so on...
In SQL I created views, and they refer to each other. From my query
with calculation I created 5 views, where view 2 use calculations from
view 1, view 3 from view 2 and 1... and view 5 use view 1 to view 4. I
use those views in Stored Procedures with sum, average and LAST which
doesn't exist in SQL. (So that is another view)
All of that works but very slow.
Is there any better way to handle this kind of calulations?
Thank you
SchapopaDeeply nested views can be slow. It might be better to simply create a
single view with all of the calcs you need...
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
"schapopa" <areklubinski@.hotmail.com> wrote in message
news:1112614187.922629.116440@.z14g2000cwz.googlegroups.com...
> Hi All,
> I am converting database from Access 2000 to SQL Server 2000.
> I have very long calculations written in Access.
> eg.
> A+B as C, C+D as E, E + F as G and so on...
> In SQL I created views, and they refer to each other. From my query
> with calculation I created 5 views, where view 2 use calculations from
> view 1, view 3 from view 2 and 1... and view 5 use view 1 to view 4. I
> use those views in Stored Procedures with sum, average and LAST which
> doesn't exist in SQL. (So that is another view)
> All of that works but very slow.
> Is there any better way to handle this kind of calulations?
> Thank you
> Schapopa
>|||Is there any other way. Those calculation are really big, and often
contain divisions. (where I am checking if value = 0) I would say that
it is impossible to create one view from those 5 views.
Wayne Snyder wrote:
> Deeply nested views can be slow. It might be better to simply create
a[vbcol=seagreen]
> single view with all of the calcs you need...
>
from[vbcol=seagreen]
4. I[vbcol=seagreen]
which[vbcol=seagreen]|||On 4 Apr 2005 07:32:33 -0700, schapopa wrote:

>Is there any other way. Those calculation are really big, and often
>contain divisions. (where I am checking if value = 0) I would say that
>it is impossible to create one view from those 5 views.
Hi schapopa,
I'm not sure if it helps in your case, but you could consider using
derived tables. Something like this:
SELECT Expr1, Expr2, Expr1 + Expr2 AS Expr3
FROM (SELECT Col1 - Col2 AS Expr1, Col3 * Col4 AS Expr2, Col7
FROM SomeTable
WHERE Col5 > Col6) AS x
WHERE Expr1 <> Expr2
AND Expr2 + Col7 > 500
You can even nest them. The example below ussees two levels of nesting,
but you can add more.
SELECT Expr1, Expr2, Expr3,
COALESCE(Expr3 / NULLIF(Expr1 - Expr2, 0), 0) AS Expr4
FROM (SELECT Expr1, Expr2, Expr1 + Expr2 AS Expr3
FROM (SELECT Col1 - Col2 AS Expr1, Col3 * Col4 AS Expr2, Col7
FROM SomeTable
WHERE Col5 > Col6) AS x
WHERE Expr1 <> Expr2
AND Expr2 + Col7 > 500) AS y
WHERE Expr3 = 18
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)|||Look at using scalar user-defined functions.
Without seeing the calculations you are trying to perform, you should still
be able to build a base set of functions that you can nest. Then, create
one VIEW that puts them all together.
Sincerely,
Anthony Thomas
"schapopa" <areklubinski@.hotmail.com> wrote in message
news:1112625153.408751.17040@.g14g2000cwa.googlegroups.com...
Is there any other way. Those calculation are really big, and often
contain divisions. (where I am checking if value = 0) I would say that
it is impossible to create one view from those 5 views.
Wayne Snyder wrote:
> Deeply nested views can be slow. It might be better to simply create
a[vbcol=seagreen]
> single view with all of the calcs you need...
>
from[vbcol=seagreen]
4. I[vbcol=seagreen]
which[vbcol=seagreen]

Calculations in Page Footer

hai,
i need some help regarding calculations done in page footer. Presently i am developing a report using subreports. I am not utilising pageNofM concept. and i have to display page numbers manually. If i have 2 subreports in one main report. i have to display page numbers like this.

If my 1st subreport is displaying 2 pages, then i have to display like this

1 Page 1 of 2
1 Page 2 of 2

If my 2nd subreport is displaying 2 pages, then i have to display like this

2 Page 1 of 2
2 Page 2 of 2

Page left side printed numbers are related to subreport numbers. if the page shows first subreport then it shows 1 otherwise 2. i have coded this successfully in main report and placed this formula at left side of the page footer. i am facing problem at subreport page count. I have used to code this using page number but the left side value changes if I wrote any code in the formula which displays page 1 of 2 which i placed at right side of the page. since 1 week i am trying for this concept

can anybody help me?

Thanks in advance,
BhuvanaBhuvana,
Can you post the code you used in the formula?|||I have split the group header into 2 and placed the same subreport in each section.

I have used this code in a formula placed in each group header section

global i as number
whileprintingrecords
i=i+1
formula=i

i have used this code to display subreport number left side and placed this formula leftside of the main report page.

global i as number
whileprintingrecords
formula=replace(cstr(i),".00","")

It is perfectly working. The problem with rightside page number printing.

Rightside of the page i have used this code to print page numbers

whileprintingrecords
global i as number
global p as number

if replace(cstr(i),".00","")="1" then
formula="Page "+replace(cstr(pagenumber),".00","")
elseif replace(cstr(i),".00","")="2" then
formula="Page "+Replace(cstr((pagenumber-p)),".00","")+" of "+ Replace(cstr(p),".00","")
elseif replace(cstr(i),".00","")="3" then
formula="Page "+Replace(cstr((pagenumber-(2*p))),".00","")+" of "+ Replace(cstr(p),".00","")
elseif replace(cstr(i),".00","")="4" then
formula="Page "+Replace(cstr((pagenumber-(3*p))),".00","")+" of "+ Replace(cstr(p),".00","")
end if

and i have placed the following code in pagefooter section and supressed it

global p as number
whileprintingrecords
if {@.SampleFormula}="1" then
p=p+1
end if
formula=p

I have assigned "1" to sampleformula in first group header section and assigned 0 to sampleformula in second group header section.

Please provide me the solution
Bhuvana|||Bhuvana,
As you have used the variable formula at the right side code, change of formula will affect the value of formula at left side code. What is your expected outcome at the right side?|||hai,
suppose if i have total number of pages in 1st subreport is 4 then i want to display right side as page 1 of 4 for page 1, page 2 of 4 for page 2 and so on. while displaying second subreport first page i want to repeat as page 1 of 4 ,
page 2 of 4, page 3 of 4, page 4 of 4 etc.

i am waiting for your reply

Regards,
Bhuvana|||Bhuvana,
At the formula you used at the right side, try to use different name other than formula as that is referenced by other Formula code

Calculations in Mdx Query

How to show the vlaues of increase in salary for few departments along with other departments.

Ex

we have A,B,C,D departments having total salary of 1000 each

A 1000

B 1000

c 1000

d 1000

Total 4000

If there was an increment of 2% for A and C deptment

Then I want to see the results as

Old_sal NewSal

A 1000 1020

B 1000 1000

C 1000 1020

D 1000 1000

Total 4000 4040

Please help to write the mdx query to populate the above results.

I am using Pivot table as client

Thanks In advance

The simplest technique is using a calculated member which detects the current department member and increases the Old_Sal by a percentage to give the NewSal value. The drawback to this technique is "hardcoding" the detection of the department in the calculated member making the calculation somewhat inflexible. However, without knowing a lot more detail about your model this is the best suggestion I have. Here's the MDX for the calculated member [NewSal]

WITH MEMBER Measures.[NewSal] AS
'
IIF([Department].[Department].CurrentMember.Name = "A" OR [Department].[Department].CurrentMember.Name = "C",
Measures.[Old_Sal] * 1.2,
Measures.[Old_Sal])
'

SELECT {Measures.[Old_Sal], Measures.[NewSal]} ON COLUMNS
,{[Department].[Department].[<your level>].Members} ON ROWS
FROM [your cube]

Hope this helps.

PGoldy

|||

Hello Paul. I have thought about the same problem. Will this work in a MDX-script?

Create Member CurrentCube.[Measures].[NewSal] AS "NA";
SCOPE ([Department].Members) =
( CASE
When [Department].CurrentMember IS [Department].[ DepA]
OR [Department].CurrentMember IS [Department].[ DepB]
THEN [Salary]*1.2
ELSE [Salary]
END);

This is with the assumption that you have correct attribute relations defined.

Regards

Thomas Ivarsson

|||

This should instead be formulated as:

Create Member CurrentCube.[Measures].[NewSal] AS [Measures].[Salary];
SCOPE ({[Department].[DepA],[Department].[DepB]}, [Measures].[NewSal]);
This = 1.2 * [Measures].[Salary];
END SCOPE;

|||

Thanks for the responses to every body.

Using these I can change the values but as I am using pivot table in the aspx page. The total are not calculated. They show the same old total.

How to get the new total also..

Thanks

|||

Hi Anil:

Using the CreateMember... as Michael, and Thomas suggested (Thanks Michael and Thomas) is a change to the cube definition which resides on the server. When the new calculated member resides on the server you can reference is from your pivot table and see [Measures].[NewSal] as an additional measure.

Hope this helps - PaulG

|||

Thank you Micheal, Thomas and paul for giving me valuble responses

I understood what you are saying.

I am still having problems with executing these.

I am new to analysis services and pivot table concepts.

I am using asp.net 2003 and sql server 2000

I wish to do the above logic at a click of a button.

Could you guys pleas help in to provide steps How to proceed for this scenario.

in the below code

cmd.execute is giving error saying syntax error.

Please Help!!!

Dim m_XML As String

Dim strOLAPConn As String = ConfigurationSettings.AppSettings("OLAPConnectionString")

Dim objPT As PivotTableClass = New PivotTableClass

Dim objPTView As PivotView

Dim fldFCElement, fldCenter, fldProcess, fldHierarchy As PivotField

Dim fSetFCElement, fsetOrgTitle, fSetProcess, fsetOrgAttr, fsetCenter, fsetHierarchy As PivotFieldSet

Try

Dim cnn As New ADODB.Connection

Dim cmd As New ADODB.Command

Dim rs As New ADOMD.Cellset

cnn.ConnectionString = strOLAPConn

cnn.Open()

cmd.ActiveConnection = cnn

Cmd.CommandText = "Create Member Demo.[Measures].[NewSal] AS '[Measures].[BY];SCOPE ({[Center].[NASA Headquarters]}, [Measures].[NewSal]);This = 1.2 * [Measures].[BY];END SCOPE;'"

cmd.Execute()

objPT.ConnectionString = cnn.ConnectionString

objPT.Toolbar.Enabled = True

objPT.DataMember = "Demo"

objPT.AutoFit = True

objPTView = objPT.ActiveView

fSetProcess = objPTView.FieldSets("Process")

objPT.ActiveView.ColumnAxis.InsertFieldSet(fSetProcess)

...

...

.

|||

Ahhh... Yes. The command you are trying to send will not work. First of all, what I suggested was syntax for Analysis Services 2005. Apparently, you are connecting to an Analysis Services 2000 instance, so that is one reason why it does not work... Even if you were connecting to AS2005, it still would not work, since SCOPE statements need to be defined on the server.

Now, if what you need to do is create the calculated member with DDL, your CommandText should be something like:

CREATE MEMBER Demo.[Measures].[NewSal] AS 'IIF([Department].[Department].CurrentMember IS [Department].[Department].Angel OR [Department].[Department].CurrentMember IS [Department].[Department].Coffee, Measures.[Old_Sal] * 1.2, Measures.[Old_Sal])'

This will, of course, not return any data, why you could use the ExecuteNonQuery() method on your Command object for clarity - at least you can do this with ADOMD.NET, not quite sure about ADOMD.

Calculations in Matrix report

I have a Report Designer problem, whereby I need to perform a calculation on
each row of data laid out in a crosstab.
My datasource is a flat xml file (read into a dataset), and consists of the
following repeat base units:-
<base>
<StartDate>2006-04-10</StartDate>
<EndDate>2006-04-17</EndDate>
<Category>Books</Category>
<Amount>100</Amount>
</base>
<base>
<StartDate>2006-04-18</StartDate>
<EndDate>2006-04-25</EndDate>
<Category>CDs</Category>
<Amount>200</Amount>
</base>
...etc
I need to present this in the following way:-
Week 1 Week 2
10th-17th April 18th-25th April Calculation
Category
Books 100 300 week2 - week1
CDs 200 400 week2 - week1
..etc
The two options I have in the designer toolbox are:-
1) To use a matrix - this allows variable column data (period start date to
period end date), with variable row data (category), to be laid out as a
crosstab, but I can find no way of identifying individual cells within the
matrix to use in the calculation at the end of each row. Matrices only
appear to support totals/subtotals'
2) To use a table - is it possible to present the repeat base units shown
above in the form of a table? I can find the max EndDate in the dataset, but
is there some method of filtering the data so I can work out (period + 1
week), (period + 2 weeks), etc and then reference individual cells in the
table for the calculation'
Neither approach appears to allow crosstab representation of the data, with
calculations on each row. Is this possible?
I would like to avoid having to assemble the raw data in the form of fixed
'buckets', i.e.
<base>
<Category>Books</Category>
<Period1>2006-04-10</Period1>
<Amount1>100</Amount1>
<Period2>2006-04-18</Period2>
<Amount2>200</Amount2>
<Period3>2006-04-26</Period3>
<Amount3>400</Amount3>
</base>
<base>
<Category>CDs</Category>
<Period1>2006-04-10</Period1>
<Amount1>100</Amount1>
<Period2>2006-04-18</Period2>
<Amount2>200</Amount2>
<Period3>2006-04-26</Period3>
<Amount3>400</Amount3>
</base>
...etc
Can anyone see a solution?Hi Pete,
Thank you for using MSDN Managed Newsgroup Support.
From your description, my undestanding of this issue is : You want to add a
Calculation column in the Matrix or Table region. If I misunderstood your
concern, please feel free to let me know.
Based on my scope, I think you could add a calculated field in the dataset
and then try to present this field in the layout:
1. In the Data page in the Report Designer, click the Edit Selected dataset
button.
2. In the Dataset Dialogbox, please click the Fields Page and then type the
Field name, choose the Type as Calculated Field and then type the
Expression you want to use.
After doing this, I think you could put the calculated field in any data
region.
Hope this information will be helpful!
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Thanks for your prompt response Wei.
Unfortunately, my issue is not as simple as adding a calculation to the
matrix/table.
My data is represented by a crosstab. I wish to add a calculation column,
which is an expression that references two preceding cells in the same row,
for example...
---Calculation
Row1 Cell1 Cell2 Cell3 Cell4 Cell4/Cell3
---
This does not appear possible with a matrix. And because I have variable
columns, it does not appear possible to lay the data out in tabular form
either (which would allow me to reference individual cells).
Can you see a solution to this more complex issue?
Thanks
Pete
"Wei Lu [MSFT]" <weilu@.online.microsoft.com> wrote in message
news:SaUsE8MoGHA.2028@.TK2MSFTNGXA01.phx.gbl...
> Hi Pete,
> Thank you for using MSDN Managed Newsgroup Support.
> From your description, my undestanding of this issue is : You want to add
> a
> Calculation column in the Matrix or Table region. If I misunderstood your
> concern, please feel free to let me know.
> Based on my scope, I think you could add a calculated field in the dataset
> and then try to present this field in the layout:
> 1. In the Data page in the Report Designer, click the Edit Selected
> dataset
> button.
> 2. In the Dataset Dialogbox, please click the Fields Page and then type
> the
> Field name, choose the Type as Calculated Field and then type the
> Expression you want to use.
> After doing this, I think you could put the calculated field in any data
> region.
> Hope this information will be helpful!
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>|||Hi Pete,
Thank you for the update.
I would like to know what do you mean about the variable columns. Since
Reporting Services use dataset to get the data from the datasource, I would
like to know how you implement variable columns in the dataset.
If the field name does not consist, I don't think you could refer any field
in the Expression. So please let me know the exactly meaning of "variable
columns" so that I may provide further assistance. Thank you!
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi Wei,
The dataset generated by our datasource consists of the following fields:
StartDate
EndDate
Category
Amount
i.e. the data is periodic (weekly). We need to present this as follows:
Week 1 Week 2 Week 3
10th-17th April 18th-25th April 26th-3rd
Calculation
Category
Books 100 300 200
week3 - week2
CDs 200 400 150
week3 - week2
..etc
We can do this using a matrix, with 3 groupings: Category (row), StartDate
(column), EndDate (column).
What I meant was the columns are variable in Start/EndDate. But we know no
way of performing the calculation. Is this possible?
Or is there a way to do it if we use a table instead of a matrix?
Thanks in advance
Pete
"Wei Lu [MSFT]" <weilu@.online.microsoft.com> wrote in message
news:7vnx8XOoGHA.2028@.TK2MSFTNGXA01.phx.gbl...
> Hi Pete,
> Thank you for the update.
> I would like to know what do you mean about the variable columns. Since
> Reporting Services use dataset to get the data from the datasource, I
> would
> like to know how you implement variable columns in the dataset.
> If the field name does not consist, I don't think you could refer any
> field
> in the Expression. So please let me know the exactly meaning of "variable
> columns" so that I may provide further assistance. Thank you!
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>|||Sorry, my last post might be confusing... the matrix should look like:
Week 1 Week 2 Week 3
10th-17th 18th-25th 26th-3rd Calculation
Category
Books 100 300 200 week3 - week2
CDs 200 400 150 week3 - week2
..etc
"Pete D" <peted@.community.nospam> wrote in message
news:u7enVZQoGHA.4176@.TK2MSFTNGP05.phx.gbl...
> Hi Wei,
> The dataset generated by our datasource consists of the following fields:
> StartDate
> EndDate
> Category
> Amount
> i.e. the data is periodic (weekly). We need to present this as follows:
> Week 1 Week 2 Week 3
> 10th-17th April 18th-25th April 26th-3rd
> Calculation
> Category
> Books 100 300 200
> week3 - week2
> CDs 200 400 150
> week3 - week2
> ..etc
> We can do this using a matrix, with 3 groupings: Category (row), StartDate
> (column), EndDate (column).
> What I meant was the columns are variable in Start/EndDate. But we know no
> way of performing the calculation. Is this possible?
> Or is there a way to do it if we use a table instead of a matrix?
> Thanks in advance
> Pete
>
> "Wei Lu [MSFT]" <weilu@.online.microsoft.com> wrote in message
> news:7vnx8XOoGHA.2028@.TK2MSFTNGXA01.phx.gbl...
>> Hi Pete,
>> Thank you for the update.
>> I would like to know what do you mean about the variable columns. Since
>> Reporting Services use dataset to get the data from the datasource, I
>> would
>> like to know how you implement variable columns in the dataset.
>> If the field name does not consist, I don't think you could refer any
>> field
>> in the Expression. So please let me know the exactly meaning of "variable
>> columns" so that I may provide further assistance. Thank you!
>> Sincerely,
>> Wei Lu
>> Microsoft Online Community Support
>> ==================================================>> When responding to posts, please "Reply to Group" via your newsreader so
>> that others may learn and benefit from your issue.
>> ==================================================>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>|||Hi Pete,
Thank you for the update. I would like to get your report file to do more
research.
Would you pleae send the report file to me?
You may send to me directly. I understand the information may be sensitive
to you, my direct email address is weilu@.ONLINE.microsoft.com ( Please
remove ONLINE when you send the email ), you may send the file to me
directly and I will keep it secure.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi,
Are you able to solve this issue with Matrix, i have the similar kind
of requirement. If yes pls let me know how could you achieve it
FYI: my req is as mentioned( hope i am clear, else let me know)
Thanks in advance..
Venkat
*******************
Hello,
I am using matrix control for which the rows, columns are all dynamic(
based on the group i specify). I am able to get the Subtotal for both
the rows and colums, which is Great!!..
my problem is i need to add more columns(some formula columns) which
might have "% difference", "varience" etc..
the report should look something like this (M1, M2 are model_id's)
Div/Sec M1 M2 Variance % Difference
----==AD--
O3580 0.71 1.47 -0.76 -107.04
8040 1.33 1.33 0 0
8110 9.98 14.47 -4.49 -44.99
11210 5.44 6.36 -0.92 -16.91
and my query is :
select div_sec, model_ID, model_time from table1
the output of my query is below( seperated by commas)
div_sec, model_ID, model_time
O3580,M1,0.7
O3580,M2,1.47
8040 ,M1,1.33
8040 ,M2,1.33
8110 ,M1,9.98
8110 ,M2,14.47
11210 ,M1,5.44
11210 ,M2,6.36
Any help is greatly appreciated.
Thanks,
Venkat
Wei Lu [MSFT] wrote:
> Hi Pete,
> Thank you for the update. I would like to get your report file to do more
> research.
> Would you pleae send the report file to me?
> You may send to me directly. I understand the information may be sensitive
> to you, my direct email address is weilu@.ONLINE.microsoft.com ( Please
> remove ONLINE when you send the email ), you may send the file to me
> directly and I will keep it secure.
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D==3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D==3D
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D==3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D==3D
> This posting is provided "AS IS" with no warranties, and confers no right=s=2E|||Hi Pete,
Thank you for the file.
After some research, I found that we could not meet the requirement in
Matrix. The Static column in Matrix does not meet your requirement.
As for the table control, it is not suitable to use table as a dynamic
columns data region.
I will try to contact internal to check whether there is an suitable
workaround for you. I appreciate your patience.
Sincerely,
Wei Lu
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi Wei,
Appreciate if you can look into my problem too(its up in this thread)..
I think its almost the same.
Let me know if you find any solution for this issue. This is a Top
reqirement for lots of my reports.
Thanks,
Venkat
Wei Lu [MSFT] wrote:
> Hi Pete,
> Thank you for the file.
> After some research, I found that we could not meet the requirement in
> Matrix. The Static column in Matrix does not meet your requirement.
> As for the table control, it is not suitable to use table as a dynamic
> columns data region.
> I will try to contact internal to check whether there is an suitable
> workaround for you. I appreciate your patience.
> Sincerely,
> Wei Lu
> Microsoft Online Community Support
> ==================================================> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================> This posting is provided "AS IS" with no warranties, and confers no rights.|||I've posted details of my report/requirement to Wei to determine whether
there's a solution to my problem.
Its seems that Venkat and "dbro101" both have very similar issues (re:
separate postings on 12th July)
If I become aware of a solution I'll post details here.
Pete
<venkat.oar@.gmail.com> wrote in message
news:1152883485.115457.194350@.h48g2000cwc.googlegroups.com...
> Hi Wei,
> Appreciate if you can look into my problem too(its up in this thread)..
> I think its almost the same.
> Let me know if you find any solution for this issue. This is a Top
> reqirement for lots of my reports.
> Thanks,
> Venkat
> Wei Lu [MSFT] wrote:
>> Hi Pete,
>> Thank you for the file.
>> After some research, I found that we could not meet the requirement in
>> Matrix. The Static column in Matrix does not meet your requirement.
>> As for the table control, it is not suitable to use table as a dynamic
>> columns data region.
>> I will try to contact internal to check whether there is an suitable
>> workaround for you. I appreciate your patience.
>> Sincerely,
>> Wei Lu
>> Microsoft Online Community Support
>> ==================================================>> When responding to posts, please "Reply to Group" via your newsreader so
>> that others may learn and benefit from your issue.
>> ==================================================>> This posting is provided "AS IS" with no warranties, and confers no
>> rights.
>|||Hi Pete,
Thank you for your followup. Since Wei is absent due to some urgent issues,
I'm continueing to help you on this issue. I've got the problem description
and sample report files from wei and will perform some research on them. I
will update you as soon as possible.
Thank you for the patience and understanding.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead|||Hello Pete,
Sorry for keep you waiting. After some further research, we've come out to
the same results as Wei has told you in the previous message, the built-in
reporting service report items(Table or Matrix) are not able to accomplish
the task. I've also involved some other SQL engineers to discuss the issue
and they've help confirmed on this. So far they pointed out that it may be
possible to use a custom data processing extension to precaculate the
additional results, and the key point is that you need to correctly pass
the parameters into the custom data processing engine. I'm sorry that we
haven't been able to help you further on this. If there is anything else we
can help, please feel free to let me know.
Thanks for your understanding!
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.|||Hi
I was just wondering if there was any progress regarding this subject.
I am sitting with a similar problem and am unable to find a workaround.
Thanks for all the effort that has been put into solving the problem thus far.
"Steven Cheng[MSFT]" wrote:
> Hello Pete,
> Sorry for keep you waiting. After some further research, we've come out to
> the same results as Wei has told you in the previous message, the built-in
> reporting service report items(Table or Matrix) are not able to accomplish
> the task. I've also involved some other SQL engineers to discuss the issue
> and they've help confirmed on this. So far they pointed out that it may be
> possible to use a custom data processing extension to precaculate the
> additional results, and the key point is that you need to correctly pass
> the parameters into the custom data processing engine. I'm sorry that we
> haven't been able to help you further on this. If there is anything else we
> can help, please feel free to let me know.
> Thanks for your understanding!
> Sincerely,
> Steven Cheng
> Microsoft MSDN Online Support Lead
> ==================================================>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>|||I know you can put a percent of total dim calculation on a dynamic matrix
report by using the year matrix group as a component of the calculation, i.e,
"matrix1_Year". See Brian Larson's Delivering Business Intelligence book
page 596 - 597. I wish there were an example of doing a variance column, but
if it can do this calculated field, then it looks like using the same
approach could do others. This example is based on a matrix report sourced
from an Analysis Services 2005 cube.
"Glaciered Pyro" wrote:
> Hi
> I was just wondering if there was any progress regarding this subject.
> I am sitting with a similar problem and am unable to find a workaround.
> Thanks for all the effort that has been put into solving the problem thus far.
> "Steven Cheng[MSFT]" wrote:
> > Hello Pete,
> >
> > Sorry for keep you waiting. After some further research, we've come out to
> > the same results as Wei has told you in the previous message, the built-in
> > reporting service report items(Table or Matrix) are not able to accomplish
> > the task. I've also involved some other SQL engineers to discuss the issue
> > and they've help confirmed on this. So far they pointed out that it may be
> > possible to use a custom data processing extension to precaculate the
> > additional results, and the key point is that you need to correctly pass
> > the parameters into the custom data processing engine. I'm sorry that we
> > haven't been able to help you further on this. If there is anything else we
> > can help, please feel free to let me know.
> >
> > Thanks for your understanding!
> >
> > Sincerely,
> >
> > Steven Cheng
> >
> > Microsoft MSDN Online Support Lead
> >
> > ==================================================> >
> >
> > This posting is provided "AS IS" with no warranties, and confers no rights.
> >
> >|||I Have found that the easiest solution to this problem is
to write custom code using vb.net or c#. Though it might
not be the most efficient... it works. Just add a Table next to
the matrix, write the code to collect the data and calculate
whatever you need to, then simply call it from the table...

Calculations in Database

I have a procedure that is performing a calculation and returning a amount, how do I store or save that amount and use it in different procedure to perform another calculationYou can simply store the value in a temporatry table.|||

Quote:

Originally Posted by debasisdas

You can simply store the value in a temporatry table.


how does one create a temporary table|||Hi,

maybe I am not understanding this but I would ask why you want to save a derived value - why not just call the first calculation procedure from the second then your data is guaranteed to be an acurate reflection of what is on the database at the time of the query..

Just my thoughts..

Regards Purple|||Yes that will be a better option.|||Thank you all, it worked out perfectly. I tried Purples advice and it was exactly what was needed. Thanks again|||Hi hopechirume,

I am pleased we were able to assist - look forward to seeing you around again soon.

Regards Purple

Calculations in a subcube world

I'm having trouble getting my calculations to work with query tools that use subcubes in the WHERE clause instead of a normal slicer. Both Excel 2007 and SSRS (when using the query designer) use this technique.

This is an example of a calculation:

CREATE MEMBER CURRENTCUBE.[MEASURES].[YTD]

AS SUM(

PERIODSTODATE([Time].[Y-Q-M-D].[Year],

[Time].[Y-Q-M-D].CurrentMember),

[Measures].CurrentMember),

FORMAT_STRING = "#,#",

VISIBLE = 1;

A typical query through Excel 12 will use the following MDX to filter when selecting March 2006 from a time hierarchy:

..FROM (SELECT ({[Time].[Y-Q-M-D].[Quarter].&[2006]&[1]}) ON COLUMNS FROM [Datawarehouse])

Instead of the old-fashioned

WHERE([Time].[Y-Q-M-D].[Quarter].&[2006]&[1])

When querying for March 2006 filtered by a subcube the mentioned calculated member will return NULL, when hand crafting the query using the WHERE construct, it will return the expected results.

Running a select through Excel 2007 with the filter and the following test member makes the problem obvious:

CREATE MEMBER CURRENTCUBE.[MEASURES].[test]

AS [Time].[Y-Q-M-D].CurrentMember.Name,

VISIBLE = 1;

The .CurentMember of the Y-Q-M-D hierarchy is the All member when a subcube is used, not the actual member(s) in the filter.

Can anyone advice me on how to formulate my calculations so they work with subcubes?

Hi Peter

This is a known issue. Please see the following blog entry for an elaboration.

http://www.sqljunkies.com/WebLog/reckless/archive/2006/03/08/18601.aspx

Calculations in a subcube world

I'm having trouble getting my calculations to work with query tools that use subcubes in the WHERE clause instead of a normal slicer. Both Excel 2007 and SSRS (when using the query designer) use this technique.

This is an example of a calculation:

CREATE MEMBER CURRENTCUBE.[MEASURES].[YTD]

AS SUM(

PERIODSTODATE([Time].[Y-Q-M-D].[Year],

[Time].[Y-Q-M-D].CurrentMember),

[Measures].CurrentMember),

FORMAT_STRING = "#,#",

VISIBLE = 1;

A typical query through Excel 12 will use the following MDX to filter when selecting March 2006 from a time hierarchy:

..FROM (SELECT ({[Time].[Y-Q-M-D].[Quarter].&[2006]&[1]}) ON COLUMNS FROM [Datawarehouse])

Instead of the old-fashioned

WHERE([Time].[Y-Q-M-D].[Quarter].&[2006]&[1])

When querying for March 2006 filtered by a subcube the mentioned calculated member will return NULL, when hand crafting the query using the WHERE construct, it will return the expected results.

Running a select through Excel 2007 with the filter and the following test member makes the problem obvious:

CREATE MEMBER CURRENTCUBE.[MEASURES].[test]

AS [Time].[Y-Q-M-D].CurrentMember.Name,

VISIBLE = 1;

The .CurentMember of the Y-Q-M-D hierarchy is the All member when a subcube is used, not the actual member(s) in the filter.

Can anyone advice me on how to formulate my calculations so they work with subcubes?

Hi Peter

This is a known issue. Please see the following blog entry for an elaboration.

http://www.sqljunkies.com/WebLog/reckless/archive/2006/03/08/18601.aspx

calculations in a self-join (was "Query")

Hi all,
If I have a table like the following: (Table Name is A)
ID Date Time DeviceNumber Sum
1 1/12/2004 06:00:00 1 200
2 1/12/2004 08:00:00 1 600
3 1/12/2004 06:00:00 2 300
4 1/12/2004 08:00:00 2 800

If I write the following SQL statment:
"Select Eight.Time,Eight.DeviceNumber,Eight.Sum - Six.Sum As Dif
From A as Eight Inner Join A as six On Eight.ID=Six.ID
Where (Eight.Time = "08:00:00") And (Six.Time="06:00:00");

How SQL interpret this statment. I make the same table innered joined be ID field.
By purpose is to calculate the Difference between the Sum of the different hourse of the two devices.
I mean,
'06:00:00 - 08:00:00' 1 400 --> (600-200)
'06:00:00 - 08:00:00' 2 500 --> (800-300)

Please help me ti under stand and solce the problem.Looks look you shoudl be joining on DeviceNumber and not on ID.|||Hi,
I don't understand right now, How SQL pull out data according to the where criteria.
This will help me to design the query.
Here I thought to make two copies of the same table, and substract the Sum of 06:00:00 o'clock from 08:00: o'clock.

Can you help me to correct the statment.
thanks...|||What I meant was:

Select Eight.Time,Eight.DeviceNumber,Eight.Sum - Six.Sum As Dif
From A as Eight Inner Join A as six On Eight.DeviceNumber=Six.DeviceNumber
Where (Eight.Time = "08:00:00") And (Six.Time="06:00:00");