无法用MDX查询中的某个值正确乘以度量值成员

无法用MDX查询中的某个值正确乘以度量值成员,mdx,Mdx,我有一个查询,显示一些商品的价格: member Measures.[Price] as ([Goods].[Good].Properties( "Base price" )), format_string = "0.000" member Measures.[Control] as [Goods].[Good].Properties( "IsControlled" ) select {(Measures.[Price]),Measures.[Control]} on columns, ...

我有一个查询,显示一些商品的价格:

member Measures.[Price] as ([Goods].[Good].Properties( "Base price" )),
format_string = "0.000"
member Measures.[Control] as [Goods].[Good].Properties( "IsControlled" )
select 
{(Measures.[Price]),Measures.[Control]} on columns, ...//select goods on rows.
结果如下:

Price  Controll

172,19 not
193,54 not
172,57 not
326,49 not
438,77 not
139,25 not
72,11  controlled
165,76 controlled
233,32 not
655,05 not
607,58 not
201,92 not
126,2  not
现在,我编写了第二个查询,由于某些原因,该查询不正确,我不知道如何修复它。 以下是查询:

member Measures.[Control] as [Goods].[Good].Properties( "IsControlled" )
member Measures.[Price] as 
CASE Measures.[Control] 
WHEN 'Controlled' THEN [Goods].[Good].Properties( "Base price" )
ELSE ([Goods].[Good].Properties( "Base price" )*0.0095)
END
select {Measures.[Price]}
问题在于,对于包含5个数字的价格,乘法是正确的,但如果价格包含4个数字,则乘法是错误的。 结果:


最后的价格应该是119.89而不是11.989。我需要得到基本价格的95%。如何正确地做到这一点?

因此,我尝试以不同的方式进行此查询,并找到了一些解决方案,这对我的情况很有帮助。问题出在点后的不同位数。。例如,172.19的95%为172.19*0.0095,但126.2的95%为126.2*0.095。不知道为什么,但在我的MDX查询中,它是这样计算的。我在这个解决方案中使用了VisualBasic函数。下面是我的解决方案:后圆点只能是1位或2位

member Measures.[FixedPrice] as [Goods].[Good].Properties( "Base price" )
member Measures.[Digits] as vba!Len(Right(Measures.[FixedPrice], Len(Measures.[FixedPrice]) - InStr(1, Measures.[FixedPrice], ",")))
member Measures.[Control] as [Goods].[Good].Properties( "IsControlled" )
member Measures.[Price] as 
iif(Measures.[Control] <> 'Controlled' and Measures.[Digits]<2 ,Measures.[FixedPrice]*0.095,
iif(Measures.[Control] <> 'Controlled' and Measures.[Digits]>1,Measures.[FixedPrice]*0.0095,Measures.[FixedPrice]))
, format_string = '#,#0.00'
select {Measures.[Цена]}
结果我所有的货物都有95%的正确价格。所有的时间都在使用SQL和T-SQL。MDX multiply的工作原理也是如此。

在处理非字符串属性时,您可能希望使用TYPED:

WITH member Measures.[Control] as [Goods].[Good].Properties( "IsControlled" )
member Measures.[Price] as 
CASE Measures.[Control] 
WHEN 'Controlled' THEN [Goods].[Good].Properties( "Base price", TYPED )
ELSE ([Goods].[Good].Properties( "Base price", TYPED )*0.0095)
END
select {Measures.[Price]} ON COLUMNS
FROM [your cube]

如果不使用类型化属性,则返回转换为字符串的结果。如果使用TYPED,则获得的数据类型与关系数据的原始列中的数据类型相同。有关详细信息,请参阅。

首先:您要乘以0.0095?不应该是0.95吗?第二:它是受控的还是受控的?在您的第一个示例中,它是小写的。我是从另一种语言翻译查询,而不是小写的。这是我在AnalysisServer172.19*0.95=16358.05中看到的乘以的结果;172.19*0.095 = 1,635.81; 172.19*0.0095 = 163.58. 它已经磨损了,但它是这样工作的。也许只是在我本地的机器上,没有尝试其他地方。谢谢。我甚至想不出不同的类型。我不明白它是如何工作的172.19string*0.0095double,float=163.58-这里应该是类型验证。你的解应该像乘法一样工作172.19*0.95=163.58。
WITH member Measures.[Control] as [Goods].[Good].Properties( "IsControlled" )
member Measures.[Price] as 
CASE Measures.[Control] 
WHEN 'Controlled' THEN [Goods].[Good].Properties( "Base price", TYPED )
ELSE ([Goods].[Good].Properties( "Base price", TYPED )*0.0095)
END
select {Measures.[Price]} ON COLUMNS
FROM [your cube]