0

我正在尝试使用计算成员构建带有参数的查询。

我已经为“硬编码”的司法计数创建了计算成员,并且我创建的参数不会影响每个组的总数。

但是,我需要使用工作参数列出每个总计数。如果所选司法类型没有值,则应显示零计数。

我确定有一个简单的方法,但我对 MDX/SSRS 相当陌生。任何帮助是极大的赞赏!

这是查询:

WITH 

Member  [Measures].[Jud] as
        (
        [Dim Foreclosure Loan].[Judicial Flag].[1],
        [Dim Foreclosure Loan].[FCL Stage].&[Sale Held],
        [Measures].[Loan Count]
        )
Member  [Measures].[Non-Jud] as
        (
        [Dim Foreclosure Loan].[Judicial Flag].[0],
        [Dim Foreclosure Loan].[FCL Stage].&[Sale Held],
        [Measures].[Loan Count]
        )
Member  [Measures].[Total] as
        (
        [Dim Foreclosure Loan].[Judicial Flag],
        [Dim Foreclosure Loan].[FCL Stage].&[Sale Held],
        [Measures].[Loan Count]
        )
--------------------------------    Query Begins    --------------------------------
SELECT NON EMPTY
        {
        ([Dim Date].[Calendar].[Day].Members)
        } ON ROWS,
        NON EMPTY 
        ({
        ([Measures].[Jud]),
        ([Measures].[Non-Jud]),
        ([Measures].[Total])
        }) ON COLUMNS
        FROM ( SELECT ( STRTOSET(@DimForeclosureLoanJudicialFlag, CONSTRAINED) ) ON COLUMNS
        FROM [Foreclosure])
        WHERE 
        (IIF( STRTOSET(@DimForeclosureLoanJudicialFlag, CONSTRAINED).Count = 1,
        STRTOSET(@DimForeclosureLoanJudicialFlag, CONSTRAINED),
        [Dim Foreclosure Loan].[Judicial Flag].currentmember)
        )CELL PROPERTIES VALUE

更新:需要有关提供的 iif 语句的帮助;请参阅下面的评论。

4

1 回答 1

0

我不是 100% 清楚你在问什么,但如果我要重申它,我认为这就是你想要做的。我想你想在列上看到 Jud、Non-Jud 和 Total。我认为您正在尝试使用该参数来选择特定的司法标志。不清楚的是参数值是否限制为 1 和 2,如您为度量显示的那样,或者是否存在一个层次结构,其中 1 和 2 有子级。我将假设第一个,因为它最简单解释一下,我们可以从那里开始。

您需要为司法标志 1 和 2 设置措施以考虑WHERE条款中的内容。现在它们是硬编码的,这告诉 SSAS 忽略WHERE子句中的任何内容。您需要通过IIF在 Measure 定义中包含一个语句来有条件地使用它。您应该返回一个NULL值作为 False 条件,以便 SSAS 可以以最佳方式执行查询,然后使用 format_string 属性填充零来代替NULL(这比在 False 条件中使用 0 来提高性能)。但是,您NON EMPTY在列上的关键字将消除该WHERE子句中未包含的司法标志,因此您需要将其删除。将其保留在行上,以便仅显示具有 Jud 或 Non-Jud 值的日期。

根据我对您要执行的操作的猜测,这是对您的查询的尝试:

WITH 
  MEMBER [Measures].[Jud] AS 
  iif(
        [Dim Foreclosure Loan].[Judicial Flag].CurrentMember is 
            [Dim Foreclosure Loan].[Judicial Flag].[1], 
            (
              [Dim Foreclosure Loan].[Judicial Flag].[1]
             ,[Dim Foreclosure Loan].[FCL Stage].&[Sale Held]
             ,[Measures].[Loan Count]
            ),
            NULL), format_string="#;#;0;0"
  MEMBER [Measures].[Non-Jud] AS 
  iif(
        [Dim Foreclosure Loan].[Judicial Flag].CurrentMember is 
            [Dim Foreclosure Loan].[Judicial Flag].[0], 
            (
              [Dim Foreclosure Loan].[Judicial Flag].[0]
             ,[Dim Foreclosure Loan].[FCL Stage].&[Sale Held]
             ,[Measures].[Loan Count]
            ),
            NULL), format_string="#;#;0;0" 
  MEMBER [Measures].[Total] AS 
    (
      [Dim Foreclosure Loan].[Judicial Flag]
     ,[Dim Foreclosure Loan].[FCL Stage].&[Sale Held]
     ,[Measures].[Loan Count]
    ) 
SELECT 
  NON EMPTY 
    {
      [Dim Date].[Calendar].[Day].MEMBERS
    } ON ROWS
 , 
    {
      [Measures].[Jud]
     ,[Measures].[Non-Jud]
     ,[Measures].[Total]
    } ON COLUMNS
FROM 
(
  SELECT 
    StrToSet
    (@DimForeclosureLoanJudicialFlag
     ,CONSTRAINED
    ) ON COLUMNS
  FROM [Foreclosure]
)
WHERE 
  IIF
  (
      StrToSet
      (@DimForeclosureLoanJudicialFlag
       ,CONSTRAINED
      ).Count
    = 1
   ,StrToSet
    (@DimForeclosureLoanJudicialFlag
     ,CONSTRAINED
    )
   ,[Dim Foreclosure Loan].[Judicial Flag].CurrentMember
  )
CELL PROPERTIES VALUE, FORMATTED_VALUE;
于 2012-05-28T21:38:03.603 回答