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])
Related
All of the measure that I want to cumulative has the same formula. So, is there any way to use the thing like function or any thing in calculate measure to resolve this issue?
There are two ways to achieve your aim:
1- the first solution is based on using the business intelligence wizard to add time intelligence to your solution.
The time intelligence enhancement is a cube enhancement that adds time calculations (or time views) to a selected hierarchy. This enhancement supports the following categories of calculations:
List item
Period to date.
Period over period growth.
Moving averages.
Parallel period comparisons.
The wizard will let you chose the calculations and measures you want to apply.
Visit : https://learn.microsoft.com/en-us/analysis-services/multidimensional-models/define-time-intelligence-calculations-using-the-business-intelligence-wizard
Visit : http://www.ssas-info.com/analysis-services-articles/62-design/2465-ssas-time-intelligence-wizard
2- Use a dimension table to calculate your calculations, this solution is more complicated, but very powerful and one of the best practices.
The first step is to create a new physical dimension, with real
members for each of the calculations we're going to need. We don't
actually need to create a table in our data warehouse for this
purpose, we can do this with an SQL view like this
CREATE VIEW DateTool AS SELECT ID_Calc = 1, Calc = 'Real Value' UNION ALL SELECT ID_Calc = 2, Calc = 'Year To Date'
Next, we need to add this view to our DSV and create a dimension based
on it. The dimension must have one hierarchy and this hierarchy must
have its IsAggregatable property set to False. The DefaultMember
property of this hierarchy should then be set to the Real Value
member. Giving this dimension a name can be quite difficult, as it
should be something that helps the users understand what it does –
here we've called it Date Tool. It needs no relationship to any
measure group at all to work.
Our next task is to overwrite the value returned by each member so
that they return the calculations we want. We can do this using a
simple SCOPE statement in the MDX Script of the cube:
this code let you create the YEAR-TO-DATE aggregation for all your measures.
SCOPE ([Date Tool].[Calculation].[Year To Date]); THIS = AGGREGATE ( YTD ([Date Order].[Calendar].CurrentMember), [Date Tool].[Calculation].[Real Value]); END SCOPE;
Visit:https://subscription.packtpub.com/book/big_data_and_business_intelligence/9781849689908/6/ch06lvl1sec35/calculation-dimensions
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 am trying to write an MDX query to return some information about survey questions. I want Average response and total responses in my results. I have two types of questions. One type of question has a single response. Another type of question can have multiple responses (Pick all that apply). Each question is tied to a question ID and a respondent ID. The following query works (somewhat)
Select NON EMPTY
{
[Measures].[Average Response], [Measures].[Total Count]
} ON 0
, NON EMPTY
{
([Question].[Question ID].[Question ID].ALLMEMBERS)
} ON 1
From [Cube]
Average Response is a combination from both single responses and multiple responses (two different fact tables). The total count is also a combination of the two tables. The problem is that for single response questions, I can just count the number of respondents. For multi response questions that falls down as I can have way more responses than I do people taking the survey. I really want to know how many people provided an answer. To do this, I think I need the distinct count of respondent IDs. So I tried changing my first axis to this.
[Measures].[Average Response], [Measures].[Total Count], DISTINCTCOUNT([Respondent].[Respondent ID])
Well, that doesn't work and I really didn't expect it to. I got "The function expects a tuple set expression for the 3 argument. A string or numeric expression was used." which is rapidly becoming my favorite SSAS error message. I am still green at this and I guess I am still thinking SQL. How can I get an average of the responses and a count of the distinct Dimension values in the same query. BTW, my query does have a slicer and I could provide that if needed but I don't think it relevant as I get the same problems with or without the slicer.
When working with the MDX DistinctCount function, it returns the count of distinct, non-empty tuples of a given set of data. Perhaps try doing something like
DistinctCount({[Respondent].[Respondent ID].members * [Measures].[Total Count]})
so that way you are working with a set (e.g. {...}) of data.
If you're working with a larger set of data, you may want to consider creating a Distinct Count measure. The DistinctCount function itself is a SSAS Formula Engine query while using the Distinct Count measure would allow Analysis Services to use both the Storage Engine and Formula Engine. For more information, please refer to Analysis Services Distinct Count Optimization.
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]
)
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.