mdx组按度量值范围

时间:2015-05-11 13:11:26

标签: group-by range mdx measures

我正在寻找按度量值创建组的方法。 我有一个维度的立方体,包括尺寸,客户,供应商......以及更多尺寸。 我想创建一个查询,该查询必须返回按总金额范围和包含每个组的供应商数量分组的供应商。

我创建了一个查询,为每个供应商返回他的范围总金额,即一个如下:

WITH
    MEMBER [Measures].[Range1] as fix([Measures].[Total Amount]/1000)*1000, FORMAT_STRING = "###############0"
    MEMBER [Measures].[Range2] as fix([Measures].[Total Amount]/1000 + 1 )*1000 - 1, FORMAT_STRING = "###############0"

    MEMBER [Measures].[MyRange] AS 
        iif([Measures].[Total Amount] >= 0,
            Cast([Measures].[Range1] as string) ||" - "||  Cast([Measures].[Range2] as string), 
            NULL)

   SET supli AS
       Order(filter([Supplier].[Supplier].Members,[Measures].[Total Amount] >= 0),
             [Measures].[Total Amount],BASC)

    MEMBER [Measures].[rank] AS 
        iif([Measures].[Total Amount] >= 0, 
            rank([Supplier].[Supplier].currentMember,supli), 
            NULL), FORMAT_STRING = "#####0"

    MEMBER [Supplier].[Range] as Aggregate([Measures].[Range1]:[Measures].[Range2])

SELECT 
    {[Measures].[Total Amount],[Measures].[MyRange], [Measures].[rank], [Measures].[Range1], [Measures].[Range2]}  on 0,
    NON EMPTY (supli)   on 1

FROM [Detail Booking]
WHERE {[Checkin Date.Date].[2015]}

结果如下:

Proveedor    Importe              MyRange             rank          Range1      Range2
P1             0               0.0 - 999.0              1             0          999
P2            100              0.0 - 999.0              2             0          999
P3           618,27            1000.0 - 1999.0          3            1000        1999
P4           855               1000.0 - 1999.0          4            1000        1999
P5           3819,5            4000.0 - 4999.0          5            4000        4999
P6           11669,23         12000.0 - 12999.0         6            12000      12999
P7           12000            12000.0 - 12999.0         7            12000      12999
P8          14805,49          15000.0 - 15999.0         8            15000      15999
P9          16784,4           17000.0 - 17999.0         9            17000      17999
P10          46967,7          47000.0 - 47999.0        10            47000      47999

大约有500家供应商,我不知道有多少范围或存在多少范围

我需要查询返回如下结果:

 Proveedor                count(supplier)
 0.0 - 999.0                    2
 1000.0 - 1999.0                2
 4000.0 - 4999.0                1
 12000.0 - 12999.0              2
 15000.0 - 15999.0              1
 17000.0 - 17999.0              1
 47000.0 - 47999.0              1     

我的问题是我不知道如何使用动态聚合创建查询

我知道我可以使用以下内容进行汇总:

WITH
MEMBER [Measures].[0:1000] as 
    Count(
        Filter({[Supplier].[Supplier].CurrentMember}, 
            [Measures].[Total Amount] < 1000), 
        EXCLUDEEMPTY)
MEMBER [Supplier].[Supplier].[0€-1000€] as Aggregate({[Supplier].[Supplier].Members},[Measures].[0:1000])

MEMBER [Measures].[1000:2000] as 
    Count(
        Filter({[Supplier].[Supplier].CurrentMember}, 
            [Measures].[Total Amount] >= 1000 and [Measures].[Total Amount] < 2000), 
        EXCLUDEEMPTY)
MEMBER [Supplier].[Supplier].[1000€-2000€] as Aggregate({[Supplier].[Supplier].Members}, [Measures].[1000:2000])

member [Measures].[Total proveedores] as [Measures].[Total Amount], FORMAT_STRING ="####0"

SELECT
NON EMPTY {[Measures].[Total proveedores]} ON 0,
NON EMPTY {[Supplier].[0€-1000€], [Supplier].[1000€-2000€]} ON 1 
FROM [Detail Booking]
WHERE {[Checkin Date.Date].[2015]}

我的问题是:大约有500家供应商,我不知道有多少范围或者使用过滤器有多大范围

有人知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

你可以在这里找到详细的解释 https://sqlmdx.net/2021/02/02/group-by-an-expression-and-limitations-mdx-vs-sql/

长话短说 - 不可能在 MDX 中向某个维度添加未知数量的成员来做到这一点既简单又好,但是有一些替代方法而不改变多维数据集设计。