I am trying to create a named set that would return sum of selected members for any measure. When I deploy I am getting error
function expects a tuple set expression for the argument. A string or
numeric expression was used.
Please review my code and suggest solution. I have a dimension named Uline and this named set should sum selected 4 members of this dimension for any measure
sum({[Uline].[CU - (46)],
[Uline].[FRU - (45)],
[Uline].[GL - (38)],
[Uline].[PU - (44)]},[Measures].CurrentMember)
Better to use Aggregate rather than Sum if you wish it to be available for any measure.
Also no need to include the Measures hierarchy inside the function.
So try something simpler like this:
Aggregate(
{
[Uline].[CU - (46)],
[Uline].[FRU - (45)],
[Uline].[GL - (38)],
[Uline].[PU - (44)]
}
)
Please note though that this will be a new member in an existing hierarchy, like this:
WITH MEMBER [Uline].[AggSet] AS
Aggregate(
{
[Uline].[CU - (46)],
[Uline].[FRU - (45)],
[Uline].[GL - (38)],
[Uline].[PU - (44)]
}
)
SELECT
[Measures].[SOMEMEASUREinCUBE] ON 0,
[Uline].[AggSet] ON 1
FROM [CubeName];
I don't play around with the actual cube scripts myself but I'd guess the above could be implemented like this:
CREATE MEMBER CURRENTCUBE.Uline.AggSet AS
'Aggregate(
{
[Uline].[CU - (46)],
[Uline].[FRU - (45)],
[Uline].[GL - (38)],
[Uline].[PU - (44)]
}
)'
If you'd rather create a custom set than a calculated member then try the following:
CREATE SET CURRENTCUBE.[AggSet] AS
{
[Uline].[CU - (46)],
[Uline].[FRU - (45)],
[Uline].[GL - (38)],
[Uline].[PU - (44)]
}
,
Display_Folder = 'Sets';
The curly braces {} mean SET in mdx.
In the context of a script this looks like the following:
WITH SET [AggSet] AS
{
[Uline].[CU - (46)],
[Uline].[FRU - (45)],
[Uline].[GL - (38)],
[Uline].[PU - (44)]
}
SELECT
[Measures].[SOMEMEASUREinCUBE] ON 0,
[AggSet] ON 1
FROM [CubeName];
Related
I just started with go language, everything looks cool, I coded everything I need but I have two problems, actually it is passing an slice into a Struct or so called object, and how to create a method that I can add for example another matrix, but this is minor problem I think.
Code:
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
a := Matrix(nonsingularRandomMatrix())
fmt.Println(a)
}
type Matrix struct {
inputMatrix [][]int
}
func NewThing(inMatrix [][]int) *Matrix {
p := new(Matrix)
p.inputMatrix = inMatrix
return p
}
func nonsingularRandomMatrix() [][]int {
rand.Seed(time.Now().UTC().UnixNano())
var matrixDeterminant int = 0
nm := make([][]int, 4)
for i := 0; i < 4; i++ {
nm[i] = make([]int, 4)
for j := 0; j < 4; j++ {
nm[i][j] = rand.Intn(100)
}
}
matrixDeterminant =
nm[0][0]*nm[1][1]*nm[2][2]*nm[3][3] - nm[0][0]*nm[1][1]*nm[2][3]*nm[3][2] -
nm[0][0]*nm[1][2]*nm[2][1]*nm[3][3] + nm[0][0]*nm[1][2]*nm[2][3]*nm[3][1] +
nm[0][0]*nm[1][3]*nm[2][1]*nm[3][2] - nm[0][0]*nm[1][3]*nm[2][2]*nm[3][1] -
nm[0][1]*nm[1][0]*nm[2][2]*nm[3][3] + nm[0][1]*nm[1][0]*nm[2][3]*nm[3][2] +
nm[0][1]*nm[1][2]*nm[2][0]*nm[3][3] - nm[0][1]*nm[1][2]*nm[2][3]*nm[3][0] -
nm[0][1]*nm[1][3]*nm[2][0]*nm[3][2] + nm[0][1]*nm[1][3]*nm[2][2]*nm[3][0] +
nm[0][2]*nm[1][0]*nm[2][1]*nm[3][3] - nm[0][2]*nm[1][0]*nm[2][3]*nm[3][1] -
nm[0][2]*nm[1][1]*nm[2][0]*nm[3][3] + nm[0][2]*nm[1][1]*nm[2][3]*nm[3][0] +
nm[0][2]*nm[1][3]*nm[2][0]*nm[3][1] - nm[0][2]*nm[1][3]*nm[2][1]*nm[3][0] -
nm[0][3]*nm[1][0]*nm[2][1]*nm[3][2] + nm[0][3]*nm[1][0]*nm[2][2]*nm[3][1] +
nm[0][3]*nm[1][1]*nm[2][0]*nm[3][2] - nm[0][3]*nm[1][1]*nm[2][2]*nm[3][0] -
nm[0][3]*nm[1][2]*nm[2][0]*nm[3][1] + nm[0][3]*nm[1][2]*nm[2][1]*nm[3][0]
if matrixDeterminant == 0 {
nonsingularRandomMatrix()
}
return nm
}
Output from my console:
go run oop.go
command-line-arguments
.\oop.go:10: cannot convert nonsingularRandomMatrix() (type [][]int) to type Matrix
Any clue?
Greets!
What your compiler is saying is that [][]int and Matrix are two totally unrelated types. You can not convert from one to the other. Thats because Matrix is a struct which contains a [][]int, but Matrix is not an [][]int. To create a Matrix out of it you'd need to create a new Matrix and set the [][]int to the only member:
a := Matrix{nonsingularRandomMatrix()}
An easier way would be if Matrix were a [][]int.
type Matrix [][]int
This would just create a new name (Matrix) for [][]int, and in this case, a simple (explicit) conversion would work
Matrix(nonsingularRandomMatrix())
Has anyone defined a spline function (i.e. defineFuction) in PMML?
There is quite a few parameters that need to be defined, with a fairly lengthy math. For example, for a predictor with a 3-knot restrictive cubic spline, I have seven parameters (including two coefficients, three knots, one reference point and one predictor name). The math includes a bit of exponential, max statements, etc.
Here is an example of my Javascript code to calculate the value from a 3-knot RCS.
function spline3(exp_value, exp_mean, exp_coef, exp_coef1, knot1, knot2, knot3) {
var step1 = exp_coef*(exp_value-exp_mean);
var step2 = Math.pow((knot3 - knot1),(2/3));
var step3 = Math.pow(Math.max((exp_value - knot1)/step2,0), 3);
var step4 = ((knot2 - knot1) * Math.pow(Math.max((exp_value - knot3)/step2,0), 3));
var step5 = (knot3 - knot1) * Math.pow(Math.max((exp_value - knot2)/ step2 ,0), 3);
var step6 = (knot3 - knot2);
var output = (step3 + step4 - step5/step6) * exp_coef1 + step1;
return output ;
}
Can anyone suggest me what is the difference between
- (void)tabtwoAction:(id)sender;
and
- ()tabtwoAction:(id)sender;
with no return type
Method return types default to id, so all of
- (id)foo;
- ()foo;
- foo;
are equivalent.
One "difference" is.. if you have the method...
- staySexy { [thanks gorgeous]; }
you will get a compiler error...
error: returning void from a function with incompatible result type id
If the (id) is omitted (as has been discussed, it is actually just being implied)... the compiler will want (need? desire?) you to return something - aka an Object, or at least nil - not just void, or return!
- uglyMethod { return [loves it], nil; } // clang love you long time
I have my own class and am writing a method with multiple input (three float values) and multiple output (three float values). I don't figure out how I can get multiple output from a single method. Any ideas?
My current method looks like this:
- (void)convertABC2XYZA:(float)a
B:(float)b
C:(float)c
outputX:(float)x
outputY:(float)y
outputZ:(float)z
{
x = 3*a + b;
y = 2*b;
z = a*b + 4*c;
}
One way to “return” multiple outputs is to pass pointers as arguments. Define your method like this:
- (void)convertA:(float)a B:(float)b C:(float) intoX:(float *)xOut Y:(float *)yOut Z:(float)zOut {
*xOut = 3*a + b;
*yOut = 2*b;
*zOut = a*b + 4*c;
}
and call it like this:
float x, y, z;
[self convertA:a B:b C:c intoX:&x Y:&y Z:&z];
Another way is to create a struct and return it:
struct XYZ {
float x, y, z;
};
- (struct XYZ)xyzWithA:(float)a B:(float)b C:(float)c {
struct XYZ xyz;
xyz.x = 3*a + b;
xyz.y = 2*b;
xyz.z = a*b + 4*c;
return xyz;
}
Call it like this:
struct XYZ output = [self xyzWithA:a B:b C:c];
Methods in Objective-C (unlike, say, Python or JavaScript) can only return at most 1 thing. Create a "thing" to contain the 3 floats you want to return, and return one of those instead.
Instead of returning, you can use output parameters.
This is more related to C than objective-c.
You need to pass the values by references. Your function should be declared like this:
- (void)convertABC2XYZA:(float)a
B:(float)b
C:(float)c
outputX:(float *)x
outputY:(float *)y
outputZ:(float *)z;
and called like this:
[receiver convertABC2XYZA:a B:b C:c outputX:&x outputY:&y outputZ:&z];
i am new to objective C and I started to learn the basics in iOS development.
How can I easily calculate with fractions in Objective C?
Example 1: 1/8000 * 60
Example 2: 1/640 / 1/400
I need to have the result (if its < 1) as a fraction, too.
I think I would implement a new class, say Fraction which has two properties, the numerator and denominator. I would then implement four (or more if necessary) of the following functions:
- (Fraction*) add:(Fraction*)operand;
- (Fraction*) subtract:(Fraction*)operand;
- (Fraction*) multiply:(Fraction*)operand;
- (Fraction*) divide:(Fraction*)operand;
- (Fraction*) invert;
+ (Fraction*) fractionByAdding:(Fraction*)op1 to:(Fraction*)op2;
+ (Fraction*) fractionBySubtracting:(Fraction*)op1 from:(Fraction*)op2;
+ (Fraction*) fractionByMultiplying:(Fraction*)op1 with:(Fraction*)op2;
+ (Fraction*) fractionByDuviding:(Fraction*)op1 by:(Fraction*)op2;
+ (Fraction*) fractionByInverting:(Fraction*)operand;
In these methods, do the usual arithmetic you learned in school. Remember to simplify if both numerator and denominator has common divisors.
EDIT: Example implementation for one of these functions:
- (Fraction*) add:(Fraction*)operand {
return [Fraction fractionByAdding:self to:operand];
}
+ (Fraction*) fractionByAdding:(Fraction*)op1 to:(Fraction*)op2 {
int num = (op1.numerator * op2.denominator) + (op2.numerator * op1.denominator);
int denom = op1.denominator * op2.denominator;
return [[Fraction alloc] initWithNumerator:num andDenominator:denom];
}
Optionally you could add a reduce or simplify method and possibly an allowReducible property and an isIrreducible method. You could also implement isEqual and compareTo methods. A description should just print "a/b" as an NSString.
You can use type cast.
int x = 1;
int y = 8000;
int z = 60;
float result = ((float)x) / y * z;
You can calculate with decimal numbers by using float variables. However, there is no direct way to get the result of the calculation as a fraction, you will always get another float, i. e. a decimal number. There are algorithms to convert decimal numbers into fractions, but it's not a language feature of Objective-C.