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];
Related
I need some help with MDX query which returns the count of leaves nodes for a selected node.
Query1 :
Select { {[Dimension1].&[Member1]},{Descendants({[Dimension1].&[Member1]},,LEAVES)} } Dimension Properties [Parent_Unique_Name] On Columns
From RepCube Where ({[attribute1].&[attrmember1],[attribute1].&[attrmember1]},([dimension2].&[1],[dimension3].&[1]))
Query2 :
With MEMBER [Dimension1].[3] AS 'COUNT({{[Dimension1].&[Member1]},{Descendants({[Dimension1].&[Member1]},,LEAVES)}}, EXCLUDEEMPTY)'
SELECT {[Dimension1].[3]} ON 0 FROM RepCube
Where ({[attribute1].&[attrmember1],[attribute1].&[attrmember1]},([dimension2].&[1],[dimension3].&[1]))
The count query Query2 should give the same count as query1 resultset count.
But it is not. Here attribute1 belong to Dimension1 only.
My assumption is that because attribute1 belong to Dimension1, count is not giving correct result. But the first query Query 1 is filtering the results correctly.
Please help me in fixing the second query to give the same count as Query1.
You need to use existing keyword to force your calcuated member to evaluate within your where clause. Use this
COUNT(existing {{[Dimension1].&[Member1]},{Descendants({[Dimension1].&[Member1]},,LEAVES)}}, EXCLUDEEMPTY)
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
)
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.
I've just started to learn MDX and i want to do a query like that:
filter data by the cost ( i've already made that query but without the sum) like that:
SELECT [Measures].[SumOfSelled] ON 0,
FILTER ([From].[From].[City].members, [Measures].[SumOfSelled]>7000) ON 1
FROM [BI-Avia]
It's working
and it is OK
BUT!!!
I need also to show the sum of filtered elements under this filtered result by cities
I know how to find it separately:
with member [Measures].FilteredSum as sum(filter([From].From].City].members,Measures].SunOfSelled]>7000),Measures].[SumOfSelled])
select{SumOfSelled} on 0
from [BI-AVIA]
But i have to show this together!! The SUM under Filtered! two in one! I need youe help! I think it's very clear for you!!!
Just define the calculated member on the [From].[From] hierarchy and then combine both queries, using a union of sets (abbreviated with + in MDX):
with member [From].[From].FilteredSum as
sum(filter([From].[From].City].members, Measures].SumOfSelled]>7000))
SELECT [Measures].[SumOfSelled]
ON 0,
FILTER ([From].[From].[City].members, [Measures].[SumOfSelled]>7000)
+
{ [From].[From].FilteredSum }
ON 1
FROM [BI-Avia]
You could possibly define the filter as a set in the WITH clause, which would avoid that Analysis Services evaluates it twice.
I am new to MDX, and have a simple requirement which would be easy to do with SQL, but I would like to accomplish this with MDX.
I would like to combine the result, of 2 queries, so when quering the cube, I only send over 1 query.
select topcount( [Fact].[Year].children, 1,[Measures].[MoneyIn]) on columns
from [Cube]
and also this MDX query, to get the least money in, for a period of years.
select bottomcount( [Fact].[Year].children, 1,[Measures].[MoneyIn]) on columns
from [Cube]
Is there an easy way to accomplish this with MDX? Ideally I would have something :
MaxValue MinValue
10k -10k
Thanks! All help appreciated!
You could write your query a few different ways. This puts the counts in one column:
SELECT [Measures].[MoneyIn] ON COLUMNS,
{TOPCOUNT([Fact].[Year].children,1, [Measures].[MoneyIn]),
BOTTOMCOUNT([Fact].[Year].children,1, [Measures].[MoneyIn])} ON ROWS
FROM [Cube]
This is closer to your output but without the named columns
SELECT [Measures].[MoneyIn] *
{TOPCOUNT([Fact].[Year].children,1, [Measures].[MoneyIn]),
BOTTOMCOUNT([Fact].[Year].children,1, [Measures].[MoneyIn])
} ON COLUMNS
FROM [Cube]