Wednesday, December 31, 2008

How to Join the Results of Multiple MDX Queries on Date Demension

I need to get a datasest and combines multiple MDX query's results. I know using stored procedure can probably solve the problem. But I don't have write access to the Cubes.

Solution:
.......Still working on it......

Monday, December 29, 2008

Use IN Statement for Multivalue Parameters

When use IN statement in the WHERE clause for multivalue parameters, the parameters needs to be in parentathes. E.g.

a.[Microsoft_VSTS_Common_Priority] IN (@Priority)

Friday, December 12, 2008

SQL: Removes the Time Portion of a DateTime Value

I encountered a situation that I need to get only the Date portion of a Datetime value. After some digging, I found a post that has exactly what I want. A SQL expression, dateadd(dd,0, datediff(dd,0,@DateTime)), was used to give just the date portion. I'm not quite sure about why it did the trick. But it worked for me.

The original post is at:
http://weblogs.sqlteam.com/jeffs/archive/2007/01/02/56079.aspx

Tuesday, November 11, 2008

Current Date 1

with member measures.test1asformat(dateadd("yyyy", -5, now()), "Medium Date")member measures.test2asinstr(format(dateadd("yyyy", -5, now()), "Medium Date"), ",")member measures.test3as"[" + mid(format(dateadd("yyyy", -5, now()), "Medium Date"), 2 + instr(format(dateadd("yyyy", -5, now()), "Medium Date"), ",")) + "]"member measures.[5YearBackSales]as(strtomember("[" + mid(format(dateadd("yyyy", -5, now()), "Medium Date"), 2 + instr(format(dateadd("yyyy", -5, now()), "Medium Date"), ",")) + "]"),[Measures].[Internet Sales Amount]), format_string = "currency"select {[Measures].[Internet Sales Amount], measures.[5YearBackSales], measures.test1, measures.test2, measures.test3} on 0,[Date].[Calendar].[Month].&[2003]&[11].children on 1from [Adventure Works]

Monday, November 10, 2008

MDX Training Notes

MDX Training Notes
Day 1
1. Performance Point
2. Dimensions that don’t have enough levels will slow down the performance. If the source doesn’t have levels, we need to create some in the dimensions
3. Aggregation helps on performance when you have big fact tables and small number of dimensions.
4. Performance
a. The actual run time for MDX
b. How fact the Cube is being processed
5. Caching is important for SSAS performance. How to create cache?
6. It is possible to create an aggregation just for one MDX query in order to improve performance.
7. ProClarity is better than Excel in terms of MDX and SSAS.
8. Calculated member can be created in three places: Cube, session, query
9. Default measure can be found in the advanced cube properties section in cube design window.
10. In SQL Server mgmt studio query window, you can select a section and just run the highlighted query
11. Models in Performance Point are Cubes in SSAS
12. Empty rows or columns mean the whole row or column has null value.
13. Density of Cell set. (Use Non Empty on rows and columns)
14. Muiltiple keys for a member
a. [Date].[Calendar].[Calendar Semester].&[2002]&[1] is the same as [Date].[Calendar].&[2002].&[2002]&[1] or [Date].[Calendar].&[2002].&[1]
15. When use tuples, the dimensions that are not listed use the default member, most of the time it’s the all member.
16. Meauses can be treated as demensions in most cases. E.g.
SELECT (
[Measures].[Internet Sales Amount], [Department].[Departments].[Department Level 01]
) ON 0
FROM [Adventure Works]
WHERE [Date].[Day of Year].[Day of Year].members
17. A set requires the same dimensionality on all its members.
18. To get rid of the all_member in a SET, specify the level in [Demension].[Hieracky].[Level]
19. .allmembers IS different than .members. .allmembers returns calculated members while .members doesn’t.
20. How to specify data type for calculated members?
21. CurrentMember function expects hierarchy
22. In SQL mgmt studio query window, put go between queries will run all the queries at the same time.
23. In Lab 05A for the Calculated member, on the Calendar Year hierarchy, [Date].[Calendar].[All Periods].[2004 Bikes] is wrong because [All Periods] is a hierarchy or level not a member(parent), instead [Date].[Calendar].[All Periods].[2004 Bikes] is correct because [All Periods] is a member.
24. Most VBA functions work in MDX
25. MDX is smart enough to handle data types by itself on calculated members
a. Dd
b. Bb
26. CrossJoin’s order does matter. The first one shows up first.
27. Attributes Hierarchy has two levels, all and the list of all members. Meanwhile, User Hierarchy is the user defined multi-level hierarchy.
28. When use Descendants() function without specifying level, it includes itself.

Day 2
1. .Currentmember is almost always optional. But for readability, use .currentmember as a good practice.
2. List of properties of a dimension can be found in BIS dimension structure window.
3. To see the cube definitions of a SSAS database without the solution file, on BIS select File ànew àprojectàImport SSAS database. A new project with the definitions will be created. Then right click on the solution and go to properties, change the server and database name, and do a deployment. That will create a copy of the database to your local server for you to play with.
4. you will get a null value. Instead you should use something like member.name to return a string or value.
5. To format strings in MDX: [cell value], format_String=”Percent”
6. User ORDER function to sort MDX results
7. NonEmpty() is a function while Non Empty is a Keyword
8. NonEmpty() is MUCH faster than filter. E.g. The first below one is much faster than the second one.
WITH
MEMBER Measures.CustomerCount AS
COUNT(NONEMPTY([Customer].[Customer Geography].[Customer].MEMBERS, [Measures].[Internet Sales Amount]))

WITH
MEMBER Measures.CustomerCount AS
COUNT(Filter([Customer].[Customer Geography].[Customer].MEMBERS, [Measures].[Internet Sales Amount]>0))

9. Generate() function ?????
10. Order() function. Use BDESC instead of DESC. BDESC sorts all members regardless of the hierarchy, while DESC sorts only within the hierarchy. B means breaking.
11. Rank() can be used as a row number column.
with member
measures.test as rank([Product].[Product Categories].currentmember,
[Product].[Product Categories].[Product].members)
select
{[Measures].[Internet Sales Amount], measures.test} on 0,
[Product].[Product Categories].[Product].members on 1
from [Adventure works]
12. .CurrentMember is NOT always the default.
SELECT [Measures].[Internet Sales Amount] ON 0,
ORDER(
[Product].[Product Categories].MEMBERS
, [Product].[Product Categories].CurrentMember.NAME, BDESC)
ON 1
FROM
[Adventure Works]
Is correct, While
SELECT [Measures].[Internet Sales Amount] ON 0,
ORDER(
[Product].[Product Categories].MEMBERS
, [Product].[Product Categories].NAME, BDESC)
ON 1
FROM [Adventure Works]

Sorts members by hierarchy instead of members.
13. SetToStr etc is usually used for debugging.
14. Exists() function is faster than Filter() function. Exists() works with two hierarchies in the same dimension.
15.

Friday, November 7, 2008

SSRS Study Notes

I went through a series of Microsoft webcast on SSRS 2005 and found it helpful. Here are some of the notes I took:

1. When use URL to access a report use \reportserver\ instead of \reports\
2. List report item is more like a container for other report items like textbox and table.
3. Shift+click allows you to select multiple cells.
4. Print layout button helps preview page setup.
5. Multi-value parameter: use IN in Where clause (SQL Query).
6. Write stored procedures directly on data set.
7. You can add calculated field directly on dataset by right clicking on the dataset in Datasets view and choose Add then select Calculated Field.
8. Report Delivery: Web Service: msdn2.microsoft.com/en-us/library/ms155071.aspx
9. To use external assembly for custom code.
a. Create a Class Library project
b. Build it and put the dll in both the Report Server location and Report Designer location in Visual Studio.
c. In report designer go to project properties window and go to reference tab, and select the dll copied to Report Designer location.
d. To call the function, view the report rdl file code, locate the field that need the custom code, then put in custom expression. E.g.
=AdventureWorks.VB.Extensions.Commonfunctions.functionName(paremters the function takes)

Thursday, November 6, 2008

Global Members

1. Fields allows you to point to a dataset field. e.g. Fields!ID.Value
2. ReportItems allows to point to an existing report item. e.g. ReportItems!textbox5.Value
3. Code allows you point to a custom function in the Code tab of Report Property window. e.g. Code.GetColor(Fields!ID.Value)

SQL Server 2005 Security Patch KB954606 Install Issue

There is a known issue about the security patch KB954606 about reporting service failing to start. To fix it, add the following new registry key in path HKLM\SYSTEM\CurrentControlSet\Control\ :

ServicesPipeTimeout = 60000

Details at http://support.microsoft.com/kb/922918

Related discussion can be found at http://forums.microsoft.com/technet/showpost.aspx?postid=3878291&siteid=17&sb=0&d=1&at=7&ft=11&tf=0&pageid=1

Friday, October 31, 2008

MDX Questions

I will take a MDX training in mid November. Here is the list of questions I'd like to bring up during the training. I will be posting answers along the way.

1. The Report Designer auto generated MDX queries have additional 'DIMENSION PROPERTIES' and 'CELL PROPERTIES'. Why are they in the MDX query and how are they used in the report? i.e. (See text in blue)
SELECT NON EMPTY { [Measures].[Build Details Count] } ON COLUMNS, NON EMPTY { ([Date].[Date].[Date].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM [Build] CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

2. I got an error message saying "The Team Project hierarchy already appears in the Axis2 axis." Does it mean that the Where clause only takes demensions that are not in the Select clause?

SELECT {[Measures].[Work], [Measures].[BizStoryValue]} ON COLUMNS,
{[Work Item].[System_Id].[System_Id]} ON ROWS,
{[Team Project].[Team Project].[Team Project]} ON 2
FROM [Current Work Item]
WHERE ([Team Project].[Team Project].&[11])


3. In our TFS process template, there are two fields in Sprint Details work item that has reportable property set to "detail". How to get their value in MDX?
-I found the answer for this question before the training. "Use reportable="detail" to add a column to the fact table without adding anything to the cube."

4. Which is better, select from (Select ....) automated MDX or filter?

Wednesday, October 29, 2008

Report Manager Printing Issue

The issue: Cannot Print SSRS 2005 report after installing KB956391

The fix:
1. Uninstall KB956391 on the client PCs.
Or
2. Install SQL Server 2005 x64 Edition Service Pack 2 (KB954606) on the data server (The one that has SSRS service running). More details on http://www.microsoft.com/technet/security/Bulletin/MS08-052.mspx

Thanks to the following discussion:
http://forums.microsoft.com/TechNet/ShowPost.aspx?PageIndex=1&SiteID=17&PageID=1&PostID=4006172

Interactive Sorting When Table Has Groups


To sort correctly on a table that has multiple groups, the correct scope needs to be specified. The default selection for the scope is 'Detail Scope'. Often times, this needs to be changed to a different grouping.






Thursday, October 16, 2008

SUM() Function Trick

When using Iif() in SUM() function, make sure data types match. In the example below, if cDec() is not used, you will get an error.

=sum(iif(Fields!Sort_Order.Value = "E1", cDec(Fields!hours_m2.Value), cDec(0)))

The orginal post is at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1507530&SiteID=1

Tuesday, October 14, 2008

SQL: Conditional WHERE clause

I encountered a situation that the WHERE clause in a SQL query changes based a parameter. When the parameter is '_All', there is no restriction. When the parameter is any other value, an AND section in the WHERE clause is needed.

After some digging, I found an elegant solution. Using
(@parameter = '_All' OR Field_X=@parameter). It greatly simplied the SQL query and fixed the problem of NULL value is hard to handle.

The post I saw is: http://dotnet.org.za/ilo/archive/2005/05/31/21280.aspx

Thursday, October 9, 2008

Jump to URL Opens a New Window

Use Java script to open a new window on a link of a report. If the dynamic value is part of the URL, be aware of the data type. Use CStr() function if the dynamnic value is not String data type.

This method only works when the report is displayed within a browser (I only tested IE7).

Here is an example:

"javascript:void(window.open('http://StaticProtionOfTheURL" & CStr(DynamicValue) & "','_blank', 'location=no,toolbar=no,left=100,top=100,height=600,width=800'))"

Useful Links

Here are the links that I found useful:

MSDN Forum:
http://forums.microsoft.com/msdn/default.aspx?SiteID=1

MDX:
MDX Function Reference (MDX)
http://msdn.microsoft.com/en-us/library/ms145970.aspx
MDX Cheatsheet
http://gumper.com/mdx.html
Format_String
http://msdn.microsoft.com/en-us/library/ms146084.aspx

Expressions:
Expression Functions (SQL Server 2008)
http://msdn.microsoft.com/en-us/library/cc281391.aspx
VB Script
http://msdn.microsoft.com/en-us/library/3ca8tfek(VS.85).aspx
VB Functions:
http://msdn.microsoft.com/en-us/library/32s6akha.aspx

T-SQL Referrence
http://msdn.microsoft.com/en-us/library/bb510741.aspx

SQL Server Analysis Services 2005/2008 Articles
http://www.ssas-info.com/analysis-services-articles

TFS Data Warehouse
http://msdn.microsoft.com/en-us/library/ms244674.aspx#DataStops







Use JOIN() Function to Display All Members of A Multivalue Parameter

Sometimes you want the report to display all the pamameters that are applied, especially when the parameter section is hided. To do that, you can simply use a text box and and point the value to the parameters. However, to display all members of a multiple value parameter, you will need to use the JOIN() function.

For example, if you have a parameter called Area that filters work items by the Area field, the following expression will allow you to display all the selected areas on the report.
="Area: " + JOIN(Parameters!Area.Label, ", ")

Thanks to a post I found on bokebb.com. Here is the link to it:
http://www.bokebb.com/dev/english/2008/posts/2008112686.shtml

About This Blog

I will be blogging the tips and lessons I learned about SSRS, mostly on TFS related reports, SQL and MDX queris.