I'm creating a member in an mdx query containing my slicer information and the last one is my measure. When I add a set to my tuple (for having multiple slicers on one dimension), i get this error.
This function expects a string or numeric expression for the argument.
A tuple set expression was used.
When I add one of the 2 members of my set to my tuple, I don't get this error.
what does this mean, I don't really know what to make of this, fundamentally there isn't a difference between adding a slicer or
A tuple is a cell. A set contains cells. A set cannot be one of the coordinates of a tuple, as the end result is not a cell (a cell is given by 1 and ONLY one member in each dimension, where unspecified members will be taken to be either the All member or the Default member.
The way around it is by creating calculated members:
With Member [Time].[Current Period] as { [Time].[2013], [Time].[2014] }
Select (... your query here ...)
Where ( [Products].[My product], [Time].[Current Period], ... )
In the slicer you in fact have a tuple, as in each dimension a single member is specified. The fact that the member on the Time dimension is not a "pure" member coming from a dimension table column but instead is a calculated member has no influence.
Without your actual code it is difficult to help you.
Anyway, from your question it seems you are confused with sets and tuples (e.g., you cannot add a set to a tuple). I would advise you to check a MDX tutorial explaining these basic concepts: e.g., the icCube gentle MDX introduction should be fine for that.
Related
Do you have any clues why excel is presenting more dimention members when i add measures to grid?
When there is no measure selected then there is for example 3 members visible, when I add some measure then there is 5 and with next measure there is 6 dimention members visible. All measures are non empty - there are some values. Can it be some excel setting or dimention?
I have not yet checked the mdx query from excel to the cube.
I've found that there is default member when no measure is selected so setting it will give answer for first case. In production env there is plenty of measures and without explicit setting, default is first measure from first group so it can have different nonempty set than other measure when sliced by given dimention.
But I cant figure out why adding second measure to grid also generates larger dimension member list - measures have values on every row.
I've found there can be cache problem in such case.
Excel is not key I think, in SSMS you can reproduce too.
First case - no measure -> one measure.
When no measure is selected there is deafault used by SSAS.
Deafault cube measure can be checked by:
SELECT NON EMPTY { [Measures].DefaultMember } ON COLUMNS
Changing default as null = no members in rows:
CREATE MEMBER CURRENTCUBE.MEASURES.UseAsDefaultMeasure AS NULL, VISIBLE = 1;
ALTER CUBE CURRENTCUBE UPDATE DIMENSION Measures, DEFAULT_MEMBER = [Measures].UseAsDefaultMeasure;
Changing as 0= all members in rows:
CREATE MEMBER CURRENTCUBE.MEASURES.UseAsDefaultMeasure AS 0, VISIBLE = 1;
ALTER CUBE CURRENTCUBE UPDATE DIMENSION Measures, DEFAULT_MEMBER = [Measures].UseAsDefaultMeasure;
Or you can set any other measure.
Second case - one measure -> two measures.
NON EMPTY is default excel setting in MDX queries so in my case there was overlooked 2 rows without first measure value, so empty members were eliminated. All values are set for second measure so new rows appeared.
So everything works as designed.
Usually I display a value for dimensions by using the CurrentMember.Value/caption as as an alias.
For the following query this breaks with an error along the lines of
'The hierarchy [Measures] appears in more than one axis or in an axis/axes and a slicer too'.
Which I understand.
So how do I edit/expand the query such that I see the book values on rows (normally achieved with
'WITH Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION'
and the column dimension values along the top?
(Excel image below, values white color'd out as on client site.)
SELECT
NON EMPTY ([Ccy].[Ccy].[Ccy])
ON COLUMNS ,
NON EMPTY
([Book].[Book].[Book])
ON ROWS
FROM [TraderCube]
WHERE
([Date].[Date].[ALL].[AllMember].[2019-12-12],[Measures].[JTD.SUM])
I have made more progress however this comes out staggered duplicating the row / book label at each repeated currency.
Does anyone know how I would:
1) Get the currencies along the top?
2) Have one row / book label per row?
WITH
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION
SELECT
NON EMPTY (HIERARCHIZE(([Ccy].[Ccy].Members, {[Measures].[Book_Label],[Measures].[JTD.SUM]}), POST))
ON COLUMNS,
NON EMPTY (HIERARCHIZE([Book].[Book].Members, POST))
ON ROWS
FROM[TraderCube] WHERE ([Date].[Date].[2019-12-13])"
As an update for anyone who comes across this thread/question, for me I am writing a C# layer that translates simple user words and constructs MDX. I query the remote cube and then I return a 2D array. Up until now I constructed the headerRow etc myself and I returned the row dimension labels using the MDX itself.
I have now discovered that metadata is available on the AdomoClient libraries I am using.
This tutorial has inspired me:
https://www.codeproject.com/Articles/28290/Microsoft-Analysis-Services-2005-Displaying-a-grid
It's not a direct answer to my query of getting all of the labels in MDX but it will mean I can construct my headerRow (may be more than one row as seen in Excel pivots) and populate my row labels differently using the positions property of each Axes on the set (Axes[0] is columns, Axes[1] is rows) and the Positions property has a member property too.
I have created a calculated field(Row No.), where the calculation is, Index(). Then tried to concatenate it with a field(Name) which has text data. Then I created another calculated field(Concat), where the calculation is, attr([Name])+'_'+str([Row No.]). The Concat field is showing under Measures. How can I have it as a Dimension ?
How can I create a calculated field which will make each entry in 'Name' field by adding an 'underscore' and a number to it ?
There are two possible ways to have it as a Dimension. First, the 'ATTR' is creating an aggregation, which is why it is a measure. You should be able to remove this and still concatenate with [Name]+'_'+str([Row No.]).
second, you should be able to right click on the Measure and select Convert to Discrete, then click and drag it to the Dimensions section.
You can't have a dimension based upon a call to a table calc function (such as index()), nor an aggregate function (such as sum()).
You can however convert a measure to discrete, which will allow you to use it to create headers in your view.
There is a good reason for this restriction. Dimensions are used early in the order of operations to partition data rows into blocks. They are effectively the group by clause in a SQL statement. Aggregate functions such as sum() are then applied to each partition, and table calcs are applied even later to the aggregated query results. So you can't use those results to go back in time and generate a different partition of your data rows -- which is why Tableau won't allow you to make those fields into dimensions.
Luckily, once you understand the order of operations, you can usually find other ways to get effect you need.
As a footnote, you can create a dimension based on a FIXED LOD calculated field that includes calls to an aggregate function -- such as { FIXED [Region] : CountD([Customer]) }.
I have a date dimension I want to filter on. I use MDX Range (:) operator for that. The problem is it appears that range bounds must be valid members of a set. I have IntDate attribute in my Date dimension, and it's an integer in the YYYYMMDD format. When I browse the dimension, there are 20120705 and 20120706 values, but not 20120704 or 20120707. Still, as far as range is concerned, both 20120705:20120706 and 20120704:20120707 encompass 20120705 and 20120706 and I hoped would return 20120705 and 20120706. But when first one works as expected, second returns empty set. The reason I need loose range to work is that users may enter date range that is not based on data in the dimension. How can I make this work?
The one that works:
The one that returns empty set.
Thank you,
Vlad.
Since your 20130707 member doesn't exist, the cube can't know where it was supposed to go.
It seems odd that you have a date dimension that doesn't contain all of the days in a month. I would suggest repopulating your date dimension so that it has all dates. You can get a fully populated date dimension from the Azure data market if you are using a tabular cube. If you are using multidimensional, you can have SSAS generate one for you. If you have parameters built off of dates, you can limit the list to populate them to show only the data for which there are measures using Exists.
I also wonder why you want users to enter dates rather than choose dates from a valid list. How do you handle the errors when they enter a value that is simply invalid? It seems the easiest/safest choice is to give them the list of dates from which to choose. If they are entering things that don't have data and you have error handling, the result should be the same as if they choose from a valid list.
That being said, you should be able to so something like the below. I check to see if the date is a valid member. If it isn't I substitute the first valid member I find in the list of members (you could choose your own date and insert it there). For the end of the range, I find the last valid member (again, you can substitute your own value).
{Iif(Count(Exists([Date].[Int Date].members, [Date].[Int Date].[20130704]))>0,[Date].[Int Date].[20130704], [Date].[Int Date].firstchild):
Iif(Count(Exists([Date].[Int Date].members, [Date].[Int Date].[20130707]))>0,[Date].[Int Date].[20130707], [Date].[Int Date].lastchild)}
I have a fairly complex calculated measure that works perfectly for each row of data from a cube. However, I then need a sum of those values line by line. But the behavior of calculated measures seems to be in the subtotal and total lines in Excel, it's performing the calculation again instead of summing the previous rows. Is there a way to have a calculated measure that performs it's calculation on each row, but they does a traditional SUM in the total and subtotals?
Thanks in advance.
A calculated measures does not aggregate; it will be computed each time.
There is a solution, but that is really ugly:
You would have to use something like
SCOPE([dim1].[hier1].[All]);
[Measures].[MyCalculatedMeasure] = Sum([dim1].[hier1].[bottomlevel].Members, [Measures].[MyCalculatedMeasure]);
END SCOPE;
for all hierarchies of all dimensions, be it an attribute or user hierarchy, replacing dim1, hier1, bottomlevel as appropriate.
You need to immitate real measure behavior for calculated member. Make dummy real measure with Null value and then use Scope to define your formula on the granullarity level. For more detailed answer see here: http://blog.crossjoin.co.uk/2013/05/29/aggregating-the-result-of-an-mdx-calculation-using-scoped-assignments/
I found the easiest way to do this:
Create a new named calculation in the appropriate measure table in your DSV. (Right click, add new named calculation and set its expression to be CAST(NULL as [insert appropriate data type]).
Add the new named calculation as a measure in your cube.
In the calculations area of your cube switch to script view and add the following:
({[Measures].[The named calculation you created in step 1]},Leaves())=Your complex calculation;
This sets the definition at the leaf level and all the aggregations work perfectly.
Ref: http://sqlblog.com/blogs/mosha/archive/2005/02/13/performance-of-aggregating-data-from-lower-levels-in-mdx.aspx