Showing measure values as "not applicable" which are not related to dimensions - ssas

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.

Related

TABLEAU Totals not matching what's in view

I've been dealing with this issue in various ways throughout my time with this dataset in Tableau.
As you can see, the Total count of properties for each city is including properties that have been successfully filtered out of view. Why? The dyn.RANKED Profitable Investments (grouped) variable on the Filter shelf is an attempt to double down on the same as the first line of the Calculated Field - to ignore the unwanted properties in each city. The view ignores them, but the totals do not.
If the Watershed Property pill is removed from the Rows shelf, then the dyn.NumProps_in_City results shown on the table are each the same as the Totals you see here (i.e., despite the first line of the calculated field, properties that do not meet that opening condition are being counted)...despite the view with the Watershed pill knowing not to show them.
Also if the Watershed Property pill is removed from the Rows shelf, then the dyn.RANKED Profitable Investments (grouped) variable on the Filter shelf suddenly only has one category to choose from (i.e., 'INVEST') if you go to edit the filter. Which would be great since that's the category I care about, but not if the counts are including things that are not in that category despite the filter.
Messing around with Include, Exclude, and Fixed in the calculated field doesn't seem to work here since I can't figure out how to get around various aggregate/non-aggregate and/or ATTR errors no matter where I place them. Plus, my incorrect counts are not suffering from an LOD issue - the LOD is correct - it's an issue of not consistently filtering out the unwanted rows at the desired LOD.
Please advise!
Thanks,
Christian
It seems that dyn.Ranked calculated field calculates the value prior to filtering. This may happen if you have used any LOD calculations in the syntax.
Simply right click such fields on filters shelf and click add to context. This will cause LOD calculations to calculate after the filtering.
see this link, the context filters are above the LOD calculations, in order of precedence; but measure filters are below the LOD calcs. Therefore if measures are used as filters, these have to be added to context so that their order of precedence is above such calculations

MDX multiple conditions filter on multiple dimensions

I am relatively new to MDX, about a month or so, and I am now writing MDX queries against a remote cube I also work on (Java 8 ActivePivot).
This query works when they are ORs, but when I add parentheses and change that first OR to an AND it works, kind of, but drops the measure resulting in the CDR and BOOK dimensions coming back correctly. Can someone with more MDX knowledge tell me what I have missed or do not yet know?
WITH
Member [Measures].[CDR_Label] AS [CDR].[CDR].CURRENTMEMBER.MEMBER_CAPTION
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION
SELECT
NON EMPTY
{[Measures].[CDR_Label],
[Measures].[Book_Label],[Measures].[RepoRate.LATEST]}
ON COLUMNS,
NON EMPTY
FILTER(
([CDR].CHILDREN,[Book].CHILDREN), (LEFT([CDR].[CDR].CURRENTMEMBER.MEMBER_CAPTION,1) = "8") AND
(LEFT([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION,2) = "ST" OR
RIGHT([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION,4) = "CIES"))
ON ROWS
FROM [TraderCube]
WHERE ([Date].[Date].[2019-10-23])
And here the query before I changed it, with OR OR etc which works. I wanted the above to return only the CDR beginning with 8, which it does, but it loses the measure (and also breaks my headers - as this is actually being fired from inside an xll / custom Excel function, to a dll calling the remote cube using AdomdClient package as I am building a very custom plugin - Essentially the ability for users to use simple words/from enumerations presented and I then translate and construct MDX in C# to fire at the cube. Data comes back and I send 2D arrays back to Excel :)).
WITH
Member [Measures].[CDR_Label] AS [CDR].[CDR].CURRENTMEMBER.MEMBER_CAPTION
Member [Measures].[Book_Label] AS [Book].[Book].CURRENTMEMBER.MEMBER_CAPTION SELECT NON EMPTY {[Measures].[CDR_Label],[Measures].[Book_Label],[Measures].[RepoRate.LATEST]}
ON COLUMNS,
NON EMPTY
FILTER(
([CDR].CHILDREN,[Book].CHILDREN),
LEFT([CDR].[CDR].CURRENTMEMBER.MEMBER_CAPTION,1) = "8" OR
LEFT([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION,2) = "ST" OR
RIGHT([Book].[Book].CURRENTMEMBER.MEMBER_CAPTION,4) = "CIES")
ON ROWS
FROM [TraderCube]
WHERE ([Date].[Date].[2019-10-23])
Aah...ignore me!
I think I was tired and didn't see the pattern. Essentially, and I just reproduced this, if you ask for two dimension patterns that do exist with a measure, you get back the dimensions you expect (in my case 3, a real measure and two fake / labels for the dimensions to bring them all back as rows).
If there are no matches it seems to return you back what you asked for without any measures as they do not exist for the dimension combination.

SSAS OLAP Cube - Sum measure only works when keys are present

(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.

Calculated Members with multiple Attribute Hierarchy - MDX

I found this little code where it dynamically calculates TOTALs for all Dimension/Hierarchy I want.
This is close to what I need but will not work for Dimensions that have different number of Hierarchy Levels (Attribute Hierarchy). Current Code only works if there is only one Attribute Hierarchy because of CurrentMember.Parent. I could use CurrentMember.Parent.Parent for Dimension.Hierarchy that have two levels and so on but would not work for the the ones with only one Attribute Hierarchy (Level).
CALCULATE;
CREATE MEMBER CURRENTCUBE.[Measures].[Total On Hand Amount]
AS ([Measures].[On Hand Amount],Axis(1).Item(0).Item(0).Dimension.CurrentMember.Parent),
FORMAT_STRING = "#,#",
VISIBLE = 1 ;
I would like to make this MDX code work for any Dimension.Hierarchy regardless of number of Attribute Hierarchy (Level/s).
Any help is appreciated!!
You can use the ancestors function instead of parent. It takes a dimension parameter and a second parameter which shows how many levels you want to get (how deep in the tree to go). So if you know how many levels your dimension has you can use something like:
Ancestors(Axis(1).Item(0).Item(0).Dimension.CurrentMember, 5)
Instead of a number you can also add a dimension level as a second parameter. Then it will go as deep as the dimension level specified - so if you add the root dimension level it should get to there
(Axis(1).Item(0).Item(0).Dimension.Levels(0).Item(0), [Measures].[On Hand Amount])
Above gave me the correct answer, total for a measure for dynamic selection of any dimension but this MDX calculation would not work from PowerBI(DAX) report, which is merely PowerBI's limitation.
I got the TOTAL working now with this -
SCOPE(DESCENDANTS([Warehouses].[Warehouses],,AFTER));
[Measures].[Total On Hand Amount] = (ROOT([Warehouses]),[Measures].[On Hand Amount]);
END SCOPE;
I just have to repeat this SCOPE for each [Dimension].[Hierarchy] in the cube to make the TOTAL work for any selection including multiple dimensions from Power BI. It does not have dynamic functionality like Axis() did, but it yields the result I needed.
Hope this would help someone else too!!

How to get the name of invisible attributes and user defined Hierarchies using MDX?

I have a cube with some dimensions. There I have a dimension 'Product' which has some attributes and user defined hierarchies hidden. I do not know which attributes are hidden.
Is there a way to write an MDX to get the invisible attributes and user defined hierarchies?
I can get the name by other ways. But I want to know the way to get using MDX.
http://msdn.microsoft.com/en-us/library/ms145613.aspx gives an example query that reveals a member property:
WITH MEMBER [Measures].[Product List Price] AS
[Product].[Product].CurrentMember.Properties("List Price")
SELECT
[Measures].[Product List Price] on COLUMNS,
[Product].[Product].MEMBERS ON Rows
FROM [Adventure Works]
I cannot test it myself right now, but I assume that you could also write .Properties(0) or .Properties(1) to refer to properties by index, since you don't know the names. I'm not sure if there is a way to then discover the property name from the resulting cellset or not, sorry.
I'd start with looking into the DMVs for this, as you're really after metadata, not data.
http://dwbi1.wordpress.com/2010/01/01/ssas-dmv-dynamic-management-view/
They look like SQL, but run in the MDX window of SQL Management Studio, so will also run in an MSOLAP connection.
SELECT * FROM $system.mdschema_properties
That looks to be the query, a full list of members and a column identifying which are visible.
See how that works out for you.