SSAS / MDX:除以COUNT覆盖FORMAT_STRING吗?

时间:2019-04-05 12:49:46

标签: ssas mdx

在格式化SSAS(多维)中的计算成员时,我遇到一个奇怪的问题。

我有一个在年度级别上定义的预算金额,然后通过将年度金额除以成员数,将其分配到季度,月或周级别。

将SCOPE与DIVIDE和COUNT MDX函数一起使用时,不再应用定义的小节格式(FORMAT_STRING)。

这是代码和示例:

CREATE MEMBER CURRENTCUBE.[Measures].[VA Budget]
AS 
    NULL,
FORMAT_STRING = "#,#.00",
VISIBLE = 1; 

([Measures].[VA Budget], [Datum].[Datum JQMT].[Jahr].Members) = [VA Jahresbudget];
([Measures].[VA Budget], [Datum].[Datum JQMT].[Quartal].Members) = DIVIDE([VA Jahresbudget], COUNT( Descendants(Ancestor([Datum].[Datum JQMT].CurrentMember, [Datum].[Datum JQMT].[Jahr]), [Datum].[Datum JQMT].[Quartal]) ));
([Measures].[VA Budget], [Datum].[Datum JQMT].[Monat].Members) = DIVIDE([VA Jahresbudget], COUNT( Descendants(Ancestor([Datum].[Datum JQMT].CurrentMember, [Datum].[Datum JQMT].[Jahr]), [Datum].[Datum JQMT].[Monat]) ));
([Measures].[VA Budget], [Datum].[Datum JQMT].[Tag].Members) = DIVIDE([VA Jahresbudget], COUNT( Descendants(Ancestor([Datum].[Datum JQMT].CurrentMember, [Datum].[Datum JQMT].[Jahr]), [Datum].[Datum JQMT].[Tag]) ));
([Measures].[VA Budget], [Datum].[Datum JWT].[Woche].Members) = DIVIDE([VA Jahresbudget], COUNT( Descendants(Ancestor([Datum].[Datum JWT].CurrentMember, [Datum].[Datum JWT].[Jahr]), [Datum].[Datum JWT].[Woche]) ));

[]

但是,当我不使用DIVIDE函数中的COUNT时,它可以正确应用:

([Measures].[VA Budget], [Datum].[Datum JQMT].[Monat].Members) = DIVIDE([VA Jahresbudget], 12 ));

[]

此外,如果我定义了另一个计算所得的成员并且引用了前一个成员,则格式将再次正确应用:

CREATE MEMBER CURRENTCUBE.[Measures].[VA Budget2]
AS 
    [Measures].[VA Budget],
FORMAT_STRING = "#,#.00",
VISIBLE = 1; 

[]

这是怎么回事?这是错误吗?如何在不定义其他计算所得成员的情况下使格式正确?

(SSAS版本为2016-13.0.5206)

1 个答案:

答案 0 :(得分:0)

似乎MDX函数Divide()会导致结果丢失格式。

一种解决方法是创建一个仅包含DIVIDE定义的新的(不可见的)计算成员;然后在您的计算成员中使用它。这里是一个例子:

CREATE MEMBER CURRENTCUBE.[Measures].[My measure YTD]
 AS NULL, 
FORMAT_STRING = "0.0000",
VISIBLE = 1 ,  ASSOCIATED_MEASURE_GROUP = 'MeasureGroup';


CREATE MEMBER CURRENTCUBE.[Measures].[My measure YTD DIVIDE YMD]
 AS DIVIDE (
        AGGREGATE (
                         PeriodsToDate([Date].[Year-Month-Day].[Year YMD],
                                        [Date].[Year-Month-Day].CurrentMember),
                         [Measures].[Dividend]
                    ),
        AGGREGATE (
                         PeriodsToDate([Date].[Year-Month-Day].[Year YMD],
                                        [Date].[Year-Month-Day].CurrentMember),
                         [Measures].[Divisor]
                    )
 ),
FORMAT_STRING = "0.0000",
VISIBLE = 0 ,  ASSOCIATED_MEASURE_GROUP = 'MeasureGroup';

CREATE MEMBER CURRENTCUBE.[Measures].[My measure YTD DIVIDE YQMD]
 AS DIVIDE (
        AGGREGATE (
                         PeriodsToDate([Date].[Year-Quarter-Month-Day].[Year YQMD],
                                        [Date].[Year-Quarter-Month-Day].CurrentMember),
                         [Measures].[Dividend]
                    ),
        AGGREGATE (
                         PeriodsToDate([Date].[Year-Quarter-Month-Day].[Year YQMD],
                                        [Date].[Year-Quarter-Month-Day].CurrentMember),
                         [Measures].[Divisor]
                    )
 ),
FORMAT_STRING = "0.0000",
VISIBLE = 0 ,  ASSOCIATED_MEASURE_GROUP = 'MeasureGroup';

SCOPE ( [Measures].[My measure YTD] );

    SCOPE ( [Date].[Data YMD].MEMBERS, [Date].[Year YMD].[Year YMD].MEMBERS );
        THIS = [My measure YTD DIVIDE YMD];
    END SCOPE;

    SCOPE ( [Date].[Data YQMD].MEMBERS, [Date].[Year YQMD].[Year YQMD].MEMBERS );
        THIS = [Measures].[My measure YTD DIVIDE YQMD];
    END SCOPE;

END SCOPE;