MDX return fiscal PriorMTD date as value - attributes

I am trying to create MDX Calculated member which returns prior mtd date.
This is Calculated member I've created:
CREATE MEMBER CURRENTCUBE.[Measures].PriorMTDDate
AS cousin(
[Date].[Fiscal].CurrentMember,
[Date].[Fiscal].CurrentMember.parent.parent.lag(1)
),
VISIBLE = 1 ;
And this is query, but it returns just null:
select {[Measures].[PriorMTDDate]} on 0
from [WH_Cube]
WHERE ( [Date].[Fiscal].[Date].&[2014-09-12T00:00:00] )
Any idea what am I doing wrong?
EDIT: Another example returning null:
WITH MEMBER Measures.x AS
[Date].[Fiscal].CurrentMember
SELECT Measures.x ON 0
FROM [WH_Cube]
WHERE ( [Date].[Fiscal].[Date].&[2014-09-30T00:00:00] )

Does a measure need to be a numeric value?:
CREATE MEMBER CURRENTCUBE.[Measures].PriorMTDDate
AS cousin(
[Date].[Fiscal].CurrentMember,
[Date].[Fiscal].CurrentMember.parent.parent.lag(1)
).MemberValue ,
VISIBLE = 1 ;

.CurrentMember is evaluated at the row level, doesn't look into the slicer. The slicer is a global restriction on the cube, providing a sub-cube domain for your query.
In your query, [Date].[Fiscal].CurrentMember is underfined, as there is nothing on the Rows clause.
Try
select {[Measures].[PriorMTDDate]} on 0,
[Date].[Fiscal].[Date].&[2014-09-12T00:00:00] on 1
from [WH_Cube]

Related

MDX - rewrite a query using scope

I have an MDX query
IIF
(
IsLeaf([PnL].[PnL_A].CurrentMember)
,
[Measures].[PnL - Plan] * [PnL].[Flag 5].CurrentMember.MemberValue
,Sum
(
[PnL].[PnL_A].CurrentMember.Children
,[Measures].[PnL- Plan (signed)]
)
)
What it does:
The whole thing represents profit and loss. Unfortunately, it is constructed in a way that there are two columns: value of a profit or loss, and flag in the other column.
So if the flag ([PnL].[Flag 5]) is set to -1, the value ([Measures].[PnL - Plan]) is a loss, if the flag is a 1 - the value is a profit. I can't change that.
The query finds leaves of the hierarchy (single deepest source of a profit or loss) and multiplies the flag with the value. For non-leaf members it just aggregates it's leaves.
My problem is that it works too slow - I wanted to rewrite this query using SCOPE but I have no idea how.
Since I have absolutely no idea on your cube structure, let's say your member structure is
Pnl-->Pnl_A-->NonLeaf-->Leaf
You could define scope as below -
CREATE MEMBER CurrentCube.[Measures].[ProfitOrLossValue] AS NULL;
//Current member is leaf and Flag5 is 1
SCOPE
(
[Measures].[ProfitOrLossValue],
[PnL].[Flag 5].&[1],
[PnL].[PnL_A].[Leaf].[All].CHILDREN
);
This = [Measures].[PnL - Plan];
END SCOPE;
SCOPE
(
[Measures].[ProfitOrLossValue],
[PnL].[Flag 5].&[-1],
[PnL].[PnL_A].[Leaf].[All].CHILDREN
);
This = ([Measures].[PnL - Plan] * -1);
END SCOPE;
//Current member is non-leaf
SCOPE
(
[Measures].[ProfitOrLossValue],
[PnL].[PnL_A].[NonLeaf].[All].CHILDREN
);
This = Sum
(
[PnL].[PnL_A].CurrentMember.Children,
[Measures].[PnL- Plan (signed)]
);
END SCOPE;
Hope it helps.

MDX Calculated Member displays no value in Excel but same query works in SSMS

I have a calculated member (not measure) of a dimension, which works in SSMS, but doesn't work in Excel 2013.
I've followed the advice described in this question on how to create calculated members.
So I have a new attribute in my lottery dimension called 'Relative Lotteries' with a single member 'All Lotteries in Scope' defined through the DSV.
I have a calculated member like this:
CREATE MEMBER CURRENTCUBE.[Lottery].[Relative Lotteries].[All].[This Lottery]
AS NULL, VISIBLE = 1;
Then a SCOPE Statement like this:
SCOPE ([Lottery].[Relative Lotteries].[All].[This Lottery]
,[Lottery].[Lottery Number].members);
THIS = 10000;--([Lottery].[Lottery Number].currentmember,measures.currentMember);
END SCOPE;
I've tried loads of combinations of SCOPE and THIS = , most of which work through SSMS but none work through Excel 2013.
I used OLAP extensions to get the MDX script generated by Excel 2013, The MDX is:
SELECT
{ [Measures].[Response - Sale Amt], [Measures].[Response - Qty of Orders] } DIMENSION PROPERTIES PARENT_UNIQUE_NAME
, HIERARCHY_UNIQUE_NAME ON COLUMNS
, NON EMPTY Hierarchize (
{
DrilldownLevel (
{ [Lottery].[Relative Lotteries].[All] }
,
,
, INCLUDE_CALC_MEMBERS
)
}
) DIMENSION PROPERTIES PARENT_UNIQUE_NAME
, HIERARCHY_UNIQUE_NAME ON ROWS
FROM [Lottery]
WHERE ( [Lottery].[Lottery Number].&[141] ) CELL PROPERTIES VALUE
, FORMAT_STRING
, LANGUAGE
, BACK_COLOR
, FORE_COLOR
Through SSMS this query yields the expected result:
But through Excel 2013, I get this result:
The only thing I can think of is that its something to do with the Excel connection string. However its difficult to test. Excel won't let me remove or add any properties, it just returns the connection string back to how it was before editing. My Excel Connection string is:
Provider=MSOLAP.6;Integrated Security=SSPI;Persist Security Info=True;Initial Catalog=Cube_Name;Data Source=ServerName;MDX Compatibility=1;Safety Options=2;MDX Missing Member Mode=Error
I've been banging my head against a brick wall trying to work this out. Any ideas ???

SSAS How to scope a calculated member measure to a number of specific members?

I'm trying to create a calculated member measure for a subset of a group of locations. All other members should be null. I can limit the scope but then in the client (excel in this case) the measure does not present the grand total ([Group].[Group].[All]).
CREATE MEMBER CURRENTCUBE.[Measures].[Calculated Measure]
AS (
Null
),
FORMAT_STRING = "$#,##0.00;-$#,##0.00",
NON_EMPTY_BEHAVIOR = { [Measures].[Places] }
,VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Locations';
-----------------------------------------------------------------------------------------
SCOPE ({([Group].[Group].&[location 1]),
([Group].[Group].&[location 2]),
([Group].[Group].&[location 3]),
([Group].[Group].&[location 4]),
([Group].[Group].&[location 5])
}, [Measures].[Calculated Measure]);
// Location Calculations
THIS = (
[Measures].[Adjusted Dollars] - [Measures].[Adjusted Dollars by Component] + [Measures].[Adjusted OS Dollars]
);
END SCOPE;
It's as though the [Group].[Group].[All] member is outside of the scope so it won't aggregate the rest of the members. Any help would be appreciated.
Your calculation is applied after all calculations already happened. You can get around this by adding Root([Time]) to the scope, assuming your time dimension is named [Time]. And if you want to aggregate across more dimensions, you would have to add them all to the SCOPE.
In most cases when you have a calculation that you want too do before aggregation it is more easy to define the calculation e. g. in the DSV, e. g. with an expression like
CASE WHEN group_location in(1, 2, 3, 4) THEN
Adjusted_dollars - adjusted_dollars_by_comp + adjusted_os_dollars
ELSE NULL
END
and just make a standard aggregatable measure from it.
I've searched high and low for this answer. After reading the above suggestion, I came up with this:
Calculate the measure in a column in the source view table
(isnull(a,0) - isnull(b,0)) + isnull(c,0) = x
Add the unfiltered calculated column (x) to the dsv
Create a named calculation in the dsv that uses a case statement to filter the original calc measure CASE WHEN location IN ( 1,2,3)THEN xELSE NULLEND
Add the named calculation as measure
I choose to do it this way to capture the measure unfiltered first then, if another filter needs to be added or one needs to be taken off, I can do so without messing with the views again. I just add the new member to filter by to my named calculation case statement. I tried to insert the calculation directly into a named calculation in the dsv that filtered it as well but the calculation produced the incorrect results.

Using TopCount in MDX query

I'm trying to select the top 10 of a specified data set for use in a report. However, I'm not sure where it would go in the query. My current MDX query is below and mostly resembles what is automatically generated by the designer. What I'm trying to get is the top 10 Subcontractors by the value of Revised Value. Currently when I try to run this I get the error "Error running the data source query"
SELECT
TopCount([Dim Subcontractor].[Subcontractor Name].[Subcontractor Name].ALLMEMBERS, 10, [Measures].[Revised Value]),
{ [Dim Subcontractor].[Subcontractor Name].[Subcontractor Name].ALLMEMBERS }
ON COLUMNS,
{ [Measures].[Revised Value] }
ON ROWS
FROM [BGDEMO]
WHERE ( [Dim Project].[Project Name].DEFAULTMEMBER, [Dim Date].[Full Date].DEFAULTMEMBER )
CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, FONT_FLAGS, FORE_COLOR, BACK_COLOR
Any help with this is appreciated.
Figured it out. I'll post it here in case others might find it useful:
SELECT
{ TOPCOUNT([Dim Subcontractor].[Subcontractor Name].[Subcontractor Name],10, [Measures].[Revised Value]) }
ON COLUMNS,
{ [Measures].[Revised Value] }
ON ROWS
FROM [BGDEMO]
WHERE ( [Dim Project].[Project Name].DEFAULTMEMBER, [Dim Date].[Full Date].DEFAULTMEMBER )
CELL PROPERTIES VALUE, FORMATTED_VALUE, CELL_ORDINAL, FONT_FLAGS, FORE_COLOR, BACK_COLOR

How to filter using calculated date value based on parameter in MDX

I'm trying to fetch the values based on a Date value passed as parameter (named AsOnDate) into a Performance Point report's MDX from a Webpart Date Filter. It's an Accounts database and the scenario is to fetch the Dormant accounts data. The problem I'm facing is that I need to fetch the Accounts having Dormant Date till 6 months before the AsOnDate value, i.e. AsOnDate -6 months, I managed to calculate the 6 month old date using DateAdd() function, like following:
DateAdd('m', -6, DateValue('<<AsOnDate>>'))
Now, I cann't figure out how to pass this value in place of the paramter in WHERE clause, MDX query looks like:
WITH
SET [Products] AS { <<Product>> }
MEMBER [Measures].[Dormant A/C Count] AS ([Measures].[Account Head Count])
MEMBER [Measures].[Dormant A/C Vol.] AS ([Measures].[LC Balance])
MEMBER [AH].[Subhead - Description].[Totals] AS Aggregate([Products])
SELECT
{ [Measures].[Dormant A/C Count], [Measures].[Dormant A/C Vol.]}
ON COLUMNS,
{[Products], [AH].[Subhead - Description].[Totals]}
ON ROWS
FROM
[MyCUbe]
WHERE (
[AH].[Is Dormant].&[1],
[AH].[Is Inoperative].&[0],
{NULL : [AH].[Dormant Date].&[ DateAdd('m', -6, DateValue('<<AsOnDate>>')) ]}
)
I get this error:
Error running data source query.
The 'DateAdd('m', -6, DateValue('2012-12-03'))'
string cannot be converted to the date type.
I have tried StrToMember() like:
WHERE (
[AH].[Is Dormant].&[1], [AH].[Is Inoperative].&[0],
{ NULL : StrToMember("[AH].[Dormant Date].&["+DateAdd('m', -6, DateValue('<<AsOnDate>>'))+"]")}
)
However, passing the Date Filter value directly as following works fine:
WHERE ( [AH].[Is Dormant].&[1], [AH].[Is Inoperative].&[0],
{ NULL : [AH].[Dormant Date].&[<<AsOnDate>>T00:00:00]} )
Figured it out, after some hit n trials.. managed to hack a combination of StrToMember() and Format() to convert calculated Date into string and feed it into MDX as Member, here's the working WHERE clause:
WHERE ( [AH].[Is Dormant].&[1], [AH].[Is Inoperative].&[0],
{ NULL : StrToMember("[AH].[Dormant Date].&[" + Format(DateAdd('m', -6, DateValue('<<AsOnDate>>')), 'yyyy-MM-dd') + "T00:00:00]") } )
Hope it will prove helpful for someone out there..

Resources