.Currentmember in a named set - ssas

I believe that due to the processing order of an analysis services script using context driven functions such as currentmember within a custom set is pointless i.e. the set is evaluated before the processor knows what the currentmember actually is.
Are there any exceptions to the above rule? i.e. what is an example of using the currentmember function within a custom set?

Depending on what you mean by "within a custom set", Currentmember may have its uses. I assume here you meant the usage in the definition expression of the set.
Query level sets take into account the WHERE condition, which may set one or more CurrentMembers.
Cube level named sets may be defined as dynamic since version 2008, hence the same behavior is true.
While you can use CurrentMember in the iteration over a set that Filter and Generate do, you can also use a set alias and the Current property, which I find more clear:
Generate([Customer].[Country].[Country].Members as c,
c.Current.Name,
', '
)
or
Filter([Customer].[Country].[Country].Members as c,
InStr(c.Current.Name, 'a') > 0
)
which could have been written
Generate([Customer].[Country].[Country].Members,
[Customer].[Country].CurrentMember.Name,
', '
)
and
Filter([Customer].[Country].[Country].Members,
InStr([Customer].[Country].CurrentMember.Name, 'a') > 0
)
as well.
Please note that the second case does not deal with the usage of CurrentMember in the definiton of the set that you iterate over, but in the definition of the String or set that results from the Generate or Filter expression.

Related

Check if an item exists in MDX named set

I want to create a named set for two football teams. I'm not exactly sure what the syntax is, but what I have thus far is:
EXISTS(
[Team].[Team],
{[Team].[Team].&[BAL], [Team].[Team].&[DEN]}
)
In other words, I want to create a Named set if the team is named "BAL" or "DEN". What would be the proper way to write this expresion?
The following query syntax works for me, but I'd like to translate this into "creating a named set" in BIDS:
WITH SET[FavoriteTeams] AS{
[Team].[Team].&[DEN],
[Team].[Team].&[BAL]
}
SELECT
[Measures].[Net Wins] on 0,
[FavoriteTeams] on 1
FROM [NFL]
It seems perhaps it is as simple as just typing that in manually to the expression?
Sets are an important concept in MDX. A set is a collection of members from the same dimension and hierarchy. The hierarchy can be an attribute hierarchy or a user-defined hierarchy.
set = {membre1,member 2 ..}
the simpler the set expression the better it is.
So you should use the second expression
{
[Team].[Team].&[DEN],
[Team].[Team].&[BAL]
}
In your case no need to use the exists function since the members are defined.
we use exists in some setuations like we want to get all the cities of a specific region.
EXISTS([City].[City], [region].[region].[Region].&[1])
Visit : Microsoft.doc

Execute SQL Task -Full Result Set Datatype Mismatch Error

I am creating an SSIS package which has an execute SQL task and it passes result set variable to a for each loop container.
My Sql Query is:
Select distinct code from house where active=1 and campus='W'
I want the execute sql task to run this query and assign its results to a variable which is passed to a for each loop container which should loop through all the values in the result set.
But my execute sql task fails with error:
The type of the value (DBNull) being assigned to variable
"User::house" differs from the current variable type (String)
Now i have done my research and i have tried assigning the variable datatype Object but did not work. I tried using cast in my sql query and that also did not work.
Since my query returns multiple rows and one column, i am not sure how i can assign a datatype to the whole query?
Sample:
Code
AR
BN
CN
It sounds like you have a variety of issues in here.
Result Set
The first is in your Execute SQL Task and the need for agreement between the Result Set specification and the data type of the Variable(s) specified in the Result Set tab. If you specify Full Resultset, then the receiving object must be of type System::Object and you will only have 1 result set. The type of Connection Manager (ODBC/OLE/ADO) used will determine how you specify it but it's infinitely searchable on these fine forums.
The other two options are Single Row and XML. In 13 years of working with SSIS, I've never had cause to specify XML. That leaves us with Single Row. For a Single Row Result Set, you need to provide a variable for each column returned and it needs to be correctly typed.
To correct your issue, you need to declare a second variable. I usually call my rsObject (record set object) and then specify the data type as System.Object.
For Each Loop Container
Your For Each Loop Container will then be set with an Enumerator of "Foreach ADO Enumerator" and then the ADO object source variable will become "User::rsObject"
In the Variable Mappings, you'll specify your variable User::house to index 0.
Testing
Given a sample set of source source data, you can verify that you have your Execute SQL Task correctly assigning a result set to our object and the Foreach Loop Container is properly populating our variable.
SELECT DISTINCT
code
FROM
(
VALUES
('ABC', 1, 'w')
, ('BCD', 1, 'w')
, ('CDE', 0, 'w')
, ('DEF', 1, 'w')
, ('EFG', 1, 'x')
) house(code, active, campus)
WHERE
active = 1
AND campus = 'w';
If you change the value of campus from w to something that doesn't exist, like f then things will continue to work.
However, the error you're receiving can only be generated if the code is a NULL
Add one more entry to the VALUES collection like
, (NULL, 1, 'w')
and when the For Each Loop Container hits that value, you will encounter the error you indicate
The type of the value (DBNull) being assigned to variable "User::house" differs from the current variable type (String)
Now what?
SSIS variables cannot change their data type, unless they're of type Object (but that's not the solution here). The "problem" is that you cannot store a NULL value in an SSIS variable (unless it's of type object). Therefore you need to either exclude the rows that return a NULL (AND code IS NOT NULL) or you need to cast the NULL into sentinel/placeholder value as a substitute (SELECT DISTINCT ISNULL(code, '') AS code). If an empty string is a valid value, then you need to find something that isn't - "billinkcisthegreatestever10123432" is unlikely to exist in your set of codes but that might be a bit excessive.
Finally, think about renaming your SSIS variable from house to code. You might be able to keep things straight but some day you'll hand this code over to someone else for maintenance and you don't want to confuse them.
A picturesque answer https://stackoverflow.com/a/13976990/181965
the variable "User::house" is string , so , did you use it in result set?
you need declare son "object" var for result set
result set
then declare a string variable for every single Code from your result
For Each Loop Container
good luck

how to decide if a element is in a set in GAMS

The situation is: I define a set in gams, like:
set n /n1*n100/;
And later in the code, I want to find a way to decide a if a element is in a set. For example, I want to have a function f, such that
(1) if a element in a set, it returns true(or '1'). Like, f('n1',n) = true(or '1')
(2) if a element not in a set, it returns false(or '0'). Like, f('n111',n) = false(or '0')
Does anyone know if there exists this kink of function? Also, if exists, does it also works for multiple dimensional set?
The question is a bit unclear in what you want to do. That being said, subsets seem one to do what you want, for instance:
set m /n1*n100/;
set n(m) /n1*n50/;
parameter test(m);
test(m)=0;
test(n)=1;
display test;
This is overly explicit, for instance, you do not need test(m)=0; as gams default value is 0.
So that you could use param(m)$test(m) = 3; to only set the values where test is positive.
Of course, it is much simpler to use param(n) = 3
Finally, strictly speaking, the instructions: sameas(set1,set2) or sameas(set1,"n101") do what you want.
Without a clearer question, it is hard to help beyond this point.

JMeter Random Variable Element not recognise variable from previous step

tl;dr
When I use my variable created in Regular Expression Extractor I cannot use it in Random Variable as Maximum Value
Long description:
My test structure:
I have variable my_test what is crated in Regular Expression Extractor
request: GET //echo.getpostman.com/get?test=123
regex:
Then I want it use as Maximum Value in Regular Expression Extractor
So finally I can make request:
//echo.getpostman.com/get?test=${rand}
Unfortunately I get error from Random Variable
2016/10/07 07:52:41 ERROR - jmeter.config.RandomVariableConfig: maximum(${my_test}) must be > minimum1)
Why my_test is not evaluated?
I have tried ${__javaScript(parseInt('${my_test}'))} but it looks like it is evaluated before my variable initialization
2016/10/07 08:06:01 ERROR - jmeter.config.RandomVariableConfig: maximum(NaN) must be > minimum1)
If I initialize this variable in Test Plan in User Defined Variables value from that setting will be used - not updated by regex.
I know that I can do //echo.getpostman.com/get?test=${__Random(0,${my_test})}
I'm just curious how pass my variable as value for Maximum Value in Regular Expression Extractor.
Random Variable is a Config Element and it will be executed first before any other components get executed first.
4.9 Execution order
Configuration elements
Pre-Processors
Timers
Sampler
Post-Processors (unless SampleResult is null)
Assertions (unless SampleResult is null)
Listeners (unless SampleResult is null)
If two or more Config elements present in the Test Plan, then they will be executed in the order they appear in the Test Plan.
Check the execution order and Scope here:
Refer 4.9 7 4.10 here Execution Order and Scope Rules
So, first Random Variable is evaluated first and then Sampler and then regular expression extractor.
When you used User Defined Variables, which is another Config Element, and probably you put it before Random Variable, so it evaluated the expression as you already defined the value for "my_test". But it won't override the value you captured in Regular Expression Extractor.
To solve your problem (one probable solution):
you can use different thread groups. In first thread group, you capture the value and in second thread group, you use the value.
Run Thread Groups consecutively.
Use BeanShell Assertion to capture the value by setProperty. (in first thread group)
Use value using __property() (in thread group)
https://www.blazemeter.com/blog/knit-one-pearl-two-how-use-variables-different-thread-groups
It seems that Random Variable element does not evaluate variables, maybe it worth creating an issue in JMeter Issue Tracker
As a workaround you can substitute it with __Random() function directly where required like:
${__Random(1,${my_test},)} - if you need the value right away, directly in you URL:
//echo.getpostman.com/get?test=${__Random(1,${my_test},)}
${__Random(1,${my_test},rand)} - if if you need to store the value into ${rand} variable as well
See:
Using JMeter Functions article for extended information on this and others JMeter Functions.
Function Helper Dialog - an utility helping to generate correct function syntax.
I think it's valid for me to comment on a problem I had, I set the random variable and it didn't work at all, I did everything I could to try to solve it.
In the end my problem was a space at the beginning of the variable.
One possibility is you can use a Beanshell Postprocessor to write the RegEx value to the variable name.
After that you can use it as ${variable_name}
NB: Beanshell function vars.get can be used for getting regex value and vars.put can be used for putting it into your variable.

How should I write an MDX Filter statement with multiple OR conditions efficiently?

In SQL you can compare a field against a set in the form
[Foo] In {"Bar1", "Bar2", ... , "BarN"}
However I'm having trouble working out how to move a filter expression into something like this. That is, for now, I end up with:
Filter(
[MyHierarchy].[Foo].Members,
[MyHierarchy].CurentMember.Name = "1"
OR [MyHierarchy].CurentMember.Name = "2"
...
OR [MyHierarchy].CurentMember.Name = "N"
)
Since I have 20-30 comparisons, and a moderate chance of the heirarchy name changing, I'd much rather maintain a set and a hierarchy name than a long expression. Is there any way to accomplish this?
Worth bearing in mind that the context is an Excel CubeSet function, so I'm a little limited in terms of defining my own members in the WITH clause.
Assuming you have a set named SelectedMembers, you could use
Intersect([MyHierarchy].[Foo].Members, [SelectedMembers])
You could of course also code this directly, i. e.
Intersect([MyHierarchy].[Foo].Members,
{
[MyHierarchy].[Foo].[1],
[MyHierarchy].[Foo].[2],
...
[MyHierarchy].[Foo].[N]
}
)
But it might be more convenient to have the set already defined in the cube calculation script - if that is possible.