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]
)
Related
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])
I am new to SSAS. I have a requirement, I need to calculate no of working days between user selected date range (either in Excel or SSRS or PowerBI). I found the MDX query, I need assistance with create a named calculation with MDX expression.
Date Dimension (Filtered):
MDX:
WITH MEMBER Measures.WorkingDays AS
COUNT
(
exists( EXISTING {[Dim Date].[Date].[Date].members}
, [Dim Date].[Is Weekday].&[1] )
)
Select {Measures.WorkingDays} on 0 ,
[Dim Date].[Month].[Month] on 1
from [Project Cube]
where ([Dim Date].[Date].&[2018-01-01T00:00:00]:[Dim Date].[Date].&[2018-04-25T00:00:00])
I need to add this named column on Fact table as measurement. I am having trouble with the below items:
Creating named query with MDX expression mentioned.
Adding a [Number of Working Days] as measure in Fact table.
Please correct me, If I am doing it in wrong way. My requirement is I need a [NoOfWorkingDays] as measure in fact table, so that I can use SSAS aggregate to use it as input on other measure, such as ([utilization%] = ([ActualDaysWorked] / [NoofWorkingDays]).
Note that, I can do analysis with the given MDX, but I need to deploy it with precalculated values in cube, so that end user can directly use the cube.
Kindly let me know, if more details required, Thank you.
Welcome to SSAS and MDX. Now to the answer.
I need to add this named column on Fact table as measurement. I am
having trouble with the below items:
Creating named query with MDX expression mentioned. Adding a [Number
of Working Days] as measure in Fact table.
You dont need to add it to the Fact table at all. Open your SSAS project, in your object explorer double click your cube. Now on the top left hand you will see a CALCULATIONS tab. In the CALCULATION tab, Click new calculated member, the icon has a calculator on it.
Please correct me, If I am doing it in wrong way. My requirement is I
need a [NoOfWorkingDays] as measure in fact table, so that I can use
SSAS aggregate to use it as input on other measure, such as
([utilization%] = ([ActualDaysWorked] / [NoofWorkingDays]).
If I remember correctly, the calculated members will not be added into the Aggregations, however the underlying measures would be. Secondly if you are wondering that you can use your calculated Measure in another calculated measure. The answer is yes you can use it in another calculated measure. So this is totally possible
> ([utilization%] = ([ActualDaysWorked] / [NoofWorkingDays])
where [utilization%] and [NoofWorkingDays] are calculated measures.
I'm new to MDX and need help.
I have a list of possible accounts I want to check in the database but not all of the accounts are actually members yet. So if I try to run the query it fails and tells me the member doesn't exist. Is there a way of error handling that I can make it ignore members that don't exist or another better way to setup the query to accomplish this?
Below basically what i've tried that gives the error
Select
{[member].[Value]} on Columns,
{[member].[Acount1],
[member].[Acount2],
[member].[Acount3],
...
[member].[Acount49],
[member].[Acount50]}
on Rows
For more clarification I'm looking for the SQL equivalent of
where account in ('Account1',Account2'...'Account50')
The following does not produce an error for me even though 20040101 is not a member in the cube:
SELECT
NON EMPTY
[Measures].[Sales Amount] ON 0
,{
[Date].[Calendar].[Date].&[20040101]
,[Date].[Calendar].[Date].&[20050101]
} ON 1
FROM [Adventure Works];
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!
I just started learning SSAS and cannot understand the basic idea.
What happens when query fixes fewer dimensions than cube has?
All examples usually present queries where intersection of dimensions gives either a point or an axis; in the former case we have the value and in the latter one we get some aggregated value.
Yet I cannot understand what happens when fixed dimensions produce a cube with fewer dimensions. What will be the result of such query?
I'll try to explain it simplier, then the previous answer.
In SELECT statement you define a 'space' more like mathematical space of result. The whole cube is being projected on that space using aggregation functions.
If you want to project part of the cube you use a WHERE clause.
That's the key defference between SQL which was hard for me to grasp in the beginning:)
An MDX query actually returns a cube - well a sub-cube.
I suppose this is enough to show it in action:
SELECT
NON EMPTY
{
[Measures].[Internet Order Count]
} ON COLUMNS
,NON EMPTY
{
[Sales Territory].[Sales Territory].[Country].MEMBERS
*
[Date].[Calendar].[Month].ALLMEMBERS
} ON ROWS
FROM
( //>>>>>>following is a sub-select>>>>>
SELECT
[Date].[Calendar].[Month].&[2008]&[1] ON COLUMNS
FROM [Adventure Works]
);
The section I've marked is a sub-select which returns a cube. That cube is then further queried by the outer script.
If a cube is returned then why do we just see a table of values? Returning a cube and what is actually visible are two different things. All dimensions are used whenever we run an mdx script - if we do not explicitly use the dimension in our script then it is evaluated at the [(All)] level. So even when only a small table is shown by say ssms all the dimensions are being returned by the script and then only certain aspects are being made visible via what is specified in your script.