如何仅根据特定记录的最新日期检索数据。
SELECT
[Measures].[Assessment Patients Detail] ON COLUMNS
,NON EMPTY
(
[DimAssessment].[Assessment Text].&[Employee Wellness HRA]
,[DimAssessment].[Question Text].&[Do you use tobacco products?]
,[DimPatient].[Patient Key].[Patient Key]
,Generate
(
[DimAssessment].[Answer Text].[Answer Text].MEMBERS
,
[DimAssessment].[Answer Text].CurrentMember
*
Tail
(
NonEmpty
(
[DimDate].[Full Date Alternate Key].[Full Date Alternate Key].MEMBERS
,[DimAssessment].[Answer Text].CurrentMember
)
,[DimPatient].[Patient Key]
)
)
) ON ROWS
FROM [CareManagement];
答案 0 :(得分:0)
你所追求的可能是LastNonEmpty聚合
LastNonEmpty函数是半加性函数,需要类型为时间的维度才能适用(可以在“维度属性”中设置),这是因为当度量沿时间维度聚合时,它与沿任何其他(非时间)维度聚合相同度量时的行为不同。
取自以下链接:http://thinknook.com/ssas-lastnonempty-aggregation-function-2012-08-18/
答案 1 :(得分:0)
我认为您在Generate
内使用了错误的层次结构?
SELECT
[Measures].[Assessment Patients Detail] ON 0
,NON EMPTY
{[DimAssessment].[Assessment Text].&[Employee Wellness HRA]}*
{[DimAssessment].[Question Text].&[Do you use tobacco products?]}*
{Generate
(
[DimPatient].[Patient Key].[Patient Key].MEMBERS
,
[DimPatient].[Patient Key].CurrentMember
*
Tail
(
NonEmpty
(
[DimDate].[Full Date Alternate Key].[Full Date Alternate Key].MEMBERS
,[DimPatient].[Patient Key].CurrentMember
)
)
)}*
{[DimAssessment].[Answer Text].[Answer Text].MEMBERS} ON 1
FROM [CareManagement];
以下是AdvWrks
中的类似情况 - SO上的几个用户使用此多维数据集,因此我们都可以玩:
SELECT
[Measures].[Internet Sales Amount] ON 0
,NON EMPTY
{
[Customer].[Customer].[Alexis Thomas]
,[Customer].[Customer].[Carlos Morgan]
,[Customer].[Customer].[Carlos Scott]
}*
[Customer].[Customer Geography].[Country]*
[Date].[Calendar].[Month] ON 1
FROM [Adventure Works];
它给出了这个:
我可以开始添加Generate
尝试,但我得到以下内容但是只要我添加Tail
,结果就会消失 - 不确定它为什么会这样:
SELECT
[Measures].[Internet Sales Amount] ON 0
,NON EMPTY
Generate
(
{
[Customer].[Customer].[Alexis Thomas]
,[Customer].[Customer].[Carlos Morgan]
,[Customer].[Customer].[Carlos Scott]
} AS S
,
s.CurrentMember
*
NonEmpty
(
[Date].[Calendar].[Month].MEMBERS
*
[Customer].[Customer Geography].[Country]
,s.CurrentMember
)
) ON 1
FROM [Adventure Works];