MDX drillthrough not working with subselects - ssas

I don't have much experience with MDX and Analysis Services. I am trying to do a drillthrough and for the most part I got it right. However, there is one example that I can't figure out. When I'm using a subselect and a crossjoin the result of the drillthrough is incorrect. I ran the same query without the drillthrough clause and the result is correct. Somehow the drillthrough statement is collecting all data ignoring the subselect result. What I'm doing wrong?
The MDX query is:
DRILLTHROUGH
SELECT NON EMPTY (([Dates].[Calendar Year].&[2016]) * {[Measures].[Amount]}) ON COLUMNS
FROM (SELECT ( {[Accounts].[Account Id].&[xxxx]} ) ON COLUMNS
FROM [ExampleDW])

A sub-select isn't a normal filter can you not just re-write you script using a true filter - the WHERE clause :
DRILLTHROUGH
SELECT
NON EMPTY
[Dates].[Calendar Year].&[2016])
* [Measures].[Amount] ON COLUMNS
FROM [ExampleDW]
WHERE [Accounts].[Account Id].&[xxxx];

Related

How do I get .AllMembers of Hierarchy in olap4j?

I have an MDX query like this:
SELECT {[Gender].[Gender].AllMembers} ON COLUMNS,
{[Geography].[Country].AllMembers} ON ROWS FROM [myCube]
And I am trying to get this query as an olap4j object. I do this to set my dimension:
QueryDimension genderDim = myQuery.getDimension("GENDER");
But that produces just one column of "All Genders" and "All Geographys" respectively.
How do I get them broken down like the MDX query above?
If you switch to the MEMBERS function does that help?
SELECT
{[Gender].[Gender].MEMBERS} ON COLUMNS,
{[Geography].[Country].MEMBERS} ON ROWS
FROM [myCube];

MDX Query using DistinctCount, Except as a filter

I am new to MDX Querying and am trying to create a query that utilizes Except. I currently have one that works when i do a filter with a bunch of OR's but it is very slow.
What i want to do is count the distinct back order lines (where that doesn't equal 0) except when 2 aging codes are set. (050 and 060).
This query seems to work but is extremely slow (not using except)
DISTINCTCOUNT(filter([Product].[Segment - Line - Types].[Product].members,
(([Measures].[BackOrderLineCount], [Aging].[AgingCode].[Aging].&[005] ) OR
([Measures].[BackOrderLineCount], [Aging].[AgingCode].[Aging].&[010] )OR
([Measures].[BackOrderLineCount], [Aging].[AgingCode].[Aging].&[020] )OR
([Measures].[BackOrderLineCount], [Aging].[AgingCode].[Aging].&[030] )OR
([Measures].[BackOrderLineCount], [Aging].[AgingCode].[Aging].&[040] ))))
I was hoping if i switched it to "EXCEPT" it would speed it up...
Any help would be appreciated i've been searching all day for this.
You don't really need to use a FILTER function for this requirement. Also, the minus operator is as good as EXCEPT while being more handy.
You should be looking at obtaining tuples of products and aging code which have a value for back order line.
DISTINCTCOUNT([Product].[Segment - Line - Types].[Product].members *
NonEmpty(
([Aging].[AgingCode].[Aging].CHILDREN - {[Aging].[AgingCode].[Aging].&[50], [Aging].[AgingCode].[Aging].&[60]}),
[Measures].[BackOrderLineCount])
)
The NonEmpty function returns those aging codes which have back order lines.
If you had to use EXCEPT, the code would look like below:
EXCEPT
(
[Aging].[AgingCode].[Aging].CHILDREN, {[Aging].[AgingCode].[Aging].&[50], [Aging].[AgingCode].[Aging].&[60]}
)

MDX WHERE vs FILTER options

I have a query in which I need to do some filtering. I can do it in a subcube, but I am wondering if I could do this in a WHERE clause without subcube. I think this solution would be faster/cleaner. I need to filter out product models with IB>0 in last month, this is my solution so far (only part of a query):
SELECT {[Measures].[AFR],[Measures].[IB]} ON COLUMNS,
([dim_ProductModel].[ODM].children)*[Dim_Date].[Date Full].children ON ROWS
FROM
(
SELECT
FILTER([dim_ProductModel].[Product Model].children,
([Measures].[IB]*[Dim_Date].[Date Full].&[2014-04-01]>0)) ON COLUMNS FROM
[cub_dashboard_spares]
)
however, I would prefer to have it in one query without subquery something like this (its not working though):
SELECT {[Measures].[AFR],[Measures].[IB]} ON COLUMNS,
([dim_ProductModel].[ODM].children)*[Dim_Date].[Date Full].children ON ROWS
FROM
[cub_dashboard_spares]
WHERE FILTER([dim_ProductModel].[Product Model].children,
([Measures].[IB]*[Dim_Date].[Date Full].&[2014-04-01]>0))
I get some error message kind of:
he MDX function CURRENTMEMBER failed because the coordinate for the ... contains a set..
I basically understand why is he not accepting is as in an WHERE clause I should be more specific but I wonder if there is some possibility to rewrite it so that it works.
I don't want that ProductModel appears in the results set.
SELECT {[Measures].[AFR],[Measures].[IB]} ON COLUMNS,
([dim_ProductModel].[ODM].children)*[Dim_Date].[Date Full].children ON ROWS
FROM
[cub_dashboard_spares]
WHERE
({[dim_ProductModel].[Product Model].children},
[Measures].[IB],
PERIODSTODATE(
[Dim_Date].[Date Full], //<<needs to be a level from your Dim_date
[Dim_Date].[Date Full].&[2014-04-01]) //<<needs to be a member from the levelyou have used in above argument
)

MDX Query Join Two Dimensions

I have an MDX query as follows:
WITH
MEMBER [MatCode] AS [Product].[Material]
SELECT
([MatCode]) on 0,
([Activity].[ActivityCode].[T-50051151]) ON 1
FROM
[Cube]
This returns a value such as:
MatCode
T-50051151 Null
Which tells me it is not joining the activity code to the description when I know they match up
How can I correct my MDX query to join activity code to material?
thanks
Why not try something like the following to look for areas of the cube with data? You'll can use the WHERE clause to slice by a specific measure in your cube.
SELECT
{[Activity].[ActivityCode].[T-50051151]} ON 0,
//NON EMPTY //<<include to hide nulls
{[Product].[Material].members} on 1
FROM
[Cube]
WHERE
([Measures].[someMeasure])
Your query returns the _ default _ value / cell for the tuple :
( [Activity].[ActivityCode].[T-50051151], [Product].[Material].defaultMember )
as well as the .defaultMember for every other dimension not mentionned in your query. There is nothing wrong with it.

Adding a filter to a MDX query

I'm new to SSAS and need help with what would be equivalent to a where clause in SQL and I'm sure an easy answer for a MDX regular.
I have this pulling values for a multiple select parameter list in report builder but I need to filter out the contracts based on what project the user is currently viewing. Here is the query that is pulling all the values correctly.
WITH MEMBER [Measures].[ParameterCaption] AS [dimContracts].[ContractName].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS [dimContracts].[Contract Name].CURRENTMEMBER.UNIQUENAME
SELECT {[Measures].[ParameterCaption],
[Measures].[ParameterValue]} ON COLUMNS,
[dimContracts].[Contract Name].Children ON ROWS
FROM [cubeProjectEntities]
I need to add what would be equivalant to:
WHERE dimContracts.[Project Id] = 1
I've added which produces the correct filtered set but from here I don't know how to use the report parameter to get it to work. Every time I test it just gives and empty dataset. I have the parameter just printing on the page so I know that it is set correctly.
WHERE [dimContracts].[Project Id].[1]
This does not work:
WHERE [dimContracts].[Project Id].[#ProjectId]
And then in Report builder I will pass a parameter to the query to replace the 1 for #projectId.
Thanks for any help!
WITH MEMBER [Measures].[ParameterCaption] AS [dimContracts].[ContractName].CURRENTMEMBER.MEMBER_CAPTION
MEMBER [Measures].[ParameterValue] AS [dimContracts].[Contract Name].CURRENTMEMBER.UNIQUENAME
SELECT {[Measures].[ParameterCaption],
[Measures].[ParameterValue]} ON COLUMNS,
[dimContracts].[Contract Name].Children ON ROWS
FROM [cubeProjectEntities]
Where (STRTOMEMBER(#projectid))
In MDX, the where clause is a slicer. Here's a good article about the differences between SQL and MDX.
Here's a link about using SSRS parameters with MDX queries. You'll actually want to pass the entire member name to the query rather than just the value (ex: [DimContracts].[Project ID].[1])