Ssas 如何按范围分组记录并将其放在行上
下面的查询计算员工的工时百分比。i、 e.行上的员工和列上的工作百分比Ssas 如何按范围分组记录并将其放在行上,ssas,mdx,Ssas,Mdx,下面的查询计算员工的工时百分比。i、 e.行上的员工和列上的工作百分比 With Member [Measures].[EmployeeWisePercent] AS [Measures].[Hours] / ([Employee].[Employee].[All], [Measures].[Hours]) * 100 Member [Measures].[TotalHours] AS ([Employee].[Employee].[All], [Measures].[Hours]) SE
With Member [Measures].[EmployeeWisePercent] AS
[Measures].[Hours] / ([Employee].[Employee].[All], [Measures].[Hours]) * 100
Member [Measures].[TotalHours] AS
([Employee].[Employee].[All], [Measures].[Hours])
SELECT NON EMPTY
{ [Measures].[Hours], [Measures].[EmployeeWisePercent], [Measures].[TotalHours] } ON COLUMNS,
NON EMPTY
{ ([Employee].[Employee].[Employee].ALLMEMBERS ) }
DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM
( SELECT ( STRTOSET("[Date].[Calendar].[All]", CONSTRAINED) ) ON COLUMNS FROM
( SELECT ( STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED) ) ON COLUMNS FROM
[TimeSheetHours Cube]))
WHERE ( IIF( STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED).Count = 1,
STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED),
[Project].[Project Name].currentmember ),
IIF( STRTOSET("[Date].[Calendar].[All]", CONSTRAINED).Count = 1,
STRTOSET("[Date].[Calendar].[All]", CONSTRAINED), [Date].[Calendar].currentmember ) )
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
输出如下所示
Employee Name | Hours | Percent | Total Hours
Employee1 | 975.86 | 1.32 | 73421.22
Employee2 | (null) | (null) | 73421.22
Employee3 | (null) | (null) | 73421.22
Employee4 | (null) | (null) | 73421.22
Employee5 | (null) | (null) | 73421.22
Employee6 | (null) | (null) | 73421.22
...
...
...
我需要更新上面的查询,以获取员工数量,并将其按行(0-20%,20-40%,等等)和列(属于该范围的员工数量)进行分组。如下所示:
Employee Name | EmployeeCount
0-20% | 5
20-40% | 8
40-60% | 88
60-80% | 2
80-100% | 1
是否有任何方法可以将百分比计数分组到上面指定的范围内?
请帮助我准备mdx查询以获得所需的输出
注意:我现在不需要在行上显示员工姓名。据我所知,您的要求基本上是创建两个计算的度量(员工计数和百分比括号),并显示一个度量与另一个度量的聚合结果。这基本上可以转化为(下面的伪代码)—— 虽然这在有点复杂的SQL中是可能的,但在MDX中是不可能的。 主要原因是,这里需要的是两步计算。第一步将计算员工将跌落的支架,在下一步中,使用此结果获得每个支架的计数。这似乎可以通过使用计算成员来实现,但您必须记住,度量值不是持久的。如果没有范围,则在整个层次结构上聚合度量值。除非运行MDX,否则无法推断度量值可以包含的唯一值 在SQL中,这可以通过使用
子查询
或联接
实现,因为联接可以在聚合值处进行(并且它们被视为持久的),但MDX中不存在该特性
可能的情况是,有5个单独的计算成员,每个括号中都有计数。由于这将是一步计算,因此它将在MDX的权限范围内
这将是下面几行中的一行-
With Member [Measures].[EmployeeWisePercent] AS
[Measures].[Hours] / ([Employee].[Employee].[All], [Measures].[Hours]) * 100
Member [Measures].[TotalHours] AS
([Employee].[Employee].[All], [Measures].[Hours])
MEMBER MEASURES.[0-20%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=0 AND [Measures].EmployeeWisePercent<20))
MEMBER [20-40%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=20 AND [Measures].EmployeeWisePercent<40))
MEMBER [40-60%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=40 AND [Measures].EmployeeWisePercent<60))
MEMBER [60-80%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=60 AND [Measures].EmployeeWisePercent<80))
MEMBER [80-100%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=80 AND [Measures].EmployeeWisePercent<=100))
SELECT NON EMPTY
{ MEASURES.[0-20%], MEASURES.[20-40%], MEASURES.[40-60%], MEASURES.[60-80%], MEASURES.[80-100%] } ON COLUMNS
FROM
( SELECT ( STRTOSET("[Date].[Calendar].[All]", CONSTRAINED) ) ON COLUMNS FROM
( SELECT ( STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED) ) ON COLUMNS FROM
[TimeSheetHours Cube]))
WHERE ( IIF( STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED).Count = 1,
STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED),
[Project].[Project Name].currentmember ),
IIF( STRTOSET("[Date].[Calendar].[All]", CONSTRAINED).Count = 1,
STRTOSET("[Date].[Calendar].[All]", CONSTRAINED), [Date].[Calendar].currentmember ) )
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
成员[Measures].[EmployeeWisePercent]为
[措施].[小时]/([员工].[员工].[全部],[措施].[小时])*100
成员[测量][TotalHours]为
([Employee]。[Employee]。[All],[Measures]。[Hours])
成员度量。[0-20%]作为
计数(筛选器(现有[Employee].[Employee].[Measures].EmployeeWisePercent>=0和[Measures].EmployeeWisePercent=20和[Measures].EmployeeWisePercent=40和[Measures].EmployeeWisePercent=80和[Measures].EmployeeWisePercent我想知道这段到Sourav的脚本是如何影响结果的:
1.它们仍然有效吗?
2.下面的跑得快吗
它使用了一个扭曲的计数(FILTER
结构。MoshaP在博客中谈到了这一点:
成员[Measures].[EmployeeWisePercent]为
[措施].[小时]/([员工].[员工].[全部],[措施].[小时])*100
成员[测量][TotalHours]为
([Employee]。[Employee]。[All],[Measures]。[Hours])
成员[措施][0-20%]作为
总数(
现有[Employee].[Employee]。子项,
IIF(
[度量值].[EmployeeWisePercent]>=0
及
[措施][EmployeeWisePercent]=20
及
[措施][EmployeeWisePercent]=40
及
[措施][EmployeeWisePercent]=60
及
[措施][EmployeeWisePercent]=80
及
[Measures][EmployeeWisePercent]你太棒了!我喜欢你处理百分比范围的方式。谢谢。回答得很好
With Member [Measures].[EmployeeWisePercent] AS
[Measures].[Hours] / ([Employee].[Employee].[All], [Measures].[Hours]) * 100
Member [Measures].[TotalHours] AS
([Employee].[Employee].[All], [Measures].[Hours])
MEMBER MEASURES.[0-20%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=0 AND [Measures].EmployeeWisePercent<20))
MEMBER [20-40%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=20 AND [Measures].EmployeeWisePercent<40))
MEMBER [40-60%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=40 AND [Measures].EmployeeWisePercent<60))
MEMBER [60-80%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=60 AND [Measures].EmployeeWisePercent<80))
MEMBER [80-100%] AS
COUNT(FILTER(EXISTING [Employee].[Employee].CHILDREN, [Measures].EmployeeWisePercent >=80 AND [Measures].EmployeeWisePercent<=100))
SELECT NON EMPTY
{ MEASURES.[0-20%], MEASURES.[20-40%], MEASURES.[40-60%], MEASURES.[60-80%], MEASURES.[80-100%] } ON COLUMNS
FROM
( SELECT ( STRTOSET("[Date].[Calendar].[All]", CONSTRAINED) ) ON COLUMNS FROM
( SELECT ( STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED) ) ON COLUMNS FROM
[TimeSheetHours Cube]))
WHERE ( IIF( STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED).Count = 1,
STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED),
[Project].[Project Name].currentmember ),
IIF( STRTOSET("[Date].[Calendar].[All]", CONSTRAINED).Count = 1,
STRTOSET("[Date].[Calendar].[All]", CONSTRAINED), [Date].[Calendar].currentmember ) )
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS
With Member [Measures].[EmployeeWisePercent] AS
[Measures].[Hours] / ([Employee].[Employee].[All], [Measures].[Hours]) * 100
Member [Measures].[TotalHours] AS
([Employee].[Employee].[All], [Measures].[Hours])
MEMBER [Measures].[0-20%] AS
SUM(
EXISTING [Employee].[Employee].CHILDREN,
IIF(
[Measures].[EmployeeWisePercent]>=0
AND
[Measures].[EmployeeWisePercent]<20
,1
,NULL)
)
MEMBER [Measures].[20-40%] AS
SUM(
EXISTING [Employee].[Employee].CHILDREN,
IIF(
[Measures].[EmployeeWisePercent]>=20
AND
[Measures].[EmployeeWisePercent]<40
,1
,NULL)
)
MEMBER [Measures].[40-60%] AS
SUM(
EXISTING [Employee].[Employee].CHILDREN,
IIF(
[Measures].[EmployeeWisePercent]>=40
AND
[Measures].[EmployeeWisePercent]<60
,1
,NULL)
)
MEMBER [Measures].[60-80%] AS
SUM(
EXISTING [Employee].[Employee].CHILDREN,
IIF(
[Measures].[EmployeeWisePercent]>=60
AND
[Measures].[EmployeeWisePercent]<80
,1
,NULL)
)
MEMBER [Measures].[80-100%] AS
SUM(
EXISTING [Employee].[Employee].CHILDREN,
IIF(
[Measures].[EmployeeWisePercent]>=80
AND
[Measures].[EmployeeWisePercent]<=100
,1
,NULL)
)
SELECT
NON EMPTY
{
MEASURES.[0-20%]
, MEASURES.[20-40%]
, MEASURES.[40-60%]
, MEASURES.[60-80%]
, MEASURES.[80-100%]
} ON COLUMNS
FROM
(
SELECT ( STRTOSET("[Date].[Calendar].[All]", CONSTRAINED) ) ON COLUMNS
FROM
(
SELECT
( STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED) ) ON COLUMNS
FROM [TimeSheetHours Cube]
)
)
WHERE
( IIF( STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED).Count = 1,
STRTOSET("[Project].[Project Name].&[Self Study]", CONSTRAINED),
[Project].[Project Name].currentmember ),
IIF( STRTOSET("[Date].[Calendar].[All]", CONSTRAINED).Count = 1,
STRTOSET("[Date].[Calendar].[All]", CONSTRAINED), [Date].[Calendar].currentmember ) )
CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS