MDX Scope Assignment returns same value - scope

I have some MDX in my SSAS cube something like:
CREATE MEMBER CURRENTCUBE.[Measures].[xx] AS 1;
SCOPE ([Measures].[xx]);
SCOPE ([Measures].[xx], [DimA].[DimA Hierarchy].Members);
This= 20;
END SCOPE;
SCOPE ([Measures].[xx], [DimB].[DimB Hierarchy].Members);
This= 2;
END SCOPE;
END SCOPE;
Browsing the cube and selecting the [xx] measure always returns 2, no matter if I use the DimA, DimB or no dimensions at all.
If I swap the order of the inner scope declrations, (ie DimB's scope before DimA's) I get 20 no matter what.
Clearly I'm doing something wrong??

SCOPE only makes sense if you use it on a subset of the members of a hierarchy.
[DimB].[DimB Hierarchy].Members and [DimA].[DimA Hierarchy].Members have no effect in scope, as they refer to all members of the hierarchy. Hence, one of these is always the current member, and the last scope always is used. Except you define a calculated member on that hierarchy, and it is the current member.
You probably want at least to exclude the All member, so that the SCOPE is only used for other members that this member, which is by default the current member if you do not use the hierarchy at all. In case DimA Hierarchy is an attribute hierarchy and not a user hierarchy, you can use [DimA].[DimA Hierarchy].[DimA Hierarchy].Members to get the members of the DimA Hierarchy level, which are all members except the All member.

Try something like this:
CREATE MEMBER CURRENTCUBE.[Measures].[xx] AS 1;
SCOPE ([Measures].[xx]);
SCOPE ([DimA].[DimA Hierarchy].Members);
This= 20;
END SCOPE;
SCOPE ([DimB].[DimB Hierarchy].Members);
This= 2;
END SCOPE;
END SCOPE;

Related

Variables. scope inside of a cfmodule

I have a page with a name of
summary.cfm
inside of it:
<cfinclude template="view/totals.cfm>
view/totals.cfm
inside of it:
variables.grandTotalHTML = invoke("viewtotals, "doSummary", {...});
view/viewtotals.cfc
inside of it
<cfmodule template="summarytemplate.cfm" ...>
<!--- database is not passed in here --->
view/summarytemplate.cfm
Inside of it we have
param attributes.database = session.database;
...
databaseoverride = attributes.database;
...
<cfquery name="qData">
SELECT *
FROM [#variables.databaseoverride#]
...
</cfquery>
Now question
I don't know where the databaseoverride is coming from.
Does global page request scope?
Does it come from variables in viewtotals.cfc ?
Does the unscoped version override it?
The variables scope at the module level is local to the module. An unscoped variable in a module is in variables scope.
This line
databaseoverride = attributes.database;
is equivalent to
variables.databaseoverride = attributes.database;
so is setting the value used here
<cfquery name="qData">
SELECT *
FROM [#variables.databaseoverride#]
...
</cfquery>
(Too long for comments)
Just to elaborate on Dan's answer:
summary.cfm
Only shares a VARIABLES scope with the included template, "view/totals.cfm"
view/totals.cfm
Only shares a VARIABLES scope with the parent template, "summary.cfm"
view/viewTotals.cfc
Its VARIABLES scope is not shared with any of the calling templates (summary.cfm and view/totals.cfm)
Its VARIABLES are accessible to the cfmodule - through the CALLER scope (as are the function's local and arguments scopes)
view/summaryTemplate.cfm
Does not share its VARIABLES scope with anyone.
Can view/modify any scopes in the parent component (viewTotals.cfc) through the CALLER scope.
( The REQUEST scope is accessible to all of the scripts above.)

SSAS Cube calculation Scope with criteria

I need your help with a scope definition where the Goal is to create (in this case) a site = "TAI API", that is the aggregation of two other sites
"CPH API" + "US API" where product
in ([Product].[Manufacturing Family].&[BANT],[Product].[Manufacturing Family].&[BZNT],[Product].[Manufacturing Family].&[VANT]))
What I have done is creating the site as follow:
CREATE MEMBER CURRENTCUBE.[Order Company Group].[Parent].[All].[TAI API]
as [Order Company Group].[Parent].&[10440 - API]+[Order Company Group].[Parent].&[10240 - API]
, VISIBLE = 1 ;
Then I would like to define a scope for this site "TAI API", so that it works for any measure, but I am unsure what the next step is... I have tried something like this, but it doesn't work as intended:
SCOPE ([Order Company Group].[Parent].[All].[TAI API] ) ;<br/>
this = ([Measures].??<br/>
,([Product].[Manufacturing Family].&[BANT],[Product].[Manufacturing Family].&[BZNT],[Product].[Manufacturing Family].&[VANT]));<br/><br/>
END SCOPE;
The [Measures].?? is to indicate that I am not sure if this is needed or what to write...
Turns out I can do something like this
CREATE MEMBER CURRENTCUBE.[Order Company Group].[Parent].[All].[TAI API]
as [Order Company Group].[Parent].&[10440 - API]+[Order Company Group].[Parent].&[10240 - API]
, VISIBLE = 1 ;<br/><br/>
SCOPE ([Order Company Group].[Parent].[All].[TAI API]);<br/>
SCOPE([Product].[Manufacturing Family].[Manufacturing Family].members
- [Product].[Manufacturing Family].&[BANT]
- [Product].[Manufacturing Family].&[BZNT]
- [Product].[Manufacturing Family].&[VANT]
);<br/>
this = null;
<br/>
END SCOPE;
<br/><br/>
END SCOPE;
Thanks Thomas
You can use scope w/o any measures references:
At the very beginning (I just used my own DB with sample on standard Year-Month-Day dimension):
CREATE MEMBER CURRENTCUBE.[Create Date].[Create Date].[Month].&[201402].[20140200]
AS null,
VISIBLE = 1 , ASSOCIATED_MEASURE_GROUP = 'Data' ;
And than scope at the end:
SCOPE ([Create Date].[Create Date].[Month].&[201402].[20140200]);
THIS = SUM({[Create Date].[Create Date].[Day].&[20140214],[Create Date].[Create Date].[Day].&[20140228]});
END SCOPE;
This will work even with calculated measures with Descendants (e.g. ...Exists(Descendants([Create Date].[Create Date].[Year].&[2014],[Create Date].[Create Date].[Month],SELF_BEFORE_AFTER)...)
Please see this image. Is it expected result?
If so, you can just set first time NULL to this new member. And that in scope write
SUM([Order Company Group].[Parent].&[10440 - API],[Order Company Group].[Parent].&[10240 - API])
Hope it helps.

Initialize class reference

I get null value of instrumentRented
when I run
public class RentalAgreement
{
private MusicalInstrument instrumentRented;
public RentalAgreement(Customer renter,
RentalDate dateRented,
MusicalInstrument instrumentRented){
customer = renter;
rentalDate = dateRented;
instrumentRented = instrumentRented;
How to initialize MusicalInstrument reference in RentalAgreement?
Use this.instrumentRented = instrumentRented;
Since the parameter has the same name as the field attribute, you need to prefix with an explicit this to specify the scope.
You must instantiate a class with the new operator.
So somehwere in your code must do
instrumentRented = new MusicalInstrument();
before you access it. After you have done this you can execute functions from that class.
instrumentRented.doSomething();
In the above code you seem to pass it in in the constructor, so this means the caller has to instantiate it.
However I would advise to adopt a naming convention where you can see if a variable is a class member or a local variable. In your above code the local variable has the same name as the parameter, so it will not be set as a member variable, instead you assign it to itself. You might get a warning about this, depending on the evironment (Not sure about this but Eclipse definitely warns somethign like this). This is called shadowing, so what you need to do is:
this.instrumentRented = instrumentRented;

MDX Scope overwriting value

I am trying to overwrite the value of the member [Balance to Total] in two attributes using SCOPE. However, when I view the results in Excel they both have a value of 4. Why aren't they showing different values?
SCOPE ([Measures].allmembers);
[Group].[Attribute1].&[Balance to Total] = 2;
[Group].[Attribute2].&[Balance to Total] = 4;
END SCOPE;
I think that the FREEZE function solves my problem.

How do I get the value in a sessionScope variable within an appendItemValue call

I created a sessionScope variable that hold a list of field names and another set that are made up of those field names and the values that are stored in them.
allFieldNames is the scope variable that contains all the field name
allFieldNames
[0] T0Q1
[1] T0Q2
[2] T1Q1
[3] T2Q1
[4] T3Q1
[5] T4aQ1
[6] T5Q1
[7] T6Q1
[8] T7Q1
SS Value
T0Q1 As a part of an acquiring/purchasing/merging with another company.
T0Q2 Yes
T1Q1 Strongly agree
T2Q1 Agree
T3Q1 I have an extensive active network of experts and resources.
T4aQ1 I sometimes require assistance
T5Q1 None of these.
T6Q1 To a reasonable extent
T7Q1 Agree
var questions = #List(sessionScope.allFieldNames);
for( i=1; i < sessionScope.ssTotalQuestions; i++ ) {
viewScope.put("x", #Subset(#Subset(questions,i),-1));
newDoc.appendItemValue(x, viewScope.x);
}
The appendItemValue does create the field as I wanted but the problem I am having is that I cannot get the values in the matching scope variable. I know it is viewScope.x in my code that is causing the problem, but I cannot figure out how to identify and reference the scope variable at this point.
FYI, there is no back end form to grab these field names from - this form is created on the fly, all fields are created on the form through this routine and it is then saved.
This should work:
for( i=1; i < sessionScope.ssTotalQuestions; i++ ) {
newDoc.replaceItemValue(sessionScope.allFieldNames[i], sessionScope.ssTotalQuestions[i]);
}
(If the field-name is part of your data, you might need to use indexOf(" ") to find the first blank). However it is a bit fragile... you have name/value pairs here, so you might want to replace your two scope variables with one HashMap, so you can be sure you never run out of fields for your questions. Something like:
viewScope.questions = new java.util.HashMap();
viewScope.questions.put("T0Q1","As a part of an acquiring/purchasing/merging with another company.");
...
Hope that helps

Resources