问题
I stumbled upon a problem which I cannot resolve. For my academical project I have a cube representing an airline's data warehouse. In this airline, passengers fill out a qustionnaire with 5 questions, rating various aspects of the flight from 1 to 10
I was asked to write an MDX
query to show how their overall grade of the flight (average of five grades) depending on the class they were in.
This is my query:
WITH
MEMBER [Average Grade1] AS
[Measures].[Grade1] / [Measures].[Flight Count]
MEMBER [Average Grade2] AS
[Measures].[Grade2] / [Measures].[Flight Count]
MEMBER [Average Grade3] AS
[Measures].[Grade3] / [Measures].[Flight Count]
MEMBER [Average Grade4] AS
[Measures].[Grade4] / [Measures].[Flight Count]
MEMBER [Average Grade5] AS
[Measures].[Grade5] / [Measures].[Flight Count]
MEMBER [Average] AS
(
[Measures].[Average Grade1] + [Measures].[Average Grade2]
+
[Measures].[Average Grade3]
+
[Measures].[Average Grade4]
+
[Measures].[Average Grade5]
)
/ 5
SELECT
{
[Measures].[Average Grade1]
,[Measures].[Average Grade2]
,[Measures].[Average Grade3]
,[Measures].[Average Grade4]
,[Measures].[Average Grade5]
,[Measures].[Average]
} ON COLUMNS
,{[Junk].[Class].Children} ON ROWS
FROM [Airline];
It gives wrong results because the average is counted before the actual grouping by class that's why the same result is shown for all classes. Can anyone tell me how to get the result I want?
回答1:
As mmarie mentions this would usually be the way to get an average:
WITH
MEMBER [Average Grade1] AS
[Measures].[Grade1] / [Measures].[Flight Count]
MEMBER [Average Grade2] AS
[Measures].[Grade2] / [Measures].[Flight Count]
MEMBER [Average Grade3] AS
[Measures].[Grade3] / [Measures].[Flight Count]
MEMBER [Average Grade4] AS
[Measures].[Grade4] / [Measures].[Flight Count]
MEMBER [Average Grade5] AS
[Measures].[Grade5] / [Measures].[Flight Count]
MEMBER [Average] AS
(
[Measures].[Grade1] + [Measures].[Grade2]
+
[Measures].[Grade3]
+
[Measures].[Grade4]
+
[Measures].[Grade5]
)
/ [Measures].[Flight Count]
SELECT
{
[Measures].[Average Grade1]
,[Measures].[Average Grade2]
,[Measures].[Average Grade3]
,[Measures].[Average Grade4]
,[Measures].[Average Grade5]
,[Measures].[Average]
} ON COLUMNS
,{[Junk].[Class].Children} ON ROWS
FROM [Airline];
If a measure is not connected to the context of an MDX
script then you get repetition of the answer. So if the measures you are using are not connected to the context i.e. [Junk].[Class].Children
then you will be getting repetition based on default member evaluation.
Try swapping out [Junk].[Class].Children
for a different dimension that you know is 100% related to the measures [Measures].[Grade1]
and [Measures].[Flight Count]
来源:https://stackoverflow.com/questions/27532854/mdx-average-function-counting-on