0
votes

I need a calculated measure(SSAS MD) to calculate the percentage of count values.

I have tried below expression but I did not get the desired output.Let me know if I missing anything and I want to calculate the percentage of the age for the group by the car total:

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

Below are the sample date values in cube:

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    



   
Forumula to calculate percentage:
18/28*100 =64.28% 
10/28*100 =35.71%   

Honda  1  18   64.28%  28    
Honda  6  10   35.71%  28 
2
And what is your question?Robert
I need the calculation expression for the desired outputKusu
I have tried below expression but i did not get the desired output.Let me know if i missing anything and i want to calculate the percentage of the age for the group by the car total.. ( [DimCar].[Car], [DimAge].[Age], [Measure].[Count])/ sum([DimCar].[Car].[All].children), ([DimAge].[Age].[All], [Meaures].[Count])}*100Kusu

2 Answers

1
votes

My understanding is that for a particular car example honda, you want to divide by the total honda's irrespective of their Age. In this case 28. So for Age:six honda you use 10/28. Where as for Benz, since all Benz are Age: 1 you use 2. Use the following code

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

Below is a similar example on adventure works

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
votes

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%

Instead of "Age" attribute I have added "Model" dimension. Below code get exact output which is expected.

enter image description here