MDX - Query Attribute in the CrossJoin - Essbase - mdx

I currently have a CrossJoin working for UDA. However we want to change to using Attribute value instead. Not sure how to get the Syntax correct to use Attribute in the CrossJoin in Essbase. I commented out the UDA part which works great. However the Attribute part isn't working. Appreciate any guidance.
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
CrossJoin(
{[AC_910006]},
{[EN_TotBevEMEAElim]}),
/*
{UDA([Customer].CurrentMember,\"EUR_Intra\")}),
*/
{Filter(Descendants([CU_Intra],Levels([Customer],0)),
[Customer].CurrentMember.[IntraCoCust] = \"EUR_Intra\")}),
{Descendants([Orig_Entity],Levels([Orig_Entity],0))}),
{Descendants([Total_Sizes],Levels([Size],0))}),
{Descendants([Total_Types],Levels([Type],0))}),
{[FC],[EUR],[USD]}),
{[FY22]}),
{[Jul]:[Dec]})"

If I'm reading it correctly try
Withattr ( [Customer], "==", "EUR_Intra" )
and for more than one attribute you can use the Intersect command.
Intersect ( Withattr ( [Customer], "==", "EUR_Intra" ), Withattr ( [Customer], "==", "EUR_Extra" ) )
Here is a helpful link: https://docs.oracle.com/cd/E57185_01/ESBTR/mdx_withattr.html
Steve

Related

MDX currentMember get me error

This MDX function raise error :
with member measures.x as
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].[Date].currentmember.value
,
[Measures].[current balance]
)
select measures.x on columns,
[Branch].[HeadOffice Branch].[Head Office Code] on rows
from MyCube
Error is :
The CURRENTMEMBER function expects a hierarchy expression for the 1 argument. A member expression was used.
But when I use
[Date].[Date].[Date].&[20160101] : [Date].[Date].[Date].&[20160131]
It works good
why?
This is valid mdx:
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
Although this is not:
WITH member measures.x AS
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
,
[Measures].[current balance]
)
It is not valid because round braces (...) signify a tuple but a tuple requires exact co-ordinates so the first argument cannot be a set.
You could add an aggregation such as SUM:
WITH member measures.x AS
SUM
(
[Date].[Date].[Date].&[20160101] : [Date].[Date].currentmember
,
[Measures].[current balance]
)
This is valid mdx but if you do not have [Date].[Date] in context i.e. in the WHERE or SELECT clause then all it is returning is the All member.
Why are you using [Date].[Date].currentmember ?
CURRENTMEMBER works on an attribute hierarchy (in your case [Date].[Date]). So [Date].[Date].CURRENTMEMBER will work.
Also you will need to take out the value selector, as your expression returns a set of dates (member : member returns a set of all the members between those two members).

MDX, Remove Zero-Rows On ROWS

My MDX-Query looks like this:
WITH
MEMBER [YEAR].[A2014_1-12] AS
([YEAR].[2014], [TYPE].[ACTUAL]),
MEMBER [YEAR].[P2014_1-12] AS
([YEAR].[2014], [TYPE].[PLAN]),
MEMBER [YEAR].[P2015_1-12] AS
([YEAR].[2015], [TYPE].[PLAN]),
MEMBER [YEAR].[A2015_YTD] AS
SUM(
{[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
,(
[Measures].currentmember
,[TYPE].[ACTUAL]
)
)
SELECT
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12],
[YEAR].[P2015_1-12],
[YEAR].[A2015_YTD]
}
ON COLUMNS,
NON EMPTY
[COST_CENTER]
*[COST_ELEMENT] ON ROWS
FROM [CUBE]
WHERE ([Measures].[COSTS]);
The Query itself is working. However it is also returning a lot of zero-rows and I would like to get rid of these zero-rows. The strange thing is - If I put only one MEMBER (e.g. [YEAR].[A2014_1-12]) on the COLUMNS-axis it is not returning any zero-rows. But as soon as I start to add another MEMBER to the COLUMN-axis it is also many returning zero-rows (It seems like it is ignoring the NON EMPTY in my CROSSJOIN). How can I remove the zero-rows in the above MDX-Query?
Try this as a start
WITH
MEMBER [YEAR].[A2014_1-12] AS
iif(
([YEAR].[2014], [TYPE].[ACTUAL]) = 0
,null
,([YEAR].[2014], [TYPE].[ACTUAL])
)
MEMBER [YEAR].[P2014_1-12] AS
iif(
([YEAR].[2014], [TYPE].[PLAN]) = 0
,null
,([YEAR].[2014], [TYPE].[PLAN])
)
SELECT
NON EMPTY
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12]
}
ON COLUMNS,
NON EMPTY
[COST_CENTER]
*[COST_ELEMENT] ON ROWS
FROM [CUBE]
WHERE ([Measures].[COSTS]);
As an aside you do not need to define the current member of the measures hierarchy in this definition:
MEMBER [YEAR].[A2015_YTD] AS
SUM(
{[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
,(
[Measures].currentmember
,[TYPE].[ACTUAL]
)
)
This is enough:
MEMBER [YEAR].[A2015_YTD] AS
SUM(
{[YEARPERIOD].[201501]:[YEARPERIOD].[201509]}
,([TYPE].[ACTUAL])
)
Try this instead:
WITH
MEMBER [YEAR].[A2014_1-12] AS
iif(
([YEAR].[2014], [TYPE].[ACTUAL]) = 0
,null
,([YEAR].[2014], [TYPE].[ACTUAL])
)
MEMBER [YEAR].[P2014_1-12] AS
iif(
([YEAR].[2014], [TYPE].[PLAN]) = 0
,null
,([YEAR].[2014], [TYPE].[PLAN])
)
SET [X] AS
NonEmtpy(
[COST_CENTER]*[COST_ELEMENT],
{[YEAR].[A2014_1-12],[YEAR].[P2014_1-12]}
)
SELECT
NON EMPTY
{
[YEAR].[A2014_1-12],
[YEAR].[P2014_1-12]
}
ON 0,
//NON EMPTY
[X] ON 1
FROM [CUBE]
WHERE ([Measures].[COSTS]);

How to build a dynamic MDX formula for a calculated member?

I am trying to create a Calculated Member to get a sum up to last week.
No problem to get the week value (I need it to be two digits i.e. '05', so adding 100-1 )
with
Member [Measures].Week as
'right(str(int(99+datepart ( ''ww'', Now()))),2)'
-- That works as expected
member [Measures].SalesUpToWeek as
'strtomember(
"aggregate(periodstodate([Dim].[2015],[Dim].[2015].[" + ([Measures].Week) + "]),[Measures].[Sales])")'
I get the literal value
aggregate(
periodstodate([Dim].[2015],[Dim].[2015].[25])
,[Measures].[Sales]
)
What I need is the value of this MDX calculation.
All other attempts end up with a syntax error. Just as an example
member [Measures].SumToWeek as
'aggregate(
periodstodate(
[Dim].[2015],[Dim].[2015].[' + strtomember([Measures].Week) + '])
,[Measures].[Sales])'
Error
Lexical error at line 2, column 0. Encountered: after : "[\n"
Any idea?
[Measures].Week is already a string entity. You don't need to put StrToMember around it. Instead you should have it outside the string you dynamically defined.
with
Member [Measures].Week as
"right(str(int(99+datepart ( ''ww'', Now()))),2)"
member [Measures].SumToWeek as
aggregate(
periodstodate(
[Dim].[2015],
StrToMember("[Dim].[2015].[" + [Measures].Week + "]")
)
,
[Measures].[Sales]
)
This is your error:
strtomember([Measures].Week)
Let us say that [Measures].Week is equal to 15 then you are trying to do this:
strtomember(15)
So there are two errors in the above:
You're feeding a numeric into a functions that converts Strings to Memebers
You need to feed in the full string representation of the member i.e."[Dim].[2015].[15]"
Maybe try putting the strToMember function around the string that is the representation of the member:
MEMBER[Measures].SumToWeek AS
'aggregate(
periodstodate(
[Dim].[2015],
strtomember('[Dim].[2015].[' + [Measures].Week + ']', constrained)
)
,[Measures].[Sales])'
Here is the MSDN reference for the function strtomember:
https://msdn.microsoft.com/en-us/library/ms146022.aspx?f=255&MSPPError=-2147217396
Edit
Looking at this previous post: (StrToMember does not accept calculated measure (mdx))
...you need to create the member before feeding it into the new measure, so:
WITH
MEMBER [Measures].[Week] AS
Right
(
Str(Int(99 + Datepart('ww',Now())))
,2
)
MEMBER [Dim].[2015].[TargetWeek] AS
StrToMember
(
'[Dim].[2015].[' + [Measures].Week + ']'
,constrained
)
MEMBER [Measures].SumToWeek AS
Aggregate
(
PeriodsToDate
(
[Dim].[2015]
,[Dim].[2015].[TargetWeek]
)
,[Measures].[Sales]
)
Edit2
Ok if you wish to use PeriodsToDate then we need to use StrToSet and then use the member in this set inside the function. This is because custom members lose their family ties and are therefore useless inside some mdx functions.
Here is a working script in AdvWrks illustrating the approach I'm suggesting:
WITH
MEMBER [Measures].[Wk] AS
Right
(
Str(Int(99 + Datepart('ww',Now())))
,2
)
SET [TargetWeek] AS
StrToSet
(
'[Date].[Calendar Weeks].[Calendar Week].[Week ' + cstr([Measures].[Wk]) + ' CY 2007]'
)
MEMBER [Measures].[SumToWeek] AS
Aggregate
(
PeriodsToDate
(
[Date].[Calendar Weeks].[Calendar Year]
,[TargetWeek].item(0).item(0)
)
,([Measures].[Internet Sales Amount])
)
SELECT
{[Measures].[SumToWeek]} ON 0,
[Product].[Product Categories].[All] ON 1
FROM [Adventure Works];
I got an interesting suggestion on Pentaho forums that pointed me to a nice blog post which allowed to write an elegant solution:
http://diethardsteiner.blogspot.com.es/2009/10/current-date-function-on-mondrian.html
with
member [Measures].sm as aggregate(
periodstodate(
currentdatemember([Dim],'["Dim"]\.[yyyy]'), -- current year
currentdatemember([Dim],'["Dim"]\.[yyyy]\.[ww]').lag(1) -- previous week
),
[Measures].[Sales])
Thks

MDX with IIF parameter

I'm tyring to discern an amount based on a parameter. I currently have the #ClientType defaulted to 'C'.
WITH
MEMBER
[Measures].[Amount] AS
IIF(
#ClientType ='C',
[Measures].[Total Client Amount] ,
-[Measures].[Total Client Amount]
)
Regardless of changing the #ClientType I'm still only returning the FALSE.
Try adding in these two measures inspect their values:
WITH
MEMBER [Measures].[ClntTypParam] AS #ClientType
MEMBER [Measures].[ClntTypParamC] AS
IIF (
#ClientType = "c"
,"equalToC"
,"notC"
)

MDX CREATE MEMBER SYNTAX ERROR?

I'm very new to MDX, so sorry if this is a stupid question.
I'm creating a new calculated member
I'm getting a syntax error on Line 2 "AS SELECT NON EMPTY"?
CREATE MEMBER CURRENTCUBE.[Measures].FCR
AS SELECT NON EMPTY { [Measures].[Total Incident Count] } ON COLUMNS
FROM ( SELECT ( { [DIM INCIDENT].[First Call Resolution].&[Yes] } ) ON COLUMNS
FROM [ITSM Incident DM])
WHERE ( [DIM INCIDENT].[First Call Resolution].&[Yes] ),
FORMAT_STRING = "Standard",
VISIBLE = 1 ;
Thanks in advance for any assistance.
You cannot put a Select statement in the expression of a calculated member.
You can fine more information on this MSDN page.