如何在 SSAS 多维数据集中用 0 替换 null
How to replace null with 0 in SSAS cube
我需要在 SSAS cube
中用 0 替换 null。实现该目标的正确方法是什么?
这是我当前的查询:
SELECT {([Measures].[Employee Age Count])}
ON COLUMNS, { ([Dim Gender].[Gender Name].[Gender Name].ALLMEMBERS *
[Dim Age Ranges].[Age Range ID].[Age Range ID].ALLMEMBERS ) } ON ROWS
FROM ( SELECT ( { [Dim Location].[Location].[Location Grp Name].&[BOSTON] }) ON COLUMNS
FROM [People Dashboard])
WHERE ( [Dim Location].[Location].[Location Grp Name].&[BOSTON] )
当前查询的结果:
我还没有测试过,但如果有效,您可以像下面这样尝试,
SELECT {COALESCE (([Measures].[Employee Age Count]),"0") as AgeCount}
ON COLUMNS, { ([Dim Gender].[Gender Name].[Gender Name].ALLMEMBERS *
[Dim Age Ranges].[Age Range ID].[Age Range ID].ALLMEMBERS ) } ON ROWS
FROM ( SELECT ( { [Dim Location].[Location].[Location Grp Name].&[BOSTON] }) ON COLUMNS
FROM [People Dashboard])
WHERE ( [Dim Location].[Location].[Location Grp Name].&[BOSTON] )
WITH MEMBER [Measures].[MEASURE_NONEMPTY] AS COALESCEEMPTY([Measures].[Service Period
Count], 0)
SELECT {[Measures].[MEASURE_NONEMPTY]} ON COLUMNS, { ([Dim Gender].[Gender Name].[Gender
Name].ALLMEMBERS * [Dim Age Ranges].[Age Range ID].[Age Range ID].ALLMEMBERS )
} ON ROWS FROM ( SELECT ( { [Dim Location].[Location].[Location Grp Name].&
[BOSTON] } ) ON COLUMNS FROM [People Dashboard]) WHERE ( [Dim Location].
[Location].[Location Grp Name].&[BOSTON] )
我使用上面的代码作为我的解决方案。
我认为IIF(ISEMPTY...
很标准。
我还通过删除相当多的大括号简化了您的脚本,并将逻辑从子选择中移到基本的 WHERE
子句中:
WITH MEMBER [Measures].[MEASURE_NONEMPTY] AS
IIF(
ISEMPTY([Measures].[Service Period Count])
,0
,[Measures].[Service Period Count]
)
SELECT
{[Measures].[MEASURE_NONEMPTY]} ON 0,
[Dim Gender].[Gender Name].[Gender Name].ALLMEMBERS
* [Dim Age Ranges].[Age Range ID].[Age Range ID].ALLMEMBERS
ON 1
FROM [People Dashboard]
WHERE [Dim Location].[Location].[Location Grp Name].&[BOSTON]
;
我需要在 SSAS cube
中用 0 替换 null。实现该目标的正确方法是什么?
这是我当前的查询:
SELECT {([Measures].[Employee Age Count])}
ON COLUMNS, { ([Dim Gender].[Gender Name].[Gender Name].ALLMEMBERS *
[Dim Age Ranges].[Age Range ID].[Age Range ID].ALLMEMBERS ) } ON ROWS
FROM ( SELECT ( { [Dim Location].[Location].[Location Grp Name].&[BOSTON] }) ON COLUMNS
FROM [People Dashboard])
WHERE ( [Dim Location].[Location].[Location Grp Name].&[BOSTON] )
当前查询的结果:
我还没有测试过,但如果有效,您可以像下面这样尝试,
SELECT {COALESCE (([Measures].[Employee Age Count]),"0") as AgeCount}
ON COLUMNS, { ([Dim Gender].[Gender Name].[Gender Name].ALLMEMBERS *
[Dim Age Ranges].[Age Range ID].[Age Range ID].ALLMEMBERS ) } ON ROWS
FROM ( SELECT ( { [Dim Location].[Location].[Location Grp Name].&[BOSTON] }) ON COLUMNS
FROM [People Dashboard])
WHERE ( [Dim Location].[Location].[Location Grp Name].&[BOSTON] )
WITH MEMBER [Measures].[MEASURE_NONEMPTY] AS COALESCEEMPTY([Measures].[Service Period
Count], 0)
SELECT {[Measures].[MEASURE_NONEMPTY]} ON COLUMNS, { ([Dim Gender].[Gender Name].[Gender
Name].ALLMEMBERS * [Dim Age Ranges].[Age Range ID].[Age Range ID].ALLMEMBERS )
} ON ROWS FROM ( SELECT ( { [Dim Location].[Location].[Location Grp Name].&
[BOSTON] } ) ON COLUMNS FROM [People Dashboard]) WHERE ( [Dim Location].
[Location].[Location Grp Name].&[BOSTON] )
我使用上面的代码作为我的解决方案。
我认为IIF(ISEMPTY...
很标准。
我还通过删除相当多的大括号简化了您的脚本,并将逻辑从子选择中移到基本的 WHERE
子句中:
WITH MEMBER [Measures].[MEASURE_NONEMPTY] AS
IIF(
ISEMPTY([Measures].[Service Period Count])
,0
,[Measures].[Service Period Count]
)
SELECT
{[Measures].[MEASURE_NONEMPTY]} ON 0,
[Dim Gender].[Gender Name].[Gender Name].ALLMEMBERS
* [Dim Age Ranges].[Age Range ID].[Age Range ID].ALLMEMBERS
ON 1
FROM [People Dashboard]
WHERE [Dim Location].[Location].[Location Grp Name].&[BOSTON]
;