用于计算所有商品体积 (%ACV) 的 MDX 公式
MDX formula for calculating All-Commodity Volume (%ACV)
我想为全商品交易量 (ACV) 指标创建一个度量。公式如下:
销售产品的经销商的总销售额/所有经销商的总销售额
举个例子,比如AdventureWorks2012DW Cube的产品"LL Touring Frame - Blue, 44"。
我们可以看到它被 14 个经销商出售
这 14 家经销商合计创造了 2 706 909 美元的销售额
如果我考虑所有经销商,他们的销售额为 80 450 596 美元
我的 ACV 指标 return 2 607 909 / 80 450 596 = 产品 "LL Touring Frame - Blue, 44" 的 2%,这意味着它出现在经销商那里,他们占我间接销售额的 2%。
我正在寻找的是 MDX 表达式,它采用 "Reseller Sales Amount for all products" 而不是所选产品的经销商销售额,但前提是 "Reseller Sales Amount of the selected product is not null"。
到目前为止,感谢社区的帮助,如果我过滤某些特定产品,我可以进行查询并得到正确的结果:
WITH SET ActiveStores As NonEmpty(
[DimStore].[商店].[商店]
, { ([DimProduct].[Product].CurrentMember, [Measures].[Sales])}
)
MEMBER ACV AS SUM(ActiveStores, [Measures].[Store Sales]) / [Measures].[Store Sales]
SELECT 列上的非空 ACV,
非空 { ([DimProduct].[Product].[Product].ALLMEMBERS ) } ON ROWS
FROM ( SELECT ( { [DimProduct].[Product].&[ HAMAC DE VOYAGE] } ) ON COLUMNS FROM [Cube])
此查询 return过滤后产品的 ACV 为 9%。但是,如果我通过仅放置 FROM [Cube] 来删除过滤器,则所有产品的 ACV 都会变为 100%,即使是上一个查询为 9% 的产品。
这就像 ActiveStores 集绑定了 WHERE 子句而不是 ROWS 轴。
此致
要查找 Sales 不为空的成员,您可以使用 NonEmpty
函数:
NonEmpty(
[Stores].[Stores].members
,(
[Product].[Product].[ProductA]
, [Measures].[Sales]
)
)
怎么样:
Sum(
[Store].[Store].[Store].Members,
IIF(
IsEmpty([Measures].[Sales]),
Null,
(
ROOT([Product])
,ROOT([Supplier])
,ROOT([Promotion])
,ROOT([Misc])
,[Measures].[Sales]
)
)
)
我可以通过这种方式找到解决方案:
我添加了一个聚合事实(商店销售)作为维度商店的属性。从中创建一个 Measure Store Sales,然后使用以下表达式创建一个计算度量:
SUM(NonEmpty(
[DimStore].[Store].[Store]
,([Measures].[Sales])
), [Measures].[Store Sales]) / (ROOT([DimStore]), [Measures].[Store Sales])
我想为全商品交易量 (ACV) 指标创建一个度量。公式如下:
销售产品的经销商的总销售额/所有经销商的总销售额
举个例子,比如AdventureWorks2012DW Cube的产品"LL Touring Frame - Blue, 44"。
我们可以看到它被 14 个经销商出售
这 14 家经销商合计创造了 2 706 909 美元的销售额
如果我考虑所有经销商,他们的销售额为 80 450 596 美元
我的 ACV 指标 return 2 607 909 / 80 450 596 = 产品 "LL Touring Frame - Blue, 44" 的 2%,这意味着它出现在经销商那里,他们占我间接销售额的 2%。
我正在寻找的是 MDX 表达式,它采用 "Reseller Sales Amount for all products" 而不是所选产品的经销商销售额,但前提是 "Reseller Sales Amount of the selected product is not null"。
到目前为止,感谢社区的帮助,如果我过滤某些特定产品,我可以进行查询并得到正确的结果:
WITH SET ActiveStores As NonEmpty( [DimStore].[商店].[商店] , { ([DimProduct].[Product].CurrentMember, [Measures].[Sales])} )
MEMBER ACV AS SUM(ActiveStores, [Measures].[Store Sales]) / [Measures].[Store Sales]
SELECT 列上的非空 ACV, 非空 { ([DimProduct].[Product].[Product].ALLMEMBERS ) } ON ROWS FROM ( SELECT ( { [DimProduct].[Product].&[ HAMAC DE VOYAGE] } ) ON COLUMNS FROM [Cube])
此查询 return过滤后产品的 ACV 为 9%。但是,如果我通过仅放置 FROM [Cube] 来删除过滤器,则所有产品的 ACV 都会变为 100%,即使是上一个查询为 9% 的产品。
这就像 ActiveStores 集绑定了 WHERE 子句而不是 ROWS 轴。
此致
要查找 Sales 不为空的成员,您可以使用 NonEmpty
函数:
NonEmpty(
[Stores].[Stores].members
,(
[Product].[Product].[ProductA]
, [Measures].[Sales]
)
)
怎么样:
Sum(
[Store].[Store].[Store].Members,
IIF(
IsEmpty([Measures].[Sales]),
Null,
(
ROOT([Product])
,ROOT([Supplier])
,ROOT([Promotion])
,ROOT([Misc])
,[Measures].[Sales]
)
)
)
我可以通过这种方式找到解决方案:
我添加了一个聚合事实(商店销售)作为维度商店的属性。从中创建一个 Measure Store Sales,然后使用以下表达式创建一个计算度量:
SUM(NonEmpty(
[DimStore].[Store].[Store]
,([Measures].[Sales])
), [Measures].[Store Sales]) / (ROOT([DimStore]), [Measures].[Store Sales])