在不更改度量名称的情况下将空值替换为“0”

Replace null values with '0' without changing the name of measures

如果我重命名我的措施并使用 COALESCEEMPTY 这很好用,但我需要保持措施的真实名称。有谁知道如何用 0 替换空值而不必重命名度量。

WITH 
    MEMBER [Measures].[col_] AS COALESCEEMPTY([Measures].[col],0)
    MEMBER [Measures].[col2_] AS COALESCEEMPTY([Measures].[col2],0) 
    MEMBER [Measures].[col3_] AS COALESCEEMPTY([Measures].[col3],0) 
Select 
    NON EMPTY {[Measures].[col_], [Measures].[col2_], [Measures].[col3_]} 
    DIMENSION PROPERTIES PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME, MEMBER_TYPE ON COLUMNS , 
    NON EMPTY Hierarchize({DrilldownLevel({[Region].[Region].[All]})}) 
    DIMENSION PROPERTIES PARENT_UNIQUE_NAME, HIERARCHY_UNIQUE_NAME, MEMBER_TYPE ON ROWS FROM (
    SELECT ({[Category].[Category].&[Oil]}, {[Year].[Year].&[2019]}) 
ON COLUMNS FROM [SIIBPAGESATDIREKTEF]) CELL PROPERTIES VALUE

有两种更好的方法可以在不创建新措施的情况下实现您的目标:

  1. 在度量属性中使用 format_string 属性。

The FormatString property accepts four arguments separated by a semicolon (;). The first argument is how positive value should be formatted, the second is how negative values should be formatted, the third argument is how 0 values should be formatted, and the fourth argument is how NULL should be formatted. The fourth argument is the one we are interested in! Here is an example of how I am formatting the Reseller Sales Amount: “#,##0.00;-#,##0.00;;0”.

  1. 在计算选项卡中使用 scoope 语句:

    范围([措施].[col_]); THIS=IIF(ISEMPTY([Measures].[col_]),0,[Measures].[col_]); 结束范围;

访问:https://sqldusty.com/2014/07/15/how-to-display-0s-instead-of-null-in-your-ssas-cube-mdx-query-results/