I try to create a member by using some calculated measure (I have called it 'MyDay' here). I return date members on an axis and the members have a property which I want to use. I can return the property itself, but cannot create the member and work with it.
WITH
MEMBER [Measures].[MyDay] as DatePart("d", MyDateDimension.CurrentMember.Properties("MyProperty"))
MEMBER MyDateDimension.[MyMember] AS
STRTOMEMBER("MyDateDimension.&[2015]&[4]&[" + CStr([Measures].[MyDay]) + "]")
MEMBER [Measures].[SomeOther] as (MyDateDimension.[MyMember], [Measures].[Other]
SELECT
{
MyDateDimension.Members)
} ON COLUMNS,
{
[Measures].[MyDay] //works,
[Measures].[SomeOther] //error
}
If I replace 'MyDateDimension.CurrentMember' by some hard coded date member,
it works fine.
And this also works:
MEMBER [Measures].[SomeOther] as (STRTOMEMBER("MyDateDimension.&[2015]&[4]&[" + CStr([Measures].[MyDay]) + "]"), [Measures].[Other])
If you put the strToMember directly in the SomeMeasure then things start to function:
WITH
MEMBER [Measures].[MyDay] AS
Datepart
("d"
,[Date].[Calendar].CurrentMember.Member_Caption
)
MEMBER [Date].[Calendar].[MyMember] AS
StrToMember
(
'[Date].[Calendar].&[200603' + Cstr([Measures].[MyDay]) + ']'
,constrained
)
MEMBER [Measures].[SomeOther] AS
(
//[Date].[Calendar].[MyMember]
StrToMember
(
'[Date].[Calendar].&[200603' + Cstr([Measures].[MyDay]) + ']'
,constrained
)
,[Measures].[Internet Sales Amount]
)
SELECT
{
[Measures].[MyDay]
,[Measures].[SomeOther]
} ON COLUMNS
,Tail
(
Descendants
(
[Date].[Calendar].[Month].&[2005]&[8]
,[Date].[Calendar].[Date]
)
,10
) ON ROWS
FROM [Adventure Works];
A slightly tidier version:
WITH
MEMBER [Measures].[MyDay] AS
Datepart
("d"
,[Date].[Calendar].CurrentMember.Member_Caption
)
MEMBER [Measures].[MyDayString] AS
'[Date].[Calendar].&[200603' + Cstr([Measures].[MyDay]) + ']'
MEMBER [Measures].[SomeOther] AS
(
StrToMember
(
[Measures].[MyDayString]
,constrained
)
,[Measures].[Internet Sales Amount]
)
SELECT
{
[Measures].[MyDay]
,[Measures].[SomeOther]
} ON COLUMNS
,Tail
(
Descendants
(
[Date].[Calendar].[Month].&[2005]&[8]
,[Date].[Calendar].[Date]
)
,10
) ON ROWS
FROM [Adventure Works];
Above returns the following:
So something like this in your cube:
WITH
MEMBER [Measures].[MyDay] AS
Datepart
("d"
,MyDateDimension.CurrentMember.Properties("MyProperty")
)
MEMBER [Measures].[MyDayString] AS
StrToMember('MyDateDimension.&[2015]&[4]&[' + Cstr([Measures].[MyDay]) + ']')
MEMBER [Measures].[SomeOther] AS
(
StrToMember
(
[Measures].[MyDayString]
,constrained
)
,[Measures].[Other]
)
SELECT
{
[Measures].[MyDay]
,[Measures].[SomeOther]
} ON COLUMNS
,{MyDateDimension.MEMBERS} ON ROWS
FROM YourCube;
Try using the SUM function in the definition of [Measures].[SomeOther]. It will accept calculated members.
MEMBER [Measures].[SomeOther] as
SUM(
MyDateDimension.[MyMember],
[Measures].[Other]
)
Related
I am using Built in time intelligence feature and I would like to calculate measures for the Full Year.
Eg if current member of date is at 2015/03/01; I want to have a calculated measure from 2015/01/01 till 2015/12/31.
CREATE MEMBER CurrentCube.[DimTime].[FY-FQ-FM DimTime Calculations].[Full Year] AS "NA" ;
(
[DimTime].[FY-FQ-FM DimTime Calculations].[Year to Date]
, [DimTime].[Fiscal Year].[Fiscal Year].Members
, [DimTime].[Date].Members
, { [Measures].[Forecasts], [Measures].[Budget] }
)
= Aggregate(
{ [DimTime].[FY-FQ-FM DimTime Calculations].[Current DimTime] }
* PeriodsToDate(
[DimTime].[FY-FQ-FM].[Fiscal Year]
, [DimTime].[FY-FQ-FM].CurrentMember
)
) ;
Thanks #whytheq and #AkshayRane for the help.
I was able to do the full year using below.
(
[DimTime].[FY-FQ-FM DimTime Calculations].[Full Year],
[DimTime].[Fiscal Year].[Fiscal Year].Members,
[DimTime].[Date].Members,
{
[Measures].[Forecasts],
[Measures].[Budget]
}
)
=
Aggregate(
{ [DimTime].[FY-FQ-FM DimTime Calculations].[Current DimTime] }
*
PeriodsToDate(
[DimTime].[FY-FQ-FM].[Fiscal Year],
(
ANCESTOR(
[DimTime].[FY-FQ-FM].CURRENTMEMBER,
[DimTime].[FY-FQ-FM].[Fiscal Year]
)
)
)
)
How to get top 5 from mdx query?
I have a this query:
WITH SET [Geography].[City] AS
TopCount(
[Geography].[City]
,5
,[Measures].[Reseller Freight Cost]
)
SELECT
NON EMPTY {
CROSSJOIN(
{
[Date].[Calendar]
},
{
[Product].[Category]
}
),
CROSSJOIN(
{
[Date].[Calendar].children
},
{
[Product].[Category]
}
)
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON COLUMNS,
NON EMPTY {
[Geography].[City],
[Geography].[City].children
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON ROWS
FROM [Adventure Works]
WHERE (
[Measures].[Reseller Freight Cost]
)
But is not working.
Now i have error
error: {"faultstring":"Query (1, 21) Parser: The syntax for '.' is incorrect.","faultcode":"XMLAnalysisError.0xc10e0002"}
The best if I not must change a code after SELECT word .
When you create a set just declare it with no associated hierarchy so this is wrong [Geography].[City].
Also there is a much more readable syntax for cross-join - just use an asterisk *
Try this:
WITH SET [CitySet] AS
TopCount(
[Geography].[City]
,5
,[Measures].[Reseller Freight Cost]
)
SELECT
NON EMPTY {
[Date].[Calendar] * [Product].[Category]
,[Date].[Calendar].children * [Product].[Category]
} DIMENSION PROPERTIES children_cardinality, parent_unique_name ON COLUMNS,
NON EMPTY {
[CitySet], //<<changed here [Geography].[City],
[Geography].[City].children
}
DIMENSION PROPERTIES children_cardinality, parent_unique_name ON ROWS
FROM [Adventure Works]
WHERE (
[Measures].[Reseller Freight Cost]
)
I have very little experience with MDX and SSAS so have no idea where to start with this:
We are moving from a SQL 2005 environment to SQL 2012. On SSAS 2005 the query below runs in about 3 to 4 seconds. When running the same query on SSAS 2012 it runs for a whopping 1 hour 58 minutes before completing. Could anyone shed some light on why the performance is so terrible, and how it could be improved? We're on SQL 2012 11.0.5532.0 (X64).
Thanks a lot in advance.
with member [Measures].[Calculation] as
Format(
IIF(isempty([Measures].[average complience to requirements]), null,
[Measures].[average complience to requirements]),
"#,0.00"
)
select
non empty
{
[Measures].[average complience to requirements],
[Measures].[Calculation]
} on 0,
nonempty
(
[Customer].[App Key Company Id].children *
[Location].[App Key Region Id].children *
[Category].[App Key Category Id].children *
[Vendor].[App Key Vendor Id].children,
[average complience to requirements]
) on 1
from
[BSC]
where
(
strtomember(
"[Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].&[" + Format( Now(), "yyyyMM") + "]"
):
strtomember(
"[Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].&[" + Format( Now(), "yyyyMM") + "]").Lag(2)
)
If current month is the last member of [Date Submitted Date].[YYYY-MMMM-DD] hierarchy, query could be simplified to this one:
with member [Measures].[Calculation] as
Format([Measures].[average complience to requirements],"#,0.00")
select
{
[Measures].[average complience to requirements],
[Measures].[Calculation]
} on 0,
nonempty
(
[Customer].[App Key Company Id].children *
[Location].[App Key Region Id].children *
[Category].[App Key Category Id].children *
[Vendor].[App Key Vendor Id].children,
[average complience to requirements]
) on 1
from
[BSC]
where
Tail([Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].Members,3)
Unnecessary Non Empty checks were removed from axis 0 and [Measures].[Calculation].
TAIL function is used instead of dynamic members to let server use block mode instead of cell-by-cell computation.
Please also answer questions under your message to have better understanding of possible issues.
Not sure if this would work, but try this one out too:
Here replaced WITH clause with subselect
with member [Measures].[Calculation] as
Format(
IIF(isempty([Measures].[average complience to requirements]), null,
[Measures].[average complience to requirements]),
"#,0.00"
)
select
non empty
{
[Measures].[average complience to requirements],
[Measures].[Calculation]
} on 0,
nonempty
(
[Customer].[App Key Company Id].children *
[Location].[App Key Region Id].children *
[Category].[App Key Category Id].children *
[Vendor].[App Key Vendor Id].children
//[average complience to requirements] //removed
) on 1
from
(
SELECT
{
strtomember(
"[Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].&[" + Format( Now(), "yyyyMM") + "]"
):
strtomember(
"[Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].&[" + Format( Now(), "yyyyMM") + "]").Lag(2)
} ON 0
FROM [BSC]
)
How much time does the below queries take?
1) No calculated member
//with member [Measures].[Calculation] as
// Format(
// IIF(isempty([Measures].[average complience to requirements]), null,
// [Measures].[average complience to requirements]),
// "#,0.00"
//)
select
non empty
{
// [Measures].[average complience to requirements], /////This measure removed
[Measures].[Calculation]
} on 0,
nonempty
(
[Customer].[App Key Company Id].children *
[Location].[App Key Region Id].children *
[Category].[App Key Category Id].children *
[Vendor].[App Key Vendor Id].children
//[average complience to requirements] //removed
) on 1
FROM [BSC]
where (
{
strtomember(
"[Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].&[" + Format( Now(), "yyyyMM") + "]"
):
strtomember(
"[Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].&[" + Format( Now(), "yyyyMM") + "]").Lag(2)
}
)
2) Nothing on ROWS
with member [Measures].[Calculation] as
Format(
IIF(isempty([Measures].[average complience to requirements]), null,
[Measures].[average complience to requirements]),
"#,0.00"
)
select
non empty
{
[Measures].[average complience to requirements], /////This measure removed
[Measures].[Calculation]
} on 0,
{} on 1
FROM [BSC]
where (
{
strtomember(
"[Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].&[" + Format( Now(), "yyyyMM") + "]"
):
strtomember(
"[Date Submitted Date].[YYYY-MMMM-DD].[Month Of Year].&[" + Format( Now(), "yyyyMM") + "]").Lag(2)
}
)
3) NO SLICER
select
non empty
{
// [Measures].[average complience to requirements], /////This measure removed
[Measures].[Calculation]
} on 0,
nonempty
(
[Customer].[App Key Company Id].children *
[Location].[App Key Region Id].children *
[Category].[App Key Category Id].children *
[Vendor].[App Key Vendor Id].children
//[average complience to requirements] //removed
) on 1
FROM [BSC]
If nothing is conclusive out of them, just do some more similar troubleshooting to zero in on the actual cause of issue. Once you figure out, it will be easy to work on it. For us, it is obviously pointless to do armchair analysis without having any idea on the inside cube, when the actual query looks quite okay.
Here is my script:
WITH
SET [Set_TargetEmp] AS
{
FILTER(
[Employee Department].AllMembers,
(
InStr(
1,
[Employee].[Employee Department].currentmember.name,
"REUBEN") <> 0
)
)
}
SELECT
DESCENDANTS(
[Set_TargetEmp],
[Employee].[Employee Department],
SELF_BEFORE_AFTER)
ON 1,
{} ON 0
FROM [Adventure Works]
I know that [Set_TargetEmp] is the following:
So why when I wrap it in the function DESCENDANTS with the optional arg SELF_BEFORE_AFTER isn't reuben's related Department and Title not returned ?
EDIT
So I've simplified the above even further. Why doesn't the following return Reuben's title and department - I thought the point of SELF_BEFORE_AFTER was to also return relatives from the other levels of the hierarchy [Employee].[Employee Department] ?
SELECT
DESCENDANTS(
[Employee].[Employee Department].[Employee].[Reuben H. D'sa],
[Employee].[Employee Department],
SELF_BEFORE_AFTER)
ON 1,
{} ON 0
FROM [Adventure Works]
Descendants only returns descendants, i. e. members on a lower level than the first argument. What you require would be an Ancestor. But - according to the documentation - the Ancestor and Ancestors functions do not allow a set as first argument. This means that - assuming your set is meant to possibly contain more than one member - you would have to use Generate to iterate over the members of [Set_TargetEmp]:
WITH
SET [Set_TargetEmp] AS
{
FILTER(
[Employee Department].AllMembers,
(
InStr(
1,
[Employee].[Employee Department].currentmember.name,
"REUBEN") <> 0
)
)
}
SELECT
{} ON 0,
Generate([Set_TargetEmp] as e,
{Ancestor(e.Current, [Employee].[Employee Department].[Department])}
)
ON 1
FROM [Adventure Works]
I have this MDX query
select
{
[Measures].[Sold value]
,[Measures].[Units]
,[Measures].[Sales baskets]
,[Measures].[ATV]
,[Measures].[AUT]
} on columns
, filter(
nonempty(
{[Branch].[Branch].&[5] *[Receipt No - Sales].[Receipt No].[Receipt No]}
),
[Measures].[Sold value] >= 50
) on rows
from Rmis
where [Time].[Day].&[20131218]
Which generates following result:
How can I get the total of these measures of the above result set? The total should use the aggregation defined in the cube.
with set [rows] as
filter(
nonempty(
{[Branch].[Branch].&[5] *[Receipt No - Sales].[Receipt No].[Receipt No]}
),
[Measures].[Sold value] >= 50
)
member [Receipt No - Sales].[Receipt No].[Total] as
aggregate([rows])
select
{
[Measures].[Sold value]
,[Measures].[Units]
,[Measures].[Sales baskets]
,[Measures].[ATV]
,[Measures].[AUT]
} on columns
,
{ ([Branch].[Branch].&[5], [Receipt No - Sales].[Receipt No].[Total]) }
+
[rows]
on rows
from Rmis
where [Time].[Day].&[20131218]