Excel

Showing posts with label SSAS. Show all posts
Showing posts with label SSAS. Show all posts

Friday, September 23, 2011

SSAS - Simple Date Expression


              In general the Time dimension table will contain the full date (ie, Date with Time format) which is not preferable while browsing the data from the cube. If you want to display the Date field in the Format like “June 25,2008” –follow the given below steps:

è In Data Source View ,Right Click on Time Dimension
è  Choose “New Named Calculation”
è  Enter the Column name for the new field (Ex :SimpleDate)
è  Type following Expression.
(In the following sample Full_Date is the Date Field.)




 



Syntax:

DATENAME(mm, Full_Date) + ' ' +
DATENAME(dd, Full_Date) + ', ' +
DATENAME(yy, Full_Date)

Displaying Minutes into HH:mm:SS Format in SSAS


     To display the data in time format(HH:mm:SS)  then we you can use the following expression in calculation field :
            In the following sample, RestoreTime is the measure field which is Total minutes taken to restore the service. To display the minutes into HH:mm:SS format ,

Expression to create calculated field in SSAS:
Case
       When [Measures].[RestoreTime] <> 0   Then
              Format(Int([Measures].[ RestoreTime]/86400), "0#::")
               + Format (TimeSerial(0, 0,  [Measures].[ RestoreTime]-
            (Int([Measures].[RestoreTime]/86400) * 86400)), "HH:mm:ss")
       Else
             null
End

Monday, September 5, 2011

SSAS Calculation- Some Sample MDX expressions

              SSAS Calculation is a Multidimensional Expressions (MDX) expression or script that is used to define a calculated member, a named set, etc., in a cube in Microsoft SQL Server Analysis Services. Here, I am going to give you some sample MDX expressions to do some typical calculations which are often required in providing business solutions using SSAS.


1)       To calculate Cumulative Values (Order by Measure) :
If you want to calculate the cumulative value of a measure based on certain dimensional attribute (ordered by the Measure), you can use the following expression:
iif
(
[Measures].[Amount]> 0,
Sum (Head(Order ([DimRegion].[Area].Siblings,[Measures].[SaleAmount],BDESC) ,
Rank ([DimRegion].[Area].CurrentMember,Order ([DimRegion].[Area].Siblings,
            [Measures].[SaleAmount],BDESC ))),
[Measures].[SaleAmount])
, null
)
The above expression will give us the Regional Area wise cumulative Sales Amount.
2)      Similar to the above sample,  If you want to calculate the Cumulative sum of a measure based on the Time dimension members, we can use the following expression

Sum(
{[DimTime].[Quarter].FIRSTCHILD:[Dim Time].[Quarter].CURRENTMEMBER},
[Measures].[SaleAmount]
    )
The above expression will return you the Quarter wise cumulative Sale Amount.

3)      To calculate Total (Sum ) value of a measure and return the same to all members of the attribute

iif
(
[Measures].[Expense Amount]> 0,
sum([DimRegion].[Area].PARENT,  [Measures].[SaleAmount]),
null
)
4)      To Calculate the Percentage to Total (Contribution to Total Sales by each reach region)
            [Measures].[SaleAmount]/
MAX([DimRegion].[Area].Allmembers,[Measures].[ SaleAmount])*100
5)      To Calculate Periodic Growth of Sales in SSAS calculations

SUM(
[DimTime].[Time_Hierarchy].CURRENTMEMBER,[Measures].[SaleAmount])-SUM(ParallelPeriod([DimTime].[Time_Hierarchy].[Year],1,[DimTime].[Time_Hierarchy].CURRENTMEMBER),[Measures].[SaleAmount]
)

6)      Consider the above Calculated Member Name as [Growth], If you want to calculate What is the Periodic Growth Percentage of Sales, then we can use the following expressions:

(
[Measures].[Growth]/SUM(ParallelPeriod([Dim Time].[Time Hierarchy].[Year],1,
[Dim Time].[Time Hierarchy].CURRENTMEMBER),[Measures].[Sales Amount])
)

7)      SSAS Calculation to calculate Last Year Values:

SUM
(
ParallelPeriod([Dim Time].[Time Hierarchy].[Year],1,
[Dim Time].[Time Hierarchy].CURRENTMEMBER),
[Measures].[Sales Amount]
)

8)      SSAS Calculation for Year To Date (YTD) values

SUM
(
YTD([Dim Time].[Time Hierarchy]),
[Measures].[Sales Amount]
)

9)      SSAS Calculation for Quarter To Date (QTD) values

SUM
(
QTD([Dim Time].[Time Hierarchy]),
[Measures].[Sales Amount]
)

10)   SSAS Calculation for Month To Date (MTD) values

SUM
(
MTD([Dim Time].[Time Hierarchy]),
[Measures].[Sales Amount]
)
11)   Previous Member value

To get value of the Previous Member:
Syntax:
      Dimesion.Member.PREVMEMBER

Ex:
IIF([Dim Sales Stage].[Sales Stage].PREVMEMBER>0,
[Measures].[FactSalesCount]/Sum(([Dim SalesStep].[SalesStep].PREVMEMBER),[Measures].[FactSalesCount]),1)*100

(ie, the above example gives us the Percentage of current SalesStep’s count against previous sales step. The IIF is used to check as the previous member has any value- to avoid divide by zero issue)

12)   Last Year Values
SUM(ParallelPeriod([Date].[Time_Hierarchy].[Year],1,[Date].[Time_Hierarchy].CURRENTMEMBER),[Measures].[SalesCount])

            The above example will give us the last year sales count

Wednesday, April 20, 2011

Creating solution file from a SSAS database

When the online SSAS application has been involved into so many changes and you don’t know where the latest source code is. At this scenario, the best way to retrieve the source file of SSAS DB is:
 
·         Go to Start-->Programs-->Microsoft Visual Studio 2005
·         Click on File-->New Project
                          

·         Select the Import Analysis Services option and after giving the required Name, Location and Solution Name, click OK

                           

·         A Wizard message will pop up prompting to continue by clicking Next.
                                  

  •   Click Next and then fill in the server name as well as the DB which you need to import. And then Click Next
                                    

·         The Wizard will start importing the source files from the database and on completion
·         When the wizard finishes extracting the contents of the Analysis Services 9.0 database, click Finish on the Completing the Wizard page

·         Open the Solution Explorer window to view the contents of the project