Category Archives: MDX

Include post related to MDX (MultiDimensional Expressions)

SQL Server 2017 Adventure Works Multidimensional Cube

It is easy to find Adventure Works scripts for OLTP and DW databases. But it sometimes tricky to find either solution to the Adventure Works Multidimensional Cube and Tabular or backup files.

So solve this problem for you I am sharing links to the abf files for quick access. This post is part 2 of last post on SQL Server 2017 quick setup. With SSAS and Tabular model sample databases you will be perfectly able to handle testing and development samples.

Go to : https://github.com/Microsoft/sql-server-samples/releases/tag/adventureworks-analysis-services

and at the very end of the article you will find the link for Adventure Works Analysis Services databases samples. Backups will be working for SQL Server 2016 and later versions. Tested by me.

Analysis Services database backups:

  1. adventure-works-multidimensional-model-full-database-backup.zip  – You get two backups Enterprise and Standard. I have both restored.
  2. adventure-works-tabular-model-1200-full-database-backup.zip  – You get only Sales data Tabular Model

 

Analysis services projects:

  1. adventure-works-multidimensional-model-project.zip
  2. adventure-works-tabular-model-1200-project.zip

Enjoy!! easy download then restore and you have working cubes for testing and working.

Let me know if there is any hiccup while you do all the setups from SQL Server 2017 to Adventure Works databases. Waiting for comments with appreciation or criticism.

 

Tips and Tricks on SSRS

SSRS provide a lots of properties to update the report according to any vague requirement given by Clients. Multiple properties and all changeable is the best feature of SSRS and gives it edge over all new reporting tools.

Over the time developers can learn many ways of manipulating reports. Few cool tricks are listed in this post and can help in exploring more ways of making desired changes in SSRS reports.

1. How to get Total page number in ribbon above report?

SSRS doesn’t calculate total page number and shows on top ribbon like 1 of 2 ? for page numebrs. Instead of “?”  it should be final number of page like 11. “2” represents next page as SSRS do not calculate total number of pages.

We will need to ask SSRS to calculate Total Page Number explicitly. To do so;

Pick the “Built in FieldTotal Pages (shown as =Globals!TotalPages) and drag it on header or anywhere in report (hide it if not needed by visibility property).

As shown below:

1

Reports rendering will be like:

Before After
 2  3

 

2. Get the data refresh time of Cube (last processing time)

I have seen most of the legendary system uses extra SSAS cube to store value of last processing time of main SSAS Cube.

Use following query to get refresh time of any cube and keep it as a new dataset in report.

SELECT TOP 1 LAST_DATA_UPDATE FROM $system.mdschema_cubes
WHERE CUBE_CAPTION = 'Adventure_Works'
ORDER BY LAST_DATA_UPDATE DESC

Save as dataset “dsLastUpdatetime”. And in report create a Text Box and keep expression as:

="Data Refresh Time:  " & First(Fields!LAST_DATA_UPDATE.Value, "dsLastUpdatetime") & " UTC"

 

3. Based on rendering/export format, change properties.

SSRS provides multiple rendering format or Export format. With a property Globals!RenderFormat.Name we can make sure how final output in desired format (excel/pdf/csv etc.) should appear.

For example in my report I show Selected parameter values on top on SSRS view. But if user download the file he/she wants only report data. So I change visibility of text Box (of parameter values) as following:

=IIF(Globals!RenderFormat.Name = "EXCEL", FALSE, TRUE)

And SSRS and Excel have different appearance as final report.

 

4. If you are not using Tooltip, you are not using SSRS properly

Option for Tooltip is everywhere. If you are not using it you are missing out a big feature. Users of SSRS mostly expect interactive reports though SSRS but its not as fun as other tools. At least tool tips add a one more attribute of reporting objects (like bar values in charts, description of column header etc.). Use it under Chart properties, Series properties, Text Box properties etc. to add more details in report.

 

5. Use SWITCH function for expressions instead of nested IIF.

Its easy and fast. Don’t forget to use TRUE as a default value. Example given below:

=SWITCH(Fields!RegionShort.Value = "N", "North",
Fields!RegionShort.Value = "S", "South",
Fields!RegionShort.Value = "E", "East",
Fields!RegionShort.Value = "W", "West",
TRUE, "Unknown")

 

6. Do not need datasets for Parameters all the time (even in MDX reports)

Mostly we rely on datasets values for Available values in property of Parameters. Its not mandatory. Imagine All and Female are two values of Parameter. In MDX dataset lot of stuff will be needed to avoid Male values.

Someone will create a dataset with except for Male option for same case. Or provide a filter on parameter to avoid Male option (with All member including). Simply, provide static values, just like below:

4

 

7. Create simple dynamic members on Parameters instead of dataset.

On extension to above, we can create dynamic members as per requirement just using same method.

For example, an Adventure Works report is needed where Parameter Product Category should have 3 values ALL, Actual_Products(comprising Bikes and Components) and By_Products(comprising Accessories and Clothing). Not values from cube.

So either you can use following MDX as dataset to fill the values:

WITH
MEMBER [Product].[Category].[Actual_Products] AS
([Product].[Category].[Bikes]+[Product].[Category].[Components])
MEMBER [Product].[Category].[By_Products] AS
([Product].[Category].[Accessories]+[Product].[Category].[Clothing])
SELECT [Measures].DEFAULTMEMBER on 0,
{[Product].[Category].[Actual_Products], [Product].[Category].[By_Products],
[Product].[Category].[(All)]} on 1
FROM [Adventure Works]

Or simply just get the parameter Available values as following:

ALL =”[Product].[Category].[(All)]”
Actual Products =”{[Product].[Category].[Bikes],[Product].[Category].[Components]}”
By Products =”{[Product].[Category].[Accessories],[Product].[Category].[Clothing]}”