【问题标题】:python olap.xmla mdx queries returning single value?python olap.xmla mdx 查询返回单个值?
【发布时间】:2023-03-29 16:50:01
【问题描述】:

我总是在使用 python 的 MDX 查询中得到一个值。我正在连接到支持 xmla 的 icCube。

provider = xmla.XMLAProvider()
con = provider.connect(location='conn_str',username='q1',password='q2')
cmd="""WITH MEMBER Measures.[Avg Profit Margin] AS Sum(SOMETHING,    Measures.[Profit Margin]) select NON EMPTY {[Measures].[Profit Margin]} ON columns, {[Client Country]} ON rows FROM [XYZ]"""

res=con.Execute(cmd,Catalog="cube_closed_contracts")
print res.getSlice()

为什么总是返回一个值?

[[(Cell){
     _CellOrdinal = "0"
     Value = 0.0358054
     FmtValue = "3.58%"
   }]]

【问题讨论】:

    标签: python olap xmla iccube


    【解决方案1】:

    您确定 MDX 查询会返回多个单元格吗?

    WITH MEMBER Measures.[Avg Profit Margin] AS ... 
    select 
          NON EMPTY {[Measures].[Profit Margin]} ON columns, 
          {[Client Country]} ON rows 
    FROM [XYZ]
    

    “[Client Country] on rows” 表示 [Client Country] 的默认成员,因此我相信这将返回单个单元格结果。我会在 icCube MDX 编辑器中尝试该请求。

    希望对您有所帮助。

    【讨论】:

    • 感谢您的建议。我能够在 MDX 编辑器中修改查询和测试。我仍然不知道为什么 python xmla 包不从 res 对象返回列名。在 iccube 中,我可以输入 mdx 查询并获得一个带有列名等格式的表格。在 python 界面中,它只是值。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-21
    • 2020-05-06
    • 1970-01-01
    • 2016-10-08
    相关资源
    最近更新 更多