Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
Can any one plese help me in retreiving the latest Startdate record with its corresponding record using calculated member in ssas. I have four dimension out of which two are date dimension and the last is department.

EmployeeId StartDate EndDate Dept
101 03/02/2013 01/01/2014 Dept1
102 04/07/2012 25/05/2005 Dept5
102 25/05/2005 15/06/2012 Dept7
101 02/01/2014 27/09/2015 Dept6
102 15/06/2012 20/10/2015 Dept4




Each column is maintatined individual dimensions.
My result required should be latest start date and its corresponding row like below

EmployeeId StartDate EndDate Dept
101 02/01/2014 27/09/2015 Dept6
102 15/06/2012 20/10/2015 Dept4



Thank you in advance

What I have tried:

SQL
WITH
MEMBER [Measures].[LatestEmpStartDate] AS
 TAIL(NONEMPTY([Emp_StartDate].[Full Date].[Full Date].MEMBERS, [Measures].[No_of_Emp]),1).ITEM(0).MEMBER_NAME
 
MEMBER [Measures].[LatestEmpEndDate] AS
 TAIL(NONEMPTY(
 {LINKMEMBER(TAIL(NONEMPTY([Emp_StartDate].[Full Date].[Full Date].MEMBERS, [Measures].[No_of_Emp]),1).ITEM(0)
 ,[Emp_EndDate].[Full Date]) : null}
 , [Measures].[No_of_Emp]),1).ITEM(0).MEMBER_NAME


MEMBER [Measures].[LatestDept] AS
  TAIL(NONEMPTY(
 {LINKMEMBER(TAIL(NONEMPTY([Emp_StartDate].[Full Date].[Full Date].MEMBERS, [Measures].[No_of_Emp]),1).ITEM(0)
 , [DIM_Dept].[Dept_Code])} 
 , [Measures].[No_of_Emp]),1).ITEM(0).MEMBER_NAME

SELECT
 {
  [Measures].[LatestEmpStartDate]
 , [Measures].[LatestEmpEndDate]
  , [Measures].[LatestDept] 
 } on columns
 
,NON EMPTY
 [Employee].[EmpID].members
 on ROWS
 From Cub_
Posted
Updated 15-Feb-16 6:48am
v2

1 solution

Just use a JOIN:
SQL
SELECT a.EmployeeId, a.StartDate, a.EndDate, a.Dept FROM MyTable a
JOIN (SELECT EmployeeID, MAX(StartDate) AS maxSD FROM MyTable
      GROUP BY EmployeeId) b
ON a.EmployeeId = b.EmployeeId AND a.StartDate = b.maxSD
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900