Friday, October 19, 2012

SSAS - Understanding Non Aggregate Measures


Recently I have been asked a question, I have defined my measure with aggregate function as “None” and all the values are returned as Blank. What is the reason for this? So I have created a below demo to explain the concept of “None” aggregate function and how it works. Most you may be having the same question. So I am documenting this here to help you to understand about this.

Below is the sample model which will be used for demonstrating this



I have created a cube using the wizard with the above data model.  Below is the structure of the cube

Dimension : Product 
Attributes :ProductId
Dimension : Region
                Attributes :RegionID
Dimension :Chk  (Dummy Dimension)
                Attributes :ChkId
Measures : Sum(SoldQty)
                BillNumber (No aggregate)
Measures :  Sum(Valx) (Dummy Measure)


The cube is deployed and processed. Now in the browser, let us take a look how this measure behaves.
Now when using Region Dimension alone measure BillNumber is returning blank.





Now let us try adding the Product Dimension also inside. But still we could see only blanks in the BillNumber.



But if you try expanding for each region you will start seeing the Billnumber values.



The reason for this is in the first two tries there was an attribute at the level “All” . As we have mentioned BillNumber as NoAggregate , there will not be any value available for a “All” member.
Now you may get a question that in the first screenshot we have used Region at the granular level only. But why BillNumber is still Blank ?  As RegionId has been used in the query , by default ProductId will be at the “All” level. In the below MDX query , the product dimension is not used in the query , But by default it “All” member has been  considered for getting the values.



But in the last screen shot , we have the leaf level of all the attributes available in the cube so the BillNumber measure displays the value.Does this means do we need all the dimension attributes in the query to display the no aggregate measure ? Not necessary if you notice we have one other dummy dimension DimChk and other dimension attribute Color also. Without using the chk dimension attributes they will be considered as All member. But still we are getting the BillNumber measure displaying the value.This makes clear that we need to have attributes which is having the IDs as keys which are linked to the fact table which has this measure. In the above example if we use the ProductID&RegionIDattributes , No aggregate measure BillNumber will display the value.






If we remove one of the key attribute values, the bill number will start displaying Blank.



Conclusion

No Aggregate Measures will display values only when attributes with all keys linked to the fact is available in the MDX query or browser as it displays the leaf level data.

I have uploaded the SSAS project and relevant scripts in the below link for your reference.



Hope this blog is helpful .Will meet you next week with another blog. So far I am happy that I could keep up my resolution on doing a blog per week and hope I will be able to keep it up JJJJ.

Saturday, October 13, 2012

Query Full-Text Catalog and Index details from system tables

This week both personal and official work kept me so busy and couldn’t get time to do a brief blog. But recently I have started learning about Full-Text search and was able to create a utility script for getting the Full-Text Catalog and Index details. I have posted the script in Tech Net and available for download in the below link. Hope this is helpful.


http://gallery.technet.microsoft.com/scriptcenter/Get-Full-Text-Search-c77642de

Signing off hoping to meet you with a brief blog next week. Till then Bah Bye!!!

Thursday, October 4, 2012

SSAS – How to create User Defined member properties


SSAS – How to create User Defined member properties

It has been a long time since I wrote a blog as I was so very busy with other priorities. It feels so better to be back into this. Hope I will be able to blog frequently from now on.

Recently I have encountered a question in MSDN forums with a question how to create multiple caption for a member due to the reporting needs. As this is just for reporting purpose I have recommended creating them as User Defined member property. When I went ahead and searched in the internet for an article to provide step by step of this I couldn’t find one. So I decided to document it here so that it will be useful for all.

What is Member property?
Member properties cover the basic information about each member in each tuple. For example you need additional information on a member in a tuple of State Province code on State- Province attribute in the Geography Dimension in Adventureworks. But you don’t need any aggregation on that. For this scenario you can create this State Province code as member property for the State province so that it can be used for reporting purpose and it will not take more space in the cube as there is no aggregation for this property. Now let us take the above example itself and see how this can be achieved step by step.

Steps to create a member property
     1. Open the Adventure works solution for SQL Server 2008 R2
     2. Launch solution explorer and open the Geogrpahy dimension which we will be using as an example in this step by step

 
    3. Right click on the State province code column in Data Source View section and select New Attribute from column. Instead you can drag and drop this column into the attributes section.

     4.The attribute State Province code will appear in the attributes section under the Geography. Right click on Stateprovincecode attribute and select properties.Also you can hit F4 to display the property window.

     5.On the properties window change the below property values

AttributeHierarchyEnabled
False
GroupingBehaviour
DiscourageGrouping

     6.Move to the attribute relationship tab , you will see by default State Province code is added under GeographyID. But we need to add this attribute as member property to State Province.



7.  Right click on the relationship in attribute relationships tab and say edit relationship. Change the Source attribute to State-Province.


     8.Now you can see the relationship changes reflected in the attribute relationship tab.




9.  With this the required changes are done and now we need to Deploy & process the cube.From the project à Build menu choose Deploy the cube.
    10.   Once the deployment and process is done , Double click on the cube and move to cube browser tab. In the left measure group pane , expand the Geography àState Province à Member properties. There you will be able to see the state province code added as a member property.


11.   Now you will be able to use this member property in your MDX queries as shown below

WITH
   MEMBER [Measures].[State Province Code] AS
  [Geography].[State-Province].Properties( "State Province Code" )
SELECT
   [Measures].[State Province Code] ON COLUMNS,
   [Geography].[State-Province].[State-Province]  ON ROWS
FROM [Adventure Works]


 
Conclusion

Member properties will be handy when only used for reporting purpose without any aggregation. These member properties will not occupy any space in the cube as there is no aggregation or indexing done on these properties and it will be stored with in the dimension. As side effect of no indexes on these attributes querying member properties may be slow. But for sure this will help in terms of processing and cube size.

Hope this article is helpful. Will meet you soon with one more article next week as I have resolved to write one article a week.

Thursday, September 8, 2011

New T-SQL Functions in SQL Server Denali Part 2 - Date Time Functions

There are around 7 new DateTime functions introduced in Denali.
EOMONTH
DATEFROMPARTS
DATETIME2FROMPARTS
DATETIMEFROMPARTS
DATETIMEOFFSETFROMPARTS
SMALLDATETIMEFROMPARTS
TIMEFROMPARTS

EOMONTH
EOMonth Function returns the End Date of the given date's month. Also this takes an optional parameter Month to add. If month to add value is passed to the function , that number of months added to the date and gets the end date of that month.

Syntax : EOMONTH ( start_date [, month_to_add ] )

In the below example the first column returns the End date of the Month "September 2011" for the date passed as start_date. The Second column returns the End date of the Month "February 2012" as Month to add is passed as 5.



DATEFROMPARTS
DateFromParts function will return a specific date of date datatype for the Year , Month and Day passed as parameters.In the existing version , if we have Year , Month and Date we need to do a conversion of these values to string. Then concatenate these values and convert back to a DateTime as shown in below example. This function completly avoids the need for such a complex code. Also takes care of the issue during concatenation the month and day may get interchanged due to date format as shown in below example.

Syntax : DATEFROMPARTS ( year, month, day )

DATETIMEFROMPARTS

DateTimeFromParts is similar to DateFromParts. The difference is it will return Date of DateTime datatype by taking year, month, day, hour, minute, seconds and milliseconds as input.

Syntax : DATETIMEFROMPARTS ( year, month, day, hour, minute, seconds, milliseconds )

DATETIME2FROMPARTS
DateTime2FromParts is similar to DateFromParts. The difference is it will return Date of DateTime2 datatype by taking year, month, day, hour, minute, seconds, fractions and precision  as input.

Syntax : DATETIME2FROMPARTS ( year, month, day, hour, minute, seconds, fractions, precision )

DATETIMEOFFSETFROMPARTS
DateTimeOffsetFromParts is similar to DateFromParts. The difference is it will return Date of DateTimeOffset datatype by taking year, month, day, hour, minute, seconds, fractions, hour_offset, minute_offset and  precision as input.

Syntax : DATETIMEOFFSETFROMPARTS ( year, month, day, hour, minute, seconds, fractions, hour_offset, minute_offset, precision )


SMALLDATETIMEFROMPARTS
SmallDateTimeFromParts is similar to DateFromParts. The difference is it will return Date of DateTime datatype by taking year, month, day, hour and minute as input.

Syntax : SMALLDATETIMEFROMPARTS ( year, month, day, hour, minute )

TIMEFROMPARTS
TimeFromParts will return Time of Time datatype by taking hour, minute, seconds, fractions and precision as input.

Syntax : TIMEFROMPARTS ( hour, minute, seconds, fractions, precision )

Below is the total consolidated example for the all the Date & Time From part function


Next i will continue with the new Logical functions.  

Tuesday, September 6, 2011

New T-SQL Functions in SQL Server Denali Part 1 - Conversion Functions

It has been more than a month since i blogged.Feels good to be back in action !!!

There are around 22 new functions are introduced in Denali. In this series of posts let us take a look into functions category wise and what problem they intend to solve.

First let us take a look into the new Conversion functions

            PARSE
            TRY_PARSE
            TRY_CONVERT
 
PARSE

Parse is similar to Cast function which converts the data to required data type. But in Parse function we can include the culture in which it has to be converted.If no culture is provided , it will use the default culture. Parse function supports only converting the String values to  Numeric and Datetime Datatypes.

Syntax : PARSE(String_Value As Data_Type [USING Culture])

 

TRY_PARSE

Try_Parse function will check whether the parse function will be succesfull or not for the given string value , data type and culture.If the unable to parse the string value to the datatype the function will return NULL.Try_Parse takes the same parameters as like Parse function.This will be very usefull during data profiling to find out error records which cannot be parsed.

Syntax : TRY_PARSE(String_Value As Data_Type [USING Culture])

In the below example , the culture "en-US" returns value and "ar-SA" returns NULL as it is unable to parse the string into date with the arabian culture.

 

 
TRY_CONVERT

Try_Convert function will check whether the expression can be converted to the destination datatype or not. If unable to convert it returns NULL. This is similar to Try_Parse.But this checks the CONVERT function.This function has the same parameters as like CONVERT function.

Syntax : TRY_CONVERT ( data_type [ ( length ) ], expression [, style ] )

In the below sample , when the conversion is succesfull it returns the converted value for string to date conversion. But while trying to convert string to int , it returns NULL as conversion cannot happen from string to int.

 

These are the three new conversion functions in Denali CTP3. Hope this post is helpfull and will continue to write on other function. The next post will be on the new function on Date and Time Category.
 

Tuesday, July 26, 2011

SQL Server "Denali" - SSAS Cube Browser - Query Design mode

In SQL Server Denali CTP3 , i noticed this cool feature Query Design mode in the cube. In the previous versions to get the MDX query for the attributes used in the report area we need to run the profiler to obtain the MDX query being generated. But in Denali , this has been made very simple by Query Design mode.

Click on the Query design mode on the tool bar and you will see the MDX query for the attributes and measures in the reporting area.






Also in this mode you can modify or write your own MDX query as like in the SSMS window.


This is really a cool feature which makes the developer life with below benefits

1. No need to run the profiler to get the MDX being designed.
2. MDX query can be written in the BIDS itself for testing the cube rather than switching to SSMS.

For more details , Refer to the below link


Friday, July 22, 2011

SQL Server "Denali" - Crescent Resources

I am very much excited with Project Crescent release in SQL Sever Denali CTP3. Yet to explore the features in it.Started looking for resources for the same and below are the links which found to be a good starting point for me. Hope will be usefull for you folks too.Happy Crescenting :)

Project Crescent Overview and Usefull Links

Project Crescent Tutorials

Project Crescent Demo Video

Project Crescent Samples