SSAS MDX计算

时间:2018-12-28 15:13:55

标签: ssas mdx

我需要一个计算量度(SSAS MD)来计算计数值的百分比。

我尝试过以下表达式,但没有得到想要的输出。让我知道是否遗漏了什么,我想通过汽车总数计算出该年龄段的百分比:

    ( [DimCar].[Car], [DimAge].[Age], [Measure].[Count])/ 
sum([DimCar].[Car].[All].children), ([DimAge].[Age].[All], [Meaures].[Count])}*100

以下是多维数据集中的样本日期值:

Car     Age   Count
-----  -----  -----
Benz     1      2
Camry           37
Honda    1      18
Honda    6      10

Expected output:


Car    Age    Count Percent  TotalCount 
----- -----  ----- ------ ---------- 
Benz   1       2   100%       2   
Camry         37   100%       37    
Honda  1      18   64.28%     28    
Honda  6      10   35.71%     28    



   
 论坛计算百分比:

18/28*100 =64.28% 
10/28*100 =35.71%   

Honda  1  18   64.28%  28    
Honda  6  10   35.71%  28 

2 个答案:

答案 0 :(得分:1)

我的理解是,对于本田的特定汽车示例,您希望将其除以本田的总面积,而与它们的年龄无关。在本例中为28。因此对于Age:6本田,您使用10/28。至于奔驰车,因为所有奔驰车的年龄都是:1,所以您使用2。 使用以下代码

 Round(
(
    ( [DimCar].[Car].currentmember, [DimAge].[Age].currentmember, [Measure].[Count])
    / 
    ([DimCar].[Car].currentmember,root([DimAge]),[Measure].[Count])
    )*100
,2)

以下是关于冒险作品的类似示例

with member 
measures.t as 
(
( [Product].[Category].currentmember, [Delivery Date].[Calendar Year].currentmember, [Measures].[Internet Order Quantity])
/ 
([Product].[Category].currentmember,root([Delivery Date]),[Measures].[Internet Order Quantity])
)*100
select {[Measures].[Internet Order Quantity],measures.t} 
on columns ,

non empty
([Product].[Category].[Category],[Delivery Date].[Calendar Year].[Calendar Year])
on rows 
from [Adventure Works]

enter image description here

答案 1 :(得分:1)

with Member  [Measures].[Total Sales Count] 
as iif (isempty([Measures].[Sales]),NUll, sum([Model].[Modelname].[All].children ,[Measures].[Sales]))

Member [Measures].[Total Sales%]
as ([Measures].[Sales]/[Measures].[Total Sales Count]),FORMAT_STRING = "Percent"

select {[Measures].[Sales],[Measures].[Total Sales Count],[Measures].[Total Sales%]
}on 0
,non empty{[Car].[Carname].[Carname]*[Model].[Modelname].[Modelname]} on 1
from [Cube]

Output :

Car     Model     Sales	 Total Sales Count	 Total Sales%
Benz	 New Model	  2	    2	                  100.00%
Camry	 Old Model	 37	    37	                100.00%
Honda	 New Model	 18	    28	                 64.29%
Honda	 Top Model	 10	    28	                 35.71%

我添加了“模型”维度而不是“年龄”属性。 下面的代码获得预期的准确输出。

enter image description here