How to add member name in MDX query - mdx

I have just started to work with OLAP Cubes. I have some questions about MDX queries. I have a query like:
WITH
MEMBER [Balance].[NegEXPENSE] AS '-[Balance].[Type].[EXPENSE]'
SET BalanceTypeSet AS {[Balance].[Type].[INCOME], [Balance].[NegEXPENSE]}
MEMBER [Balance].[TypeSum] AS AGGREGATE(BalanceTypeSet)
SELECT {Measures.[Sum]} ON COLUMNS,
{[Balance].[Type].[INCOME], [Balance].[Type].[EXPENSE], [Balance].[TypeSum]} ON ROWS
FROM [Balance Cube]
The result of this query like:
RESULT
This result doesn't have a name of the last row(TypeSum). How can I add a name for TypeSum?
Thanks.

You need to add calculated dimension member, try this:
WITH
MEMBER [Balance].[Type].[TypeSum] AS AGGREGATE(BalanceTypeSet)
SELECT {[Measures].[Sum]} ON COLUMNS,
{[Balance].[Type]} ON ROWS
FROM [Balance Cube]

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];

Filtering dimensions in MDX inside a SUM

I am new to MDX expressions and I am trying to create one that sums the value of a given measure filtered by dimensions.
In my database I have several different dimensions that have the same name: "Answer". To sum them up, I have created the query below:
WITH MEMBER Measures.Total as SUM ({[Activity].[Activity].&[14], [Activity][Activity].&[22]},
[Measures].[Activity time])
SELECT NON EMPTY [Measures].[Total] on COLUMNS from [My Analytics]
This query works, however I had to use the "&[14]" and "&[22]" statments that correspond to two different "Answer" dimensions.
Since I have more than two dimensions with the same name, is there a way to rewrite the query above in a way that I would select all these dimensions without having to add their unique ID? For example, I would re-write the query as something like this:
WITH MEMBER Measures.Total as SUM ({[Activity].[Activity].&["Answer"]},
[Measures].[Activity time])
SELECT NON EMPTY [Measures].[Total] on COLUMNS from [My Analytics]
Is this possible?
Thanks!
You can use the Filter function as following:
with
set [my-answers] as
Filter( [Activity].[Activity].members,
[Activity].[Activity].currentMember.name = 'Answer'
)
member [Measures].[Total] as Sum( [my-answers] )
...

Add blank columns in MDX query

How to add blank columns in MDX Query?
I have tried all possible options such as adding member and all, but when I am trying to cross join the new member, i get MDX errors. Please guide me through this.
Thanks
We need following MDX format and need blank columns in the MDX Query
My current MDX is
WITH
SET [PL_AsOfDate_XXX] AS
Distinct(
Hierarchize({
[AsOfDate].[ALL].[AllMember].[31-05-2013], [AsOfDate].[ALL].[AllMember].[30-05-2013]})
)
SET [PL_AsOfDate_XXX2] AS
Distinct(
Hierarchize({
[AsOfDate].[ALL].[AllMember].[31-05-2013]})
)
MEMBER [Book].[Books] AS
Aggregate({[Book].[ALL].[AllMember].[YYY], [Book].[ALL].[AllMember].[ZZZ]})
SELECT
NON EMPTY DrilldownLevel({[LBook].[ALL].[AllMember]}) ON ROWS,
NON EMPTY {Crossjoin({[Measures].[1D]}, [PL_AsOfDate_XXX]), Crossjoin({[Measures].[10D]}, [PL_AsOfDate_XXX2])} ON COLUMNS
FROM [Cube]
WHERE ([Book].[Books], [Type].[Type].[TOTAL])
With
Member Something as 1+1
member BlankColumn1 as null
member BlankColumn2 as null
member BlankColumn3 as null
Select (
{
Something,
BlankColumn1,
BlankColumn2,
BlankColumn3
})
on columns
from [UKM Trading]

Combine TOPCOUNT, and BOTTOMCOUNT resultset in MDX

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]

MDX query- How do I use a member property?

I'm a complete newb to MDX / OLAP, "data warehousing" in general. I have the following MDX query and would like my results to display the month's number (1 = January, 12 = December). Luckily, the cube creator created a member property named "Month Number Of Year"
When I try to run the query, I get the following...
"Query (4, 8) The function expects a tuple set expression for the 1 argument. A string or numeric expression was used."
Any suggestions for fixing this?
Thanks!
WITH
MEMBER [Measures].[Tmp] as '[Measures].[Budget] / [Measures].[Net Income]'
SELECT {[Date].[Month].Properties("Month Number Of Year")} ON COLUMNS,
{[Measures].[Budget],[Measures].[Net Income],[Measures].[Tmp]} ON ROWS
FROM [AnalyticsCube]
It looks like you're trying to get an attribute? If so the syntax looks like:
WITH
MEMBER Measures.ProductKey as [Product].[Product Categories].Currentmember.Properties("Key")
SELECT {Measures.ProductKey} ON axis(0),
[Product].[Product Categories].Members on axis(1)
FROM [Adventure Works]
http://www.ssas-info.com/analysis-services-faq/27-mdx/167-how-can-i-get-attribute-key-with-mdx
So if your original MDX is close, try:
[Date].[Month].CurrentMember.Properties("Month Number Of Year")
Or do you mean the date dimension has this as a member, in which case you'd use:
[Date].[Month Number Of Year]