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.
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])
(This is a mock of my actual setup to help me figure out the problem.)
I have one fact table and one dimension table, linked by an id field.
My goal is to make a measure that sums up all "thing_count" (integer) values in my cube.
If the user splits by nothing, it should show the total "thing_count" for all records in the fact table. If it's split by "category_name" from the dimension, it should show the total "thing_count" for each category.
I tried to achieve this by creating a SUM measure in my cube:
It works, but not in the way I intend it to
It always shows (null) unless I drag in the "id" field from the dimension.
Measure only:
Measure and category:
Measure, category, and id:
How can I make the measure show the value without keys needing to be present?
Edit:
For GregGalloway's request (I've edited the names so the screenshots are easier to follow):
One common explanation for this behavior (no aggregation) is that you have inadvertently commented out the CALCULATE; statement in your MDX script in the cube. Please check that statement is still present.
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 have a requirement where report should show measures as "not applicable" if one selects a attribute which is not linked to that measure Group.
1) unrelateddimesnion= 'false' is not solving my problem because i have few default members.
2) I could able to show measure value as "not applicable " by Writing this MDX statement
([Customer].[customer name].[customer name], [measures].[sales forecast]) = 'not applicable'
but with this i have to repeat the same line for each and every attribute present in the dimension ( and also for each and every measure present in the measure Group)
can someone help me Writing the MDX for entire dimension instead for individual attribute. Thanks in advance.
Kind Regards
Mah
Bad news! An MDX script on your cube can't reference such a sub-cube in a simple way. You may have seen the LEAVES(dimension) function for a scope statement but that won't work when one attribute in a dimension has the [All] level and another has a selection. (That is to say the function returns the leaves of the dimension's key attribute). What you can do is use nested scope statements with the outer one filtering down to the list of measures you want to affect. That will at least save you typing a formula num_attributes * num_measures times. The scope statement may even accept the MEASUREGROUPMEASURES function. (When I last used that it only returned visible measures but that's probably what you want anyway.)
It may be easier to link measure group and dimension and let your data sit on the UNKNOWN member. (Or an explicit dummy member.) Then filters against or slices to real customer hierarchy values will exclude your [Sales Forecast] rows and show it as null. That's not something I've done and it'll have ramifications for error processing and you'll have to allow users sight of the unknown or dummy member. So recommend you play with the idea before you rely on it.
I hope this helps some.
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.