SSAS MDX Except statement issue - ssas

I am working on an requirement in Cube MDX like data for year 2008 and prior should not be displayed in report.
So thought of using MDX 'EXCEPT' function in SCOPE statement to exclude the mentioned years.
Time dimension is hierarchy with structure Year-->Quarter-->Month
Initial code was like
SCOPE([Measure Item].[Measure Item].&[SAL]);
SCOPE(EXCEPT({[Time].[Time].[Year]},{[Time].[Time].&[2006],[Time].[Time].&[2007],[Time].[Time].&[2008]}));
this=([Measure Item].[Measure Item].&[SAL]);
END SCOPE;
END SCOPE;
With the code after deploying, data for year 2008 and prior got excluded. But the issue here is, I can only see data on Grand Total on each Year. Please see the example in below screenshot, I cannot see data on Quarter level and month level.
Not able to see data on quarter and month level
Tried few other codes with descendants function, which is working in SSMS but when write it with SCOPE statements its not working.
Code written in SSMS:
select [Measures].[Value] on 0,
EXCEPT({[Time].[Time].members} ,
{descendants([Time].[Time].&[2006],0,SELF_AND_AFTER),descendants([Time].[Time].&[2007],0,SELF_AND_AFTER)}) on 1 from [TOPAS Reporting]
Working in SSMS but not working in SCOPE statement
I can see data on even Quarter and month level. But same code is not working in SCOPE statements of cube MDX.
Please help me to solve this issue and let me know for further details .
Thanks in advance.

Do you really need a scope statement?
You can achieve it by using the following calculation:
Aggregate(
existing [Time].[Time].&[20090101]:NULL,
[Measure Item].&[SAL]
)
where [Time].[Time].&[20090101] is the first day on the Day level.

Related

MDX query in cube calculation

I've created a simple cube calculation that sums two measures.I only want to sum, or to return data when both measures return a value.
When I use the calculation in an MDX query, it works as expected, however when I browse the cube via a pivot table I it display all results, and not what I need. It seems to me that I need to modify the cube calculation to get the same NONEMPTY behaviour as per the MDX query, but I just can't get the syntax correct, or know if this is indeed the correct approach. I'd be grateful for some pointers.
Sample of underlying data:
Cube calculation:
This MDX statement does exactly what I want it to:
The IIF function would be useful in this scenario
For e.g.,
CREATE MEMBER CURRENTCUBE.[Measures].[RevalCombined]
AS IIF([Measures].[Reval]=0, NULL, [Measures].[Reval]) + IIF([Measures].[dReval]=0, NULL, [Measures].[dReval])

mdx with aggregate last periods not working

I am using Analysis Services on SQL server 2014, enterprise edition.
I am trying to create a new member for Timeframe dimension that aggregates last 3 months values. The following mdx code gets compiled without errors, but when I browse it with a measure, it still shows me the month level numbers, instead of last three month sum. What am I doing wrong? Any help is appreciated.
CREATE MEMBER CURRENTCUBE.[Timeframe].[Timeframe].[ROLLING 3 MONTH]
AS IIF([Accounting Date].[Accounting Date].CurrentMember.Level.Name="Month", AGGREGATE(LASTPERIODS(3),[Timeframe].[Timeframe].&[1]), NULL),
VISIBLE = 1;
Thanks.
Please try the following:
CREATE MEMBER CURRENTCUBE.[Timeframe].[Timeframe].[ROLLING 3 MONTH]
AS
IIF(
[Accounting Date].[Accounting Date].CurrentMember.Level.Name="Month",
AGGREGATE(
LASTPERIODS(3, [Accounting Date].[Accounting Date].CurrentMember),
[Timeframe].[Timeframe].&[1]
),
NULL),
VISIBLE = 1;
Specifying the member in the LASTPERIODS function is hopefully what you were missing. SSAS was probably assuming some other Date hierarchy or you don't have any hierarchies and dimensions properly marked. That's ok. Just specify the member and then it should work.
By the way, for performance reasons I would prefer to see a SCOPE statement instead of checking the level's name. What you have should work but if you hit performance issues research SCOPE statements or create a new thread asking to optimize that MDX.
I assume you are using Excel 2010 or higher. If not watch out!

MDX YTD calculated measure

I'm still new to MDX and I'm trying to get some basic functions to work in my SSAS cube. Can you guys point out what I'm doing wrong here? I've added a calculated measure to my cube with the following code:
CREATE MEMBER CURRENTCUBE.[Measures].[Amount YTD]
AS
AGGREGATE(
YTD([OrderDate].[Calendar].CurrentMember)
,[Measures].[Amount]),
VISIBLE = 1, ASSOCIATED_MEASURE_GROUP = 'MyMeasureGroup';
After that I'm trying to get some data going...
SELECT
NON EMPTY
{
[Measures].[Amount]
, [Measures].[Amount YTD]
} ON COLUMNS,
NON EMPTY
{
[OrderDate].[Month].ALLMEMBERS *
[Product].[Product Group].ALLMEMBERS
} ON ROWS
FROM (SELECT ([OrderDate].[Year].&[2014-01-01T00:00:00]:
[OrderDate].[Year].&[2015-01-01T00:00:00]) ON COLUMNS
FROM [SalesOrderIntake])
This is the output I'm getting:
I'm not seeing any errors in my Output messages, which makes it difficult for me to figure out what is acting up. Hoping you guys can help me out on this one.
FYI: the actual select is just for testing purposes. I just want to get that YTD running. I've tried several things and it always comes out empty, so I was hoping to get some actual errors if I would query it directly in SSMS instead of using a BI tool. Also, the OrderDate dimension is a generated Time dimension which was provided to me by VS.
In your query you're using what looks like an attribute hierarchy:
[OrderDate].[Month].ALLMEMBERS
Whereas the measure uses the user hierarchy:
[OrderDate].[Calendar]
If you use Calendar in your script does it work ok?
#Error usually crops up when there are run time errors in MDX code. I could think of one scenario where the error might crop up. You are using [OrderDate].[Calendar].CurrentMember in the calculated member. But if instead of one, there are multiple members from this hierarchy in scope, it will throw an error.
The below is a scenario from Adventure Works.
with member abc as
sum(YTD([Date].[Calendar].currentmember), [Measures].[Internet Sales Amount])
select abc on 0
from [Adventure Works]
where {[Date].[Calendar].[Date].&[20060115], [Date].[Calendar].[Date].&[20060315]}
P.S. Thanks to #whytheq for teaching me this trick of checking this error by double clicking the cell :) Cheers.
I know, its an old post, but in the interest of posterity..
The correct approach is :
Aggregate
(
PeriodsToDate
(
[OrderDate].[Calendar].[Fiscal Year]
,[OrderDate].[Calendar].CurrentMember
)
,[Measures].[Amount]
)

TSQL Paramterised Pivot Query SP SSRS

Wonder if anyone has done this before and what solution you came up with?
I have a Stored Proc that basically is a financial aged debtors query. I have added params to it so that you can select the Start Date, Frequency and Period length of the query. e.g. I could pick 12 months back from TODAY or 01/01/2012 or 4 Quarters back or 1 year back depending on the detail of the output I wish to see.
All well and good and when I run it in SQL it is lovely and works beautifully. I have pivoted the data within the SP in different ways depending on the Period param so that the columns show correctly (i.e. Shows the month name column for months, Quarter name for quarters etc etc.) so the pivot is conditional on the input parameter.
As I say in SQL it is a beautiful thing... now how the hell do I display it in SSRS!? :o)
As the PIVOT is conditional I can't see the available fields and I've got to a point where I can't think anymore of a way around it.
Any help appreciated!
Assuming I got you right, there is an option to place the entire SP in the Dataset.
In the dataset properties , change the query type to Store Procedure.
Hope it helps for you...

SSAS - Moving Annual Total

Environment: SQL-Server-2005, SSAS 2005
I am using the following formula to create a Moving Annual Total
SUM ({[Time].CurrentMember.Lag(3):[Time].CurrentMember}, [Measures].[TRx Quantity])
The same column [Measures].[Trx Quantity] is used in other calculations and it works fine. This one, however, comes up with #Value! to indicate some kind of an error. Can anyone point me in the proper direction here?
Is this SSAS 2005/2008?
If it is either of these and you are running this in Management Studio you can hover over the #Value and get the details of the error.
But at a guess it is most likely because .CurrentMember needs to be called on a hierarchy and [Time] is a dimension reference. It should refer to one of the hierarchies like [Time].[Calendar].CurrentMember or maybe [Time].[Quarter].CurrentMember
It turned out to be that I was missing the MONTH
SUM ({[Time].[Month].CurrentMember.Lag(3):[Time].[Month].CurrentMember}, [Measures].[TRx Quantity])