Thursday, January 7, 2010

Child nodes with multiple parents in a parent-child hierarchy

I'm currently working on building a Finance datamart using Microsoft BI suite. As you may know, one of the key things while working with a Financial application is to understand the Chart Of Accounts(COA) - how a company categorizes their accounts such as Assets, Liabilities, Expeses etc. for the purpose of recording into GL.
The recommended UDM data model for COA is parent-child since it offers a number of benefits such as Custom Order,Custom Rollups, and Custom Members.

One of the limitations of a parent-child hierarchy is that it only allows you to have one hierarchy , which means a child node can have one and only one parent. In real world
this limitation will become an obstacle very quickly. There are a number of ways to design and implement such a requirement. Refer to the articles many-to-many revolution by Mark Russo
and Duplicate members in Analysis Services by Richard Tkachuk

Thursday, November 19, 2009

Uninstall Visual Studio 2008

Here is an easy way (one-click) to uninstall Visual Studio 2008 from your machine:

http://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=7276

Thursday, March 13, 2008

T-SQL Script to create Date Dimension table

I work on data warehousing projects, and I frequently find myself needing to create the most common, but critical dimension "Date Dimension"(or Time Dimension). So, here is a simple script that I use to create a Date Dimension table.
There are 3 sections in this script:
1) Create the Date Dimension table
2) Load Data for a specified date range. Supply start and end dates to the variables
@startDate and @EndDate.
3) Update the column "LastDayOfMonth", which I find very useful while doing data analysis.
I use a function called "fnGetLastDayOfMonth" to obtain the last day of a given month.
You need to run the script in the listed order.

Note that the last three columns prefixed with the word "Holiday" are not populated with this script. These fields can be populated at the beginning of each year as you go or you can bulk update with a pre-populated "Holiday" table. I hope you find this script handy.

Listing 1
------------
--drop table DimDate
if object_id('DimDate') IS NOT NULL
drop table DimDate
create table DimDate(
DateKey int NOT NULL
,DayOfMonth tinyint NULL
,MonthOfYear tinyint NULL
,[Year] smallint NULL
,[DayOfWeek] varchar(15) NULL
,WeekOfYear tinyint NULL
,[DayOfYear] smallint NULL
,[MonthName] varchar(20) NULL
,[Quarter] tinyint NULL
,QuarterName varchar(20) NULL
,IsLastDayOfMonth char(1) NULL
,IsHoliday char(1) NULL
,HolidayName varchar(50) NULL
,HolidayDescription varchar(150) NULL
)

GO
Listing 2
----------
declare @startDate as datetime,@enddate as datetime
--initialize
set @startDate = '01/01/2007'
set @enddate = '01/01/2009'

while @startDate<@enddate
begin
insert into DimDate(
DateKey
,[DayOfMonth]
,MonthOfYear
,[Year]
,[DayOfWeek]
,WeekOfYear
,[DayOfYear]
,[MonthName]
,[Quarter]
,QuarterName)
select cast(convert(varchar(8),@startdate,112) as int)
,day(@startdate)
,Month(@startdate)
,Year(@startdate)
,datename(weekday,@startdate) as WeekDay
,datename(week,@startdate) as Week
,datename(dayOfYear,@startdate) as dayOfYear
,datename(month,@startdate) as MonthName
,datename(quarter,@startdate) as Quarter
,CASE datename(quarter,@startdate)
WHEN 1 THEN 'First Quarter'
WHEN 2 THEN 'Second Quarter'
WHEN 3 THEN 'Third Quarter'
WHEN 4 THEN 'Fourth Quarter'
END AS QuarterName

set @startDate = @startDate +1
end
GO

Listing 3
------------

CREATE FUNCTION fnGetLastDayOfMonth
-- Input parameters
(
@Anydate datetime
)
RETURNS datetime AS
/********************************************************************
Returns the last day of the month (extracted from the date passed)
*********************************************************************/
BEGIN
-- add one month to the datepassed
SET @Anydate = DATEADD(m,1,@Anydate)
RETURN DATEADD(d,-datepart(d,@Anydate),@Anydate)
END

GO
--Update the column IsLastDayOfMonth
UPDATE
DimDate
SET
IsLastDayOfMonth = CASE WHEN dbo.fnGetLastDayOfMonth(cast(DateKey as varchar(10)))= Cast(Cast(DateKey as varchar(10)) as datetime) THEN 'Y'
ELSE 'N' END

GO
select * from DimDate

Thursday, February 14, 2008

How does the market define and describe Business Intelligence(BI) platforms today?

BI platforms enable users to build applications that help organizations learn and understand their business. Gartner defines a BI platform as a software platform that delivers the 12 capabilities listed below. These capabilities are organized into three categories of functionality: integration, information delivery and analysis. Information delivery is the core focus of most BI projects today, but we see an increasing need to focus more on analysis to discover new insights, and on integration to implement those insights.

Integration

BI infrastructure — All tools in the platform should use the same security, metadata, administration, portal integration, object model and query engine, and should share the same look and feel.

Metadata management — This is arguably the most important of the 12 capabilities. Not only should all tools leverage the same metadata, but the offering should provide a robust way to search, capture, store, reuse and publish metadata objects such as dimensions, hierarchies, measures, performance metrics and report layout objects.

Development — The BI platform should provide a set of programmatic development tools — coupled with a software developer's kit for creating BI applications — that can be integrated into a business process, and/or embedded in another application. The BI platform should also enable developers to build BI applications without coding by using wizard-like components for a graphical assembly process. The development environment should also support Web services in performing common tasks such as scheduling, delivering, administering and managing.

Workflow and collaboration — This capability enables BI users to share and discuss information via public folders and discussion threads. In addition, the BI application can assign and track events or tasks allotted to specific users, based on pre-defined business rules. Often, this capability is delivered by integrating with a separate portal or workflow tool.


Information Delivery

Reporting — Reporting provides the ability to create formatted and interactive reports with highly scalable distribution and scheduling capabilities. In addition, BI platform vendors should handle a wide array of reporting styles (for example, financial, operational and performance dashboards).

Dashboards — This subset of reporting includes the ability to publish formal, Web-based reports with intuitive displays of information, including dials, gauges and traffic lights. These displays indicate the state of the performance metric, compared with a goal or target value. Increasingly, dashboards are used to disseminate real-time data from operational applications.

Ad hoc query — This capability, also known as self-service reporting, enables users to ask their own questions of the data, without relying on IT to create a report. In particular, the tools must have a robust semantic layer to allow users to navigate available data sources. In addition, these tools should offer query governance and auditing capabilities to ensure that queries perform well.

Microsoft Office integration — In some cases, BI platforms are used as a middle tier to manage, secure and execute BI tasks, but Microsoft Office (particularly Excel) acts as the BI client. In these cases, it is vital that the BI vendor provides integration with Microsoft Office, including support for document formats, formulas, data "refresh" and pivot tables. Advanced integration includes cell locking and write-back.

Analysis

OLAP — This enables end users to analyze data with extremely fast query and calculation performance, enabling a style of analysis known as "slicing and dicing." This capability could span a variety of storage architectures such as relational, multidimensional and in-memory.

Advanced visualization — This provides the ability to display numerous aspects of the data more efficiently by using interactive pictures and charts, instead of rows and columns. Over time, advanced visualization will go beyond just slicing and dicing data to include more process-driven BI projects, allowing all stakeholders to better understand the workflow through a visual representation.

Predictive modeling and data mining — This capability enables organizations to classify categorical variables and estimate continuous variables using advanced mathematical techniques.

Scorecards — These take the metrics displayed in a dashboard a step further by applying them to a strategy map that aligns key performance indicators to a strategic objective. Scorecard metrics should be linked to related reports and information in order to do further analysis. A scorecard implies the use of a performance management methodology such as Six Sigma or a balanced scorecard framework.


If you are in the process of choosing a vendor for your BI platform, make sure the BI platform meets atleast 8 of the 12 capabilities listed above,has a decent market presence , and the solutions are used and supported across the enterprise rather than just departmental deployments.


source : Magic Quadrant for Business Intelligence Platforms, 2008 by Gartner inc.

Friday, December 14, 2007

Using sp_MSforeachdb and sp_MSforeachtable

Lets say you have a need to update the recovery model on all databases on a sql server to FULL.
We can do this in several ways:
  1. Write a cursor to loop through all the databases and run the 'Alter database set recovery FULL' on each database.
  2. Write individual SQL statements for each database and execute as a batch.
  3. Use the undocumented stored procedure sp_MSforeachdb,which is what we are going to explore below. But before you use it, a word of caution. Note that this stored procedure may not be supported in the future from Microsoft.


declare @cmd1 varchar(500)
declare @cmd2 varchar(500)
set @cmd1 = 'if ''?'' <> ''tempdb'' print ''*** Processing DB ? ***'''
set @cmd2 = 'if ''?'' <> ''tempdb'' ALTER DATABASE ? SET RECOVERY FULL'

exec sp_MSforeachdb @command1=@cmd1,
@command2=@cmd2

You can use the sp_MSforeachtable in a similar fashion, yes , you guessed it!

Lets say you want to display the row counts of all tables in a database, here is how you can do it.

declare @cmd1 varchar(500)
set @cmd1 ='SELECT ''?'',count(*) FROM ?'
exec sp_MSforeachtable @command1 = @cmd1

For more details : http://www.databasejournal.com/features/mssql/article.php/3441031