使用 MDX 查询在多维数据集中查找数据类型的度量

Find data type of measures in Cube using MDX queries

我正在处理 SSAS MDX 查询。现在我需要从 MDX 查询中识别每一列的数据类型。我已经尝试过如下。

WITH MEMBER PageSize AS 1  Member [Measures].[My Type] as TypeName([Measures].[Budget Delivered COGS])

但它 returns 对于货币字段是两倍。首先,Cubes 的数据类型是货币,百分比吗?

如果不是,有什么方法可以查明该列是货币还是百分比还是双精度还是整数?

我看过这个postFind the data type。但这对于货币和百分比是不可行的。

我在这里粘贴我的整个查询。

 WITH MEMBER PageSize AS
  1
MEMBER [Measures].[My Type] AS
  TypeName ( [Measures].[Budget Delivered COGS] )
MEMBER [PageNumber] AS
  1
MEMBER [Measures].[Orderby Measure] AS
  [Measures].[Budget Delivered COGS]
MEMBER [Orderby] AS
  "BASC"
SET ROWAXISWOF AS
  NonEmpty (
    ( [Time Periods].[Fiscal Year].[Fiscal Year].Members, [Time Periods].[Fiscal Quarter].[Fiscal Quarter].Members, [Time Periods].[Fiscal Month].[Fiscal Month].Members, [Time Periods].[Fiscal Week].[Fiscal Week].Members ),
    {
      { [Measures].[Budget Delivered COGS] },
      { [Measures].[Break Even Delivered] }
    }
  )
SET ROWAXISWF AS
  Filter ( ROWAXISWOF, [Measures].[Budget Delivered COGS] )
SET ROWAXIS AS
  IIf ( 'Filter' = "NotFilter", ROWAXISWF, ROWAXISWOF )
MEMBER [Measures].[MaxRowCount] AS
  ROWAXIS .Count
SET ROWAXIS_Count AS
  IIf (
    'Paging' = "Paging",
    (
    CASE
    WHEN [Orderby] = 'BASC'
    THEN Tail (
      TopCount ( ROWAXIS, PageSize * PageNumber, [Measures].[Orderby Measure] ),
      PageSize
    )
    ELSE Tail (
      BottomCount ( ROWAXIS, PageSize * PageNumber, [Measures].[Orderby Measure] ),
      PageSize
    ) END ),
    ROWAXISWOF
  )
SELECT ( IIf (
  'Paging' = "Paging",
  (
  { [Measures].[Budget Delivered COGS], [Measures].[Break Even Delivered], [Measures].[MaxRowCount], [Measures].[My Type] } ),
  { [Measures].[Budget Delivered COGS], [Measures].[Break Even Delivered], [Measures].[My Type] }
) ) ON COLUMNS,
ROWAXIS_Count ON ROWS
FROM (
  SELECT (
  { [Time Periods].[Fiscal Year].&[2011], [Time Periods].[Fiscal Year].&[2012], [Time Periods].[Fiscal Year].&[2013], [Time Periods].[Fiscal Year].&[2014], [Time Periods].[Fiscal Year].&[2015] } ) ON COLUMNS
  FROM [Homestore Sales]
)

如果我们在查询中获取数据,我将循环遍历该列并在 C# 中查找。任何帮助深表感谢。提前致谢。

如果您谈论的是物理度量,那么您可以在 SSAS 项目中的 SSDT-BI 中查看度量类型。或者您可以使用以下 SSAS 存储过程批量导出它,您可以安装 here:

CALL ASSP.discoverXmlMetaData("\Database\Cubes\Cube\MeasureGroups\MeasureGroup|Name\Measures\Measure");

计算的措施比较棘手。由于计算中的 IIF 语句和范围语句,CalculatedMeasure1 可能在一个单元格中为 Double 类型,而在另一个单元格中为 String 类型。您可以 运行 查询并返回 CellSet,然后查看每个单独单元格的类型,我认为它应该告诉您类型。但我不确定这对你有什么好处,因为即使在相同的计算度量中,类型也可能因单元格而异。

也许您想为计算的度量检索 FORMAT_STRING 属性?这可能表明会发生什么。在生成的 CellSet 中,您将能够从每个单元格中检索 FORMAT_STRING 属性。

select {[Measures].[Budget Delivered COGS], [Measures].[Break Even Delivered]} on 0
FROM [Homestore Sales]
PROPERTIES VALUE, FORMAT_STRING

最后一种方法是查询 MDSCHEMA_MEASURES DMV,如果您想假设每个度量对立方体中的所有单元格都具有相同的格式字符串。它有一个 DEFAULT_FORMAT_STRING 列。您可以使用针对 SSAS 的 SQL 查询来调用它,例如:

select * from $system.mdschema_measures

或者您可以通过 ADOMD.NET 调用它,代码如下:

AdomdRestrictionCollection restrictions = new AdomdRestrictionCollection();
restrictions.Add(new AdomdRestriction("CATALOG_NAME", cube.ParentConnection.Database));
restrictions.Add(new AdomdRestriction("CUBE_NAME", cube.Name));
System.Data.DataTable tblExactMatchMembers = conn.GetSchemaDataSet("MDSCHEMA_MEASURES", restrictions).Tables[0];

如果这不能回答您的问题,您可以提供更多背景知识。