我有一个CustomerToFactor作为度量,客户作为一个维度。现在,我想创建一个类似于这个SQL代码的MDX代码,但是我做不到。因为(WITH)语句在MDX中有另一个含义。
with Total_Customer(
select cus_id
,sum(ctf_price) cus_total_price
from dbo.Customer
join dbo.CustomertoFactor on cus_id = ctf_cus_id
group by cus_id
)
select cus_id
,cus_name
,ctf_date
,ctf_price
,(cus_total_price / 100 * ctf_price) as Price_pro_customer
from dbo.Customer
join dbo.CustomertoFactor on cus_id = ctf_cus_id
join Total_Customer on Total_customer.cus_id = dbo.Customer.cus_id
SELECT NON EMPTY { [Measures].[ctf_date]
,[Measures].[ctf_price]
, (?) Price_pro_customer
} ON COLUMNS
,NON EMPTY {[Customer].[Customer - cus_name].[Customer - cus_name].ALLMEMBERS}
FROM [CustomerToFactor] 谢谢你的回答。但不起作用。实际上,我希望它按你命名的每一个名字分组。例如:对于Alex名称,只需要计算Alex(100+300 = 400)和Group的总和。

发布于 2018-03-09 16:17:29
我并不真正理解计算的意义:)但是无论如何,在MDX中,您可以像这样计算自己的度量:
WITH MEMBER [Measures].[Price_pro_customer] AS
(SUM([Measures].[ctf_price]) / 100 * [Measures].[ctf_price])
SELECT NON EMPTY { [Measures].[ctf_date]
,[Measures].[ctf_price]
,[Measures].[Price_pro_customer]
} ON COLUMNS
,NON EMPTY {[Customer].[Customer - cus_name].[Customer - cus_name].ALLMEMBERS}
FROM [CustomerToFactor]不过,我不确定您是否会得到与SQL查询相同的结果,因为行上有Customer.Customer - cus_name.Customer - cus_name.ALLMEMBERS,基本上是根据客户名称进行分组的。
因此,如果表中有相同客户的几行,则MDX查询的输出应为每个客户1行。和(Measures.ctf_price)也是不同的,因为它与所有客户相加。
发布于 2018-03-13 02:43:03
我认为您应该创建一个对ctf_date的日期维度引用。那么mdx应该如下所示:
WITH MEMBER [Measures].[Price_pro_customer] AS
SUM([DimDate].[ctf_date].[All], [Measures].[ctf_price]) / 100 * [Measures].[ctf_price]
SELECT NON EMPTY {
[Measures].[ctf_price] ,
[Measures].[Price_pro_customer]
} ON COLUMNS ,
NON EMPTY {[Customer].[Customer - cus_name].[Customer - cus_name].ALLMEMBERS *
[DimDate].[ctf_date].[ctf_date].ALLMEMBERS} ON ROWS
FROM [CustomerToFactor] https://stackoverflow.com/questions/49194625
复制相似问题