MDX COUNT ON FILTERED SET

时间:2016-10-10 08:17:52

标签: filter count mdx

我有一个员工维度(22k行),其属性[country],[region]。我的事实表[LastAccess]很简单,只是员工的登录数据,测量[RowCount]是行数。我想计算有多少员工登录网站两次[两次访问],五次[五次访问],超过五次[更多访问]在一段时间内,按地区和国家/地区。在SQL中,我使用临时表来计算每个员工的访问次数,然后使用查询来显示:

systemctl restart httpd.service

GROUP BY ED。[BusinessRegion],ED。[CountryCode])

结果应该是这样的:

 SUM(IIF([Visits]=2,1,0)) AS [TwoVisits],   
 SUM(IIF([Visits]=5,1,0)) AS [FiveVisits],
 SUM(IIF([Visits]>5,1,0)) AS [MoreVisits],    
 FROM @EmployeeVisits EVPM
 INNER JOIN [dbo].[tblEmployeeData] ED ON EVPM.[AltEmployeeId] = ED.         [AltEmployeeId]

我做了一些这样的查询:

Region  Country  TwoVisits   FiveVisits   More Visits
1     US          1261        1054         913    
2    IN          1829        1576         1441    
3    GB          344          281         237 

但是经过长时间的运行,它给了我这个:

WITH 
MEMBER [Measures].[twoVisits] AS 
case when ([Measures].[Last Access 1 Count]) =2
    then 1
    else 0
end
MEMBER [Measures].[twoVisitsCount] AS
SUM([Employee].[Alt Employee Id].[Alt Employee Id].Members, [Measures].    [twoVisits])

SELECT  
{[Measures].[twoVisitsCount]}ON 0,
NON EMPTY ({[Employee].[Business Region].&    [1],[Employee].[Business Region].&[2],[Employee].[Business Region].&[3]},
{[Employee].[Country Code].[Country Code].Members}) ON 1
FROM 
 (
     select(
        {[Employee].[Status Id].&[1],[Employee].[Status Id].&[3],[Employee].[Status Id].&[4]},          
        {[Employee].[Employee Type].&[13],[Employee].[Employee Type].&[29],
        [Employee].[Employee Type].&[9],[Employee].[Employee Type].&[25],
        [Employee].[Employee Type].&[5],[Employee].[Employee Type].&[1],
        [Employee].[Employee Type].&[14],[Employee].[Employee Type].&[30],
        [Employee].[Employee Type].&[10],[Employee].[Employee Type].&[26],
        [Employee].[Employee Type].&[6],[Employee].[Employee Type].&[2]},
        {[Date].[Date Key].&[20160801]:[Date].[Date Key].&[20160803]}
        ) on 0
FROM [OLAP Prep]
)

所有分解计数都相同。

1 个答案:

答案 0 :(得分:1)

尝试更改此计算,如下所示。

MEMBER [Measures].[twoVisitsCount] AS
SUM(Existing [Employee].[Alt Employee Id].[Alt Employee Id].Members, [Measures].    [twoVisits])

您的计算在所有员工中循环。添加关键字Existing只会遍及该商家区域和国家/地区的员工。