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]
)
)
)
)
Related
I have 1 dimension Data with 2 hierarchies: Gregorian Calendar, Planning Calendar.
[Gregorian Year] - [Gregorian Month] - [Gregorian Day]
[Planning Year] - [Planning Month] - [Planning Day]
I have 2 MDX measures:
[Planning Stock] = Sum(PeriodsToDate([Data].[Planning Calendar].[(All)]), [amount])
[Gregorian Stock] = Sum(PeriodsToDate([Data].[Gregorian Calendar].[(All)]), [amount])
How to create one measure that will recognize the hierarchy?
I wrote something like that, but it does not work :(
iif(([Data].currentmember.level is [Data].[Planning Calendar].[(All)]),
(Sum(PeriodsToDate([Data].[Planning Calendar].[(All)]), [amount])),
(Sum(PeriodsToDate([Data].[Gregorian Calendar].[(All)]), [amount]))
)
Do you have any ideas?
You can do this using the level.hierarchy. Take a look at the example.
with member
measures.t
as
axis(1).item(0).hierarchy.name
select
{
[Measures].[Internet Sales Amount],measures.t
}
on columns,
{
[Date].[Fiscal].[Month].&[2014]&[7].children
--[Date].[Calendar].[Month].&[2013]&[6].children
}
on rows
from [Adventure Works]
Result
Lets change the hierarchy
with member
measures.t
as
axis(1).item(0).hierarchy.name
select
{
[Measures].[Internet Sales Amount],measures.t
}
on columns,
{
--[Date].[Fiscal].[Month].&[2014]&[7].children
[Date].[Calendar].[Month].&[2013]&[6].children
}
on rows
from [Adventure Works]
Result
I have an MDX Query running on the SSAS cube that returns lots of object codes and the period balances for them. I was able to add multiple period balances by using a crossjoin on the rows, however I would like to add one more row with the period end balance for the last fiscal period, and can't seem to figure out a way to do it.
The initial query is
select
non empty
{
[Object Code].[Object Code Number].[Object Code Number]
*
[Object Code].[Object Code Description].[Object Code Description]
*
[Object Code Pathing 1E 1R].[1E_R1 Value].[1E_R1 Value]
*
[Object Code Pathing 1E 1R].[1E_R2 Value].[1E_R2 Value]
*
[Object Code Pathing 1E 1R].[1E_R3 Value].[1E_R3 Value]
*
[Object Code Pathing 1E 1R].[1E_R4 Value].[1E_R4 Value]
}
on rows,
{
[Measures].[Current Period Balance]
}
*
{
[Date].[Fiscal].[Fiscal Period].&[2016]&[1]:[Date].[Fiscal].[Fiscal Period].&[2016]&[7]
}
on columns
from [Finance]
and when I am trying to add one more column
select
non empty
{
[Object Code].[Object Code Number].[Object Code Number]
*
[Object Code].[Object Code Description].[Object Code Description]
*
[Object Code Pathing 1E 1R].[1E_R1 Value].[1E_R1 Value]
*
[Object Code Pathing 1E 1R].[1E_R2 Value].[1E_R2 Value]
*
[Object Code Pathing 1E 1R].[1E_R3 Value].[1E_R3 Value]
*
[Object Code Pathing 1E 1R].[1E_R4 Value].[1E_R4 Value]
}
on rows,
{
[Measures].[Balance At Period End]
*
[Date].[Fiscal].[Fiscal Period]&[2016]&[7]
},
{
[Measures].[Current Period Balance]
}
*
{
[Date].[Fiscal].[Fiscal Period].&[2016]&[1]:[Date].[Fiscal].[Fiscal Period].&[2016]&[7]
}
on columns
from [Finance]
I get the
Parser: The statement dialect could not be resolved due to ambiguity. error
and if I add it like
{
[Measures].[Current Period Balance],
[Measures].[Balance At Period End]
}
*
{
[Date].[Fiscal].[Fiscal Period].&[2016]&[1]:[Date].[Fiscal].[Fiscal Period].&[2016]&[7]
}
on columns
I get Period end Balances for all periods, and this is not needed in the report, I only need the Balance at Period End for the very last period
Here is your first piece of troublesome code:
crossjoin (
[Measures].[Current Period Balance]
,{
[Date].[Fiscal].[Fiscal Period].&[2016]&[1]
,[Date].[Fiscal].[Fiscal Period].&[2016]&[2]
,[Date].[Fiscal].[Fiscal Period].&[2016]&[3]
}
), //<<1
crossjoin(
[Measures].[Balance At Period End]
,{[Date].[Fiscal].[Fiscal Period].&[2016]&[3]}
) on columns
from [Finance]
At point 1 you have closed the first crossjoin and then put a comma - this is a syntax error.
You could try moving that brace from 1 to the end of the statement:
crossjoin (
[Measures].[Current Period Balance]
,{
[Date].[Fiscal].[Fiscal Period].&[2016]&[1]
,[Date].[Fiscal].[Fiscal Period].&[2016]&[2]
,[Date].[Fiscal].[Fiscal Period].&[2016]&[3]
}
, //<<1
crossjoin(
[Measures].[Balance At Period End]
,{[Date].[Fiscal].[Fiscal Period].&[2016]&[3]}
)
) on columns //<<now closing initial crossjoin here
from [Finance]
Ok I just tested the above via the following and it is not a valid approach:
SELECT
CrossJoin
(
[Measures].[Internet Sales Amount]
,{
[Date].[Calendar].[Date].&[20060628]
,[Date].[Calendar].[Date].&[20060629]
}
,CrossJoin
(
[Measures].[Internet Order Quantity]
,{[Date].[Calendar].[Date].&[20060629]}
)
) ON COLUMNS
,[Product].[Product Categories].[All] ON ROWS
FROM [Adventure Works];
We get the following error:
Query (2, 3) The Measures hierarchy is used more than once in the
Crossjoin function.
You could switch to the following structure, creating a set of tuples. This does run:
SELECT
{
[Measures].[Internet Sales Amount]
*
{
[Date].[Calendar].[Date].&[20060628]
,[Date].[Calendar].[Date].&[20060629]
}
,(
[Measures].[Internet Order Quantity]
,{[Date].[Calendar].[Date].&[20060629]}
)
} ON COLUMNS
,[Product].[Product Categories].[All] ON ROWS
FROM [Adventure Works];
Result:
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]
)
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 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]