[英]Show rows only if previous measure member meets certain condition
Consider certain query in MDX 考虑MDX中的某些查询
SELECT NON EMPTY {[Measures].[Income]} ON COLUMNS,
{
SellDate.[year].Members
} ON ROWS
FROM [HD Kawiarnia]
that shows income of a company during each year. 显示了公司每年的收入。 The question is how to show only this years in which income was higher then it was in the previous year? 问题是如何仅显示今年收入高于上一年的收入?
WITH MEMBER [Measures].[MyMeasure] as
IIF(
([Measures].[Income], [SellDate].[Year].currentmember)
<= ([Measures].[Income], [SellDate].[Year].CURRENTMEMBER.PREVMEMBER)
, NULL,
[Measures].[Income])
SELECT NON EMPTY {[Measures].[Income]} on COLUMNS
NON EMPTY {[SellDate].[Year].CHILDREN} on ROWS
FROM
[HD Kawiarnia]
I used the IIF function to to evaluate the clause and return null if the previous year income is higher. 我使用了IIF函数来评估该子句,如果前一年的收入较高,则返回null。 I got the previous year by using the PREVMEMBER function. 我通过使用PREVMEMBER函数获得了上一年的知识 。 I also replaced your [SellDate].[Year].MEMBERS with [SellDate].[Year].CHILDREN. 我还用[SellDate]。[Year] .CHILDREN替换了您的[SellDate]。[Year] .MEMBERS。 This removes the ALL member, which you probably didn't want to be returned. 这将删除ALL成员,您可能不想将其返回。
Word of caution: although Iif is the simplest way to understand how to do this, it traditionally is a bit slow (although performance has improved with 2008 and 2012 versions of SQL Server). 警告:尽管Iif是了解如何执行此操作的最简单方法,但从传统上讲它有点慢(尽管SQL Server 2008和2012版本的性能有所提高)。 This one probably won't be too bad, but in general you can replace iif functions with scripting using scope to get better performance. 这一功能可能还不错,但是总的来说,您可以使用作用域的脚本替换iif函数,以获得更好的性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.