我有一个事实表,其中列出了公司中每位员工都已通过的所有课程。
FactPassedCourse :( CourseKey,EmployeeKey,DateKey)
DimEmployee:(EmployeeKey)
DimCourse :( CourseKey)
Emp1,Emp2
课程1,课程2,课程3,课程4,课程5
FactPassedCourse
-----------------------------------------
(Emp1, Course1, DateKey1)
(Emp1, Course2, DateKey2)
(Emp1, Course2, DateKey3)
(Emp1, Course3, DateKey3)
(Emp1, Course4, DateKey3)
(Emp2, Course4, DateKey1)
(Emp2, Course5, DateKey5)
DimEmployee& DimCourse与我的Cube中的FactPassedCourse有规律的关系。
我希望根据每门课程获得员工人数,但如果员工不止一次通过特殊课程(如Course2),那么员工必须被计算一次,我的意思是我想要的结果:
MDX结果:
(Coursename: Course1 Employee_Count: 1)
(Coursename: Course2 Employee_Count: 1:because ONE employee passed this course two times)
(Coursename: Course3 Employee_Count: 1)
(Coursename: Course4 Employee_Count: 2: because two different employees passed this course)
(Coursename: Course5 Employee_Count: 1)
为了得到这个结果,我写了这个mdx查询,这会返回正确的结果,但这个查询的性能非常慢。
With
Member [measures].[Employee_Count] as
Count(
Filter(
[DimEmployee].EmployeeKey].members-[DimEmployee].[EmployeeKey].[All]),
[measures].[FactPassedCourseCount]>0)
)
Set [Course_Set] as
Filter(
([DimCourse].[CourseKey].members–[DimCourse].CourseKey].[All]),
[measures].[FactPassedCourseCount] > 0
)
Select
[measures].[Employee_Count] on 0
, [Course_Set] on 1
From MyCube
此查询结果为:
(Coursename: Course1 Employee_Count: 1)
(Coursename: Course2 Employee_Count)
(Coursename: Course3 Employee_Count: 1)
(Coursename: Course4 Employee_Count)
(Coursename: Course5 Employee_Count: 1)
有没有更好的方法来编写具有快速性能的mdx查询?
答案 0 :(得分:0)
这样更快吗?
With
Member [measures].[Employee_Count] as
Count(
EXISTING
NONEMPTY(
[DimEmployee].[EmployeeKey].[EmployeeKey]
,[measures].[FactPassedCourseCount]
)
)
Select
[measures].[Employee_Count] on 0
, NONEMPTY(
[DimCourse].[CourseKey].[CourseKey]
,[measures].[FactPassedCourseCount]
) on 1
From [MyCube];
答案 1 :(得分:0)
接受答案的替代方案 -
with member [measures].[Employee_Count] AS
NonEmpty
(
[DimEmployee].EmployeeKey].[EmployeeKey].members,
([DimCourse].[CourseKey].Currentmember, [measures].[FactPassedCourseCount])
).Count
Select
[measures].[Employee_Count] on 0
, [Course_Set] on 1
From MyCube
此外,如果您想根据任何值进行过滤,有一种方法可以在不使用filter
的情况下进行过滤。
with
member measures.GrtThan5 as
IIF(
[Measures].[Claim As Of - Count] > 5,
1,
NULL
)
定义必须改为以下 -
member [measures].[Employee_Count] AS
NonEmpty
(
[DimEmployee].EmployeeKey].[EmployeeKey].members,
([DimCourse].[CourseKey].Currentmember, [measures].GrtThan5)
).Count