简体   繁体   中英

MDX YTD function doesn't calculate correcty if the row is empty

My SQL server is 2008 R2. YTD function works fine except the following case.

For example if I have amount field and break down by the category (AAA, BBB, CCC). YTD doesn't show the BBB Value ($200) for Feb because it exist in Jan but not in Feb.

[Amount] 2011 JAN AAA $100 BBB $200 FEB AAA $100 CCC $300

[YTD Amount] 2011 JAN AAA $100 BBB $200 FEB AAA $200 CCC $300

This is my formula for the YTD calculated field.

AGGREGATE(YTD(), [Measures].[Amount])

How can show the value of BBB for Feb ??

You could use a calculated measure to force a 0 when there is no value:

WITH MEMBER [Measures].[Amount Or Zero] as
Iif(ISEMPTY( [Measures].[Amount]),0, [Measures].[Amount])

And then:

AGGREGATE(YTD(), [Measures].[Amount Or Zero])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM