Dear Friends,
I need to create a new column in a VIEW with a reference date to call from SQL Analysis Services 2005.
The refDate is the last VALID date from previous year for each date in each row of FactTable. My TimeTable only has valid dates (does not has holidays, saturday, sunday and forcedHolidays). so I need a query to get for each date in each row of FactTable the last date for previous year. Probably using the parameter "year" of the date in each row in facttable (using Datepart)
Someone help me?
Help me please!|||Pedro,
To clarify: RefDate is the highest date from the Time Dimension table for a given year (dateid should be ignored)?
Also, you say "the last date for previous year" but your sample result shows the last date of the same year. Should DateID=8225 have 25-12-2004?
|||Dalej you are write!!
I made a mistake, is
The RefDate is the highest date from Time Table for a given year (for each date in each row)
Could help me?!
THANKS
|||
Code Snippet
select ft.*, td.RefDate
from FactTabl ft
innerjoin
(
select [Year],max([Day])as RefDate
from [Time Dimension]
groupby [Year]
)as td
on(ft.datepart(yy, Date)-1)= td.[Year]
|||Dear alej,
I customize your statment to my database and there is an error...
Code Snippet
select ft.*, td.RefDate
from FactCashFlows ft
innerjoin
(
select [Ano],max([Dia])as RefDate
from [DimTime]
groupby [Ano]
)as td
on(ft.datepart(yy, T_Dia)-1)= td.[Ano]
The error is:
Code Snippet
Msg 4121, Level 16, State 1, Line 1
Cannot find either column "ft" or the user-defined function or aggregate "ft.datepart", or the name is ambiguous.
When I was trying to customize your code I saw that I dont have the DATE in my FactTable, only the integer foreign key for time dimension. So, I created the FactCashFlow as a view to do a inner join to time table to get the date value.
If I can do it only in one view would be perfect!!
Could help me?
Thanks!!!
|||
OK!
I changed and this statment finally works:
Code Snippet
select ft.*, td.RefDate
from FactCashFlows ft
innerjoin
(
select [Ano],max([Dia])as RefDate
from [DimTime]
groupby [Ano]
)as td
on(datepart(yy, ft.T_Dia)-1)= td.[Ano]
But I have 2 views, and would be better using only one...
I need to change the the first select to get the date value from time dimension...
|||In order to have only one view to call from SSAS, I need the query something like this:
Code Snippet
select ft.*, td.RefDate, MyTable.Dia
from(SELECT Dia FROM dbo.Time INNERJOIN dbo.CashFlows ON CF_RKData_ID=time.ID) MyTable INNERJOIN
CashFlows ft
innerjoin
(
select [Ano],max([Dia])as RefDate
from [DimTime]
groupby [Ano]
)as td
on(datepart(yy, ft.T_Dia)-1)= td.[Ano]
Code Snippet
Msg 102, Level 15, State 1, Line 11
Incorrect syntax near 'Ano'.
And this view will be the FactCashFlows in SSAS!
But this is wrong, could someone help me?
Thanks!
|||OK I Found the solution...
Code Snippet
select ft.*, td.RefDate
from(dbo.time INNERJOIN CashFlows ft ON CF_RKData_ID=time.ID)
innerjoin
(
select [Ano],max([Dia])as RefDate
from [DimTime]
groupby [Ano]
)as td
on(datepart(yy, dbo.time.Dia)-1)= td.[Ano]
THANKS ALL!!!
No comments:
Post a Comment