none
Modificar dimension tiempo en proyecto SSAS RRS feed

  • Pregunta

  • Hola.

    Hace un tiempo tome un proyecto SSAS que no he desarrollado yo, quien lo desarrollo creo en este una dimensión tiempo mediante el asistente de SSAS, creando una dimensión tiempo de servidor.

    La estructura de esta dimensión me a  traído ciertos problemas, tales como:

    • Los meses están ordenados de manera alfabética, no cronológica. Al crear sentencias MDX (ParallelPeriod especificamente), no me trae la informacion del mes cronológico anterior, me trae la info del mes alfabéticamente anterior a mi Current Month.
    • Los días del año, no están explícitos desde Lunes a Domingo, sino de 1 a 30 (o 31 según corresponda) esto no me permite hacer un Nemed Set que contenga los 5 días hábiles de la semana.

    Mi intención, es ver la factibilidad de modificar la actual dimensión tiempo que poseo, para que me muestre los días con el atributo de nombre, y los meses ordenados cronológicamente.

    ¿Existe alguna forma de realizar esta modificación?

    De antemano muy agradecido de quien me puedo orientar en este proceso.

    :)

    Atte,

    lunes, 16 de febrero de 2015 19:33

Respuestas

  • GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    IF OBJECT_ID('[dbo].[DimCalendar]', 'U') IS NULL
    BEGIN
    CREATE TABLE [dbo].[DimCalendar](
    	[idDate] [int] NOT NULL,
    	[date] [date] NULL,
    	[dayOfMonth] [int] NULL,
    	[dayName] [nvarchar](20) NULL,
    	[dayNameEs] [nvarchar](20) NULL,
    	[dayNamePt] [nvarchar](20) NULL,
    	[dayInMonth] [smallint] NULL,
    	[dayInQuarter] [smallint] NULL,
    	[dayInYear] [smallint] NULL,
    	[weekOfMonth] [smallint] NULL,
    	[weekOfQuarter] [smallint] NULL,
    	[weekOfYear] [smallint] NULL,
    	[month] [smallint] NULL,
    	[monthName] [nvarchar](20) NULL,
    	[monthNameEs] [nvarchar](20) NULL,
    	[monthNamePt] [nvarchar](20) NULL,
    	[monthOfQuarter] [varchar](2) NULL,
    	[quarter] [smallint] NULL,
    	[quarterMicrosoft] [smallint] NULL,
    	[year] [int] NULL,
    CONSTRAINT [PK_idDate] PRIMARY KEY CLUSTERED 
    (
    	[idDate] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    
    SET ANSI_PADDING OFF
    GO
    
    DECLARE @StartDate DATE = '01/01/2013' --Starting value of Date Range
    DECLARE @EndDate DATE = '12/31/2020' --End Value of Date Range
    DECLARE @CurrentDate DATE = @StartDate
    
    WHILE @CurrentDate < @EndDate
    BEGIN 
    	INSERT INTO [dbo].[DimCalendar] VALUES (
    		CONVERT(INT,CONVERT(NVARCHAR,@CurrentDate,112)), --Key field
    		@CurrentDate, --Date
    		DATEPART(DD, @CurrentDate), --Day on Month
    		DATENAME(dw, @CurrentDate), --Day name in English
    		dbo.udf_TitleCase(FORMAT(@CurrentDate, N'dddd', N'es-mx')), --Day name in Spanish
    		dbo.udf_TitleCase(FORMAT(@CurrentDate, N'dddd', N'pt-br')), --Day name in Portugues
    		DATEPART(DAY, @CurrentDate), --Day of month
    		DATEDIFF(d, DATEADD(qq, DATEDIFF(qq, 0, @CurrentDate), 0), @CurrentDate) + 1, --Day of Quater
    		DATEPART(DAYOFYEAR, @CurrentDate), --Day of Year
    		DATEPART(DAY, DATEDIFF(DAY, 0, @CurrentDate)/7 * 7)/7 + 1, -- Week Number of Month 
    		DATEDIFF(WEEK, DATEADD(QUARTER, DATEDIFF(QUARTER, 0, @CurrentDate), 0), @CurrentDate) +1, --Week Number of the Quarter
    		DATEPART(WEEK, @CurrentDate), --Week Number of the Year
    		DATEPART(MONTH, @CurrentDate), --Month of the Year
    		DATENAME(M, @CurrentDate), --Month name in English
    		dbo.udf_TitleCase(FORMAT(@CurrentDate, N'MMMM', N'es-mx')), --Month name in Spanish
    		dbo.udf_TitleCase(FORMAT(@CurrentDate, N'MMMM', N'pt-br')), --Month name in Portugues
    		DATEDIFF(MONTH, DATEADD(QUARTER, DATEDIFF(QUARTER, 0, @CurrentDate), 0), @CurrentDate) +1, --Month Number of the Quarter
    		DATEPART(QUARTER, @CurrentDate), --Quarter
    		DATEPART(QUARTER, DATEADD(QUARTER, 2, @CurrentDate)), --Microsoft Quater
    		DATEPART(YEAR, @CurrentDate)) --Year
    		SET @CurrentDate = DATEADD(DAY,1,@CurrentDate)
    END

    Este es  un ejemplo de una dimensión de tiempo que use.

    martes, 17 de febrero de 2015 16:55

Todas las respuestas

  • Me podrias mandar en un .sql una muestra de 1 mes, lo que mas me interesa es tu granuralidad, mándame un mes de datos (o sea por decir todo el enero) quiero ver que tan factible es lo que buscas.

    Lo más importante es ver como esta hecha la llave primaria.

    • Editado Enrique AA martes, 17 de febrero de 2015 2:11
    lunes, 16 de febrero de 2015 19:42
  • Hazte lo primero de todo una copia de seguridad, y luego cambia la gr anualidad de la dimensión, añade por ejemplo los días laborables L M X J V, un numero que indique cual quieres que sea el comienzo de la semana, el numero de mes en vez del nombre etc. Una vez tenga definida tu nueva dimensión re-procesa esa dimensión y luego re procesa el cubo y vuelve a ejecutar la visualización pero ahora añadiendo los filtros nuevos.

    Saludos.

    martes, 17 de febrero de 2015 16:08
  • GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    IF OBJECT_ID('[dbo].[DimCalendar]', 'U') IS NULL
    BEGIN
    CREATE TABLE [dbo].[DimCalendar](
    	[idDate] [int] NOT NULL,
    	[date] [date] NULL,
    	[dayOfMonth] [int] NULL,
    	[dayName] [nvarchar](20) NULL,
    	[dayNameEs] [nvarchar](20) NULL,
    	[dayNamePt] [nvarchar](20) NULL,
    	[dayInMonth] [smallint] NULL,
    	[dayInQuarter] [smallint] NULL,
    	[dayInYear] [smallint] NULL,
    	[weekOfMonth] [smallint] NULL,
    	[weekOfQuarter] [smallint] NULL,
    	[weekOfYear] [smallint] NULL,
    	[month] [smallint] NULL,
    	[monthName] [nvarchar](20) NULL,
    	[monthNameEs] [nvarchar](20) NULL,
    	[monthNamePt] [nvarchar](20) NULL,
    	[monthOfQuarter] [varchar](2) NULL,
    	[quarter] [smallint] NULL,
    	[quarterMicrosoft] [smallint] NULL,
    	[year] [int] NULL,
    CONSTRAINT [PK_idDate] PRIMARY KEY CLUSTERED 
    (
    	[idDate] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    END
    
    SET ANSI_PADDING OFF
    GO
    
    DECLARE @StartDate DATE = '01/01/2013' --Starting value of Date Range
    DECLARE @EndDate DATE = '12/31/2020' --End Value of Date Range
    DECLARE @CurrentDate DATE = @StartDate
    
    WHILE @CurrentDate < @EndDate
    BEGIN 
    	INSERT INTO [dbo].[DimCalendar] VALUES (
    		CONVERT(INT,CONVERT(NVARCHAR,@CurrentDate,112)), --Key field
    		@CurrentDate, --Date
    		DATEPART(DD, @CurrentDate), --Day on Month
    		DATENAME(dw, @CurrentDate), --Day name in English
    		dbo.udf_TitleCase(FORMAT(@CurrentDate, N'dddd', N'es-mx')), --Day name in Spanish
    		dbo.udf_TitleCase(FORMAT(@CurrentDate, N'dddd', N'pt-br')), --Day name in Portugues
    		DATEPART(DAY, @CurrentDate), --Day of month
    		DATEDIFF(d, DATEADD(qq, DATEDIFF(qq, 0, @CurrentDate), 0), @CurrentDate) + 1, --Day of Quater
    		DATEPART(DAYOFYEAR, @CurrentDate), --Day of Year
    		DATEPART(DAY, DATEDIFF(DAY, 0, @CurrentDate)/7 * 7)/7 + 1, -- Week Number of Month 
    		DATEDIFF(WEEK, DATEADD(QUARTER, DATEDIFF(QUARTER, 0, @CurrentDate), 0), @CurrentDate) +1, --Week Number of the Quarter
    		DATEPART(WEEK, @CurrentDate), --Week Number of the Year
    		DATEPART(MONTH, @CurrentDate), --Month of the Year
    		DATENAME(M, @CurrentDate), --Month name in English
    		dbo.udf_TitleCase(FORMAT(@CurrentDate, N'MMMM', N'es-mx')), --Month name in Spanish
    		dbo.udf_TitleCase(FORMAT(@CurrentDate, N'MMMM', N'pt-br')), --Month name in Portugues
    		DATEDIFF(MONTH, DATEADD(QUARTER, DATEDIFF(QUARTER, 0, @CurrentDate), 0), @CurrentDate) +1, --Month Number of the Quarter
    		DATEPART(QUARTER, @CurrentDate), --Quarter
    		DATEPART(QUARTER, DATEADD(QUARTER, 2, @CurrentDate)), --Microsoft Quater
    		DATEPART(YEAR, @CurrentDate)) --Year
    		SET @CurrentDate = DATEADD(DAY,1,@CurrentDate)
    END

    Este es  un ejemplo de una dimensión de tiempo que use.

    martes, 17 de febrero de 2015 16:55