OLAP: MDX Examples
Problem 1: Displaying Information About Members
We want on row per quarter, but for each quarter, we also want to display the corresponding year. Here an example with an output where we do the same thing on the column axis with the Region dimension (displaying both the State and City):
Solution 1.1: Displaying Information in Cells
It is not possible to add have tuples with two members from the same dimension (here: Year and Quarter are both from the Time dimension), so one alternative is to display the year in a cell instead.
with
member Measures.Year as 'time.currentmember.parent.name'
select
{ Measures.Year, [Measures].[Store Sales] } on columns,
[Time].[Quarter].members on rows
from Sales
And here we have a more complex but realistic example using the same method.
with
member Measures.Year as 'time.currentmember.parent.name'
member Measures.Quarter as 'time.currentmember.name'
select
{
{ ( [Store].[All Store], Measures.Year ) } ,
{ ( [Store].[All Store], Measures.Quarter ) } ,
CrossJoin( { [Store].[Store Country].members } , {Measures.[Store Sales] })
} on columns,
[Time].[Quarter].members on rows
from Sales
Solution 1.2: CrossJoin with Duplicate Dimension
Here we create an additionnal dimension [Year] with the years as members. We CrossJoin [Year] with [Time] and then Join the two dimensions.
select
{ [Measures].[Store Sale] } on columns,
Filter (
CrossJoin(
{ [Year].members },
{ [Time].[Quarter].members }
),
[Year].currentmember.name =
Ancestor([Time].currentmember, [Time].[Year]).name
) on rows
from [Sales]
Problem 2: Output in a Cell a Combination of Values
In this example below we display in each cell the "sale"value along the percentage it represents across all regions, displayed in parenthesis. We do this with the non-standard Format() function.
with
member [Measures].[Sale] as '
Format([Region].currentmember, "$#,### ") ||
Format([Region].currentmember /
[Region].currentmember.parent, "(0%)")
'
select
{ [Period].[Period's Year].members } on columns,
{ [Region].[All Regions].children } on rows
from [Sales]
where ( [Measures].[Sale] )
Problem 3: Output in a Cell Different Values Depending on Some Condition
In the example below we add a tag around the value along with the "number of units sold"if the "sale"value is below a certain threshold:
with
member [Measures].[Sale] as 'Iif (
[Measures].[Total Price] > 1000000,
Format([Measures].[Total Price], "$#,###"),
"" ||
(Format([Measures].[Total Price], "$#,###") ||
("
Units: " ||
(Format([Measures].[Total Units], "#,###"))))
)'
select
{ [Period].[Period's Year].members } on columns,
{ [Region].[All Regions].children } on rows
from [Forecast]
where ( [Measures].[Sale] )
References
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C에서 파일 입/출력저장 및 , 우리는 파일 유형을 가리키는 구조 포인터를 사용합니다 - FILE. fopen() 함수는 기존 파일을 열거나 새 파일을 만드는 데 사용됩니다. 여기서 fp는 열린(또는 생성된) 파일에 대한 참조를 보유할...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.