Using SSRS Reports with SSAS Cubes

Preview:

DESCRIPTION

Take your reports to the next dimension! In this session we will discuss how to combine the power of SSRS and SSAS to create cube driven reports. We will talk about using SSAS as a data source, writing MDX queries, using report parameters, passing parameters for drill down reports, performance tuning, and the pro’s and con’s of using a cube as your data source. Jeff Prom is a Senior Consultant with Magenic Technologies. He holds a bachelor’s degree, three SQL Server certifications, and is an active PASS member. Jeff has been working in the IT industry for over 14 years and currently specializes in data and business intelligence.

Citation preview

Using SSRS Reports with SSAS CubesPresented By:

Jeff PromSenior ConsultantMCTS - Business Intelligence (2008), Admin (2008), Developer (2008)

Magenic Technologies

Agenda1. The How & Why of using SSRS with Cubes2. Using SSAS as a Data Source3. Writing MDX queries4. Refactoring SSRS to use SSAS5. Demo6. Performance Tuning7. Questions / Wrap up

Why run reports from a cube?• Cubes may be readily available• Cubes may be your company’s primary data source• Cubes may be your only resource• ‘Canned’ reports can be created/scheduled/Emailed• May want to use SSRS instead of Excel

Primary Differences• Connect to a cube rather than a relational database• Report queries will use MDX instead of T-SQL• Report Parameters will use MDX• Report Field Sources will use XML• More difficult / time consuming

SSAS• Online Analytical Processing (OLAP) Cube data structures• Great for numeric analysis• Pre-calculated aggregations• Dimensional Model / Star Schema• Facts (Measures) & Dimensions

SSAS• Member

– An item in a dimension representing one or more occurrences of data.– The lowest level of reference when describing cell data in a cube.

• Tuple– Used to define a slice of data from a cube.– Composed of one or more members.

• Set– An ordered collection of zero, one, or more tuples.

MDX Basics• MultiDimensional Expressions (MDX)• MDX lets you query multidimensional objects, such as cubes, and return

multidimensional cellsets.• Parent/Child hierarchical structure • Comment your code with:

– --– //– /* Code Block */

• Terminate queries with a semicolon ;• Write/test your MDX queries in Management Studio first!

www.microsoft.com/webcasts

T-SQL vs MDX StructureT-SQLSELECT DISTINCT DATEPART(year, ReservationDate) FROM FactReservationDates;

MDXSELECT { } ON COLUMNS, { NONEMPTY([Reservation Dates].[Calendar Year].Children) } ON ROWS FROM [HT Cube];

Using MDX in Report Queries• STRTOSET – Converts a string to a set• STRTOMEMBER – Converts a string to a member• Cross Join – Combines tuples of one set with the tuples of another

– Use * to combine multiple dimensions• Can’t execute more than one MDX query at a time in SSMS in the same query

window.• Beware of the ‘All’ and ‘Unknown’ members.• If you have multiple conditions in your WHERE clause, you need to enclose

them in ( )– e.g. WHERE (condition1, condition2, condition3);

Double Empty?• Non Empty vs NonEmpty()

– Non Empty is a prefix and is used to remove empty record sets– NonEmpty() returns the set of tuples that are not empty from a specified set

MDX Filtering• Filtering in the WHERE clause• Inline filtering

– [Customers].[CustomerID].&[123]– Use with ON ROWS

• Using ‘Filter’– Checks tuples to see if it exists within the filter condition– Use with ON ROWS

SSRS• Data Source: Use Microsoft SQL Server Analysis Services• Queries need to use MDX instead of T-SQL• Parameter Values need to use MDX data sources

– May also need to convert string values into MDX.• Field sources will be in XML

Report Fields: T-SQL vs MDX (XML)

XML Field Source Values• Numeric Values

– <?xml version="1.0" encoding="utf-8"?><Field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="Measure" UniqueName="[Measures].[Total Amount]" />

• Dimension Values– <?xml version="1.0" encoding="utf-8"?><Field xmlns:xsi="http://www.w3.org/2001/XMLSchema-

instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="Level" UniqueName="[Customers].[Customer Name].[Customer Name]" />

Calculated Fields• Use Calculated Fields to pass MDX parameter strings

– ="[Reservation Dates].[Calendar Year].&["+Fields!CalendarYear.Value+"]"

Passing Parameters Between Reports• Passing Single Values

– Easier– Two options when passing parameter values:

1. Pass the parameter name (e.g. @Parameter) and then convert it back into an MDX string in the subsequent queries and use a StrToMember function.

Passing Parameters Between Reports• Passing Single Values

– Two options when passing parameter values:2. Or, create and pass a Calculated Field as an MDX string and then use the

StrToMember function.

Passing Parameters Between Reports• > 1 Value

– Typically More difficult– Have to convert to MDX string values– In MDX use StrToSet

Demo

Performance Tuning - SSAS• Ensure the SSAS server has sufficient hardware• Tune aggregations on your cubes• Use Partitions

– By Time– By Geography

• Add a Constrained flag to StrToSet and StrToMember functions– More secure and improves performance– StrToMember('[Geography].[Geography].[Country].[Germany].FirstChild', CONSTRAINED)

Performance Tuning - MDX• Performance tune MDX queries• Use Named Sets to avoid recalculating set expressions• Use Calculated Members to cache numeric values• Apply filters to limit the result sets• Only use StrToSet and StrToMember when using SSRS parameters• Use the NonEmpty function wherever possible

Performance Tuning - SSRS• Avoid returning too many records (~ 2,000+)• Use parameters and filtering to limit records returned• Try to avoid resource intensive reporting features

– Fixed Data (Advanced Mode)– Repeat on New Page (Advanced Mode)– Matrix reports with column groupings

Gotchas• Constant balancing act between using parameter strings, MDX Values,

and data set values.• BIDS2010 – If you put the wrong XML field name values, you will get

warnings even AFTER you fix it. Need to close BIDS and restart.• BIDS2008 – Avoid using the query wizard!

– Can change your queries back to the original– The MDX wizard likes to ‘Hide’ your datasets

Pro’s & Con’s• Pro’s

– Ability to report off of existing cubes– Take advantage of SSAS aggregations

• Con’s– Writing queries can be more difficult / time consuming– Using parameters can be more complex– Not the most efficient for large, detailed reports

Links• Analysis Services Connection Type for MDX (SSRS)

– http://msdn.microsoft.com/en-us/library/dd239327.aspx

• Microsoft SSAS Overview– http://msdn.microsoft.com/en-us/library/bb522607.aspx

• Microsoft MDX Overview– http://msdn.microsoft.com/en-us/library/ms145514.aspx

• Microsoft SSRS Overview– http://msdn.microsoft.com/en-us/library/ms159106.aspx

Jeff Prom• Contact Info

– Blog: http://jeffprom.wordpress.com– Email: jeffp@magenic.com

Questions?

Thank You!

Jeff Prom