WHERE clause in calculated member

泪湿孤枕 提交于 2020-01-02 07:25:11

问题


I am facing some problem to calculate values from comparing dimension's value. I have 3 dimensions (Datatype, Customer, Product) and one measure (GrossSales).

What would be the MDX query if I want GrossSales for ProductID = 1,2,3 and Dataype = 4,5,6?

Here Datatype has relationship with GrossSales, Customer has relationship with GrossSales and Product has relationship with Customer.

I am trying this but doesn't work

CREATE MEMBER CURRENTCUBE.[Measures].Forecast_Gross_Sales AS 
( 
    SELECT NON Empty [Measures].[Gross Sale] 
    FROM [Measures] 
    WHERE (
        [Data Type].[ID].[ID] = 4 
        AND [Chain].[Customer ID] = [Measures].[Customer ID]
    ) 
), VISIBLE = 1 
, DISPLAY_FOLDER = 'Forecast' 
, ASSOCIATED_MEASURE_GROUP = 'Data Types';

回答1:


It looks like you are just getting started with MDX. There are some fundamental concepts that will help you get what you need. This comparison of SQL and MDX might be helpful. MDX uses the where clause as a slicer (to select certain dimension members) rather than a filter. You can't put member = somevalue in the where clause. And you can't really use the where clause to define a relationship to some other table.

Instead, your where clause would be something more like

[Data Type].[ID].[ID].&[4]

Since I can't see your data model, I can't be sure, but I would guess that [Chain].[Customer ID] = [Measures].[Customer ID] is something that you want to define the the dimension usage of your cube rather than in the query.

Edit: Now that the question has been edited, it looks like you are creating a calculated member. in this case there is no select or where clause. It will look more like this:

CREATE MEMBER CURRENTCUBE.[Measures].Forecast_Gross_Sales AS 
Aggregate([Data Type].[ID].[ID].&[4], [Measures].[Gross Sale])
, VISIBLE = 1 
, DISPLAY_FOLDER = 'Forecast' 
, ASSOCIATED_MEASURE_GROUP = 'Data Types';

The relationship from the measure group through the Customer dimension to the Chain dimension is something that should be defined in the dimension usage. This is called a Reference dimension relationship.



来源:https://stackoverflow.com/questions/19635584/where-clause-in-calculated-member

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!