What´s wrong with this MDX query? - mdx

I tried to execute this query and i can´t understand what´s wrong with it.
SELECT {[Measures].[Internet Sales Amount],
[Measures].[Reseller Sales Amount]} ON COLUMNS,
[Product].[Product].[Product].Members ON ROWS
FROM [AdventureWorks2008R2]
I get error message:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'Measures'.
I thought it was the "{}" and changed them for "()" instead, then i got this message:
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ','.
--- EDIT
I was at the wrong place writing the query but now i get this other message:
Executing the query ...
Query (3, 10) The MEMBERS function expects a hierarchy expression for the argument. A member expression was used.
Execution complete
The query:
SELECT {[Measures].[Internet Sales Amount] ,
[Measures].[Reseller Sales Amount]} ON COLUMNS,
{[Product].[Product].[Product].Members} ON ROWS
FROM [Adventure Works]

nothing wrong with query.
i think you run the query against sql db .not Analysis service db
.please right click on ssas db adventurework an run the query.

The brackets are breaking the query in the first instance, since the statement is not valid SQL. The bigger problem is that you aren't writing SQL, you are writing MDX, so your syntax is wrong.
Did you want to have a Hierarchize in there somewhere? Also, are you selecting from a database, or a table? (I can't tell, but you need to change the end From [] to select from what you want.)
SELECT
Hierarchize({[Measures].[Internet Sales Amount], [Measures].[Reseller Sales Amount]}) ON COLUMNS,
Hierarchize({[Product].[Product].[Product].Members}) ON ROWS
FROM [AdventureWorks2008R2]

i think the problem is with
this expression
[Product].[Product].[Product].Members
and espcially second and third '[Product]'
i think in your code maby you put some space or ..[Product ] the Product.
check for correctnes
i suggest drag this member from Cube explorer .
maybe it helps!!

Related

How to use multi level hierarchy names in MDX query

I need to use the dimension field under the 2 hierarchies i.e., one hierarchy under another hierarchy in the MDX query.
Am having the below hierarchies/data in my cube:
I need to use the highlighted [Country] field in the MDX query.
Please find the query I have tried.
WITH MEMBER [Measures].[Expression1] AS [Geography].[Geography].[Country].currentmember.membervalue
select [Measures].[Expression1] on Columns from [Adventure Works]
Am getting below error:
But when am using the same syntax for a single hierarchy it works.
Please find the query and its result
WITH MEMBER
[Measures].[Expression1] AS [Geography].[Country].currentmember.membervalue
select [Measures].[Expression1] on Columns from [Adventure Works]
Am expecting the same result using the two hierarchy names of the field.
Can anyone please guide me to get the required value?
I don't think you need WITH or currentmember or membervalue` at all.
These two queries ought to list you the items within each hierarchy's level...
select {[Geography].[Country].members} on Columns from [Adventure Works]
select {[Geography].[Geography].[Country].members} on Columns from [Adventure Works]

Reading Data from different dimension when creating MDX queries in SSAS

I am trying to create a query but it utilizes two different dimensions. I receive this error "Members, tuples, or sets must use the same hierarchies in the function." I've run this with/without the brackets in the row section and got the same error. How do I resolve this issue?
Error Message/MDX Query
You are using two different hierarchies of the same dimension [Dim Course] in the tuple which is not allowed.
You will have to change your query, something like this should work:
select {[Measures].[Dim Course Count],[Measures].[Dim Semester Count]} on 0,
{([Dim Course].[Course Code].[Course Code], [Dim Semester].[Academic Year].[Academic Year]) } on 1
from [CCSE-DM]
where [Dim Course].[Level1].[Level1]

Simple Calculated Member Running for Forever - MDX

I am facing very strange issue with MDX (SSAS 2014), on which simplest calculated member is taking forever to execute. Could someone please help me to understand why i am facing this issue. If i not use calculated member everything works fast and result comes in seconds. When i remove Producer attribute, query performances well.
Below is the complete query.
WITH
MEMBER Measures.AsOfDate AS ("[Policy Effective Date].[Year-Month].[Date].&[2018-01-04T00:00:00]")
MEMBER Measures.YTDPremium AS AGGREGATE (YTD(STRTOMEMBER(Measures.AsOfDate)), [Measures].[Written Premium])
SELECT NON EMPTY
{
Measures.YTDPremium
} ON COLUMNS, NON EMPTY
{
(
[Program].[Program Name].[Program Name]
,[Insuring Company].[Insuring Company Name].[Insuring Company Name]
,[Line Of Business].[Line Of Business].[Line Of Business]
,[Producer].[Producer Name].[Producer Name]
)
} ON ROWS
FROM [Premium]
Try understand what the following part does in your query
NON EMPTY { ( [Program].[Program Name].[Program Name]
,[Insuring Company].[Insuring Company Name].[Insuring Company Name]
,[Line Of Business].[Line Of Business].[Line Of Business]
,[Producer].[Producer Name].[Producer Name]
) } ON ROWS
In the above MDX you are telling the server to take a cross product of all values of "Programs", "Line Of Business" and "Producer Name". So lets say you have 4 values of programs , 3 values of line of business and 2 values of producer name. The total combinations are 4*3*2=24
Now the "Non empty" removes any combinations that are not present in your dataset. This is done by removing all rows that have "Null" value in column value.
Your measure is returning value irrespective if that combination exists or not. You can modify your Calculatedmeasure to return value only in the case if the combination is valid. This can be achived by checking an actual measure for that combination
Edit: based the below example is based on the comment
In the below example i am trying to get the internet sales amount categories and components
select
{ [Measures].[Internet Sales Amount] }
on columns,
(
[Product].[Category].[Category],
[Customer].[Country].[Country]
)
on rows
from [Adventure Works]
Result
Now add "Non empty" to the query and observe the results.
Results
Now lets add calculted measure that returns "hello". Notice how the non empty clause is ineffective.
Now modify the code make the calculated measure check other measures for null
with member measures.t as
case when [Measures].[Internet Sales Amount] = null then null else "hello" end
select
{ [Measures].[Internet Sales Amount] ,measures.t }
on columns,
non empty
(
[Product].[Category].[Category],
[Customer].[Country].[Country]
)
on rows
from [Adventure Works]
Result
The bottom line: Because of cross product your result is so huge that SSAS is having hard time handling it.

MDX currentmember/IS inconsistent?

I have three queries to filter by a member using the currentmember function. When the filter is applied to the hierarchy that has the member I want to filter by, I can match the members using the IS operator and get the correct result. It does not work though when the filtered set and the member are in different hierarchies. Yet, I can get the filtered results correctly for the second case if instead of objects comparison I just do a caption comparison. The examples use the AdventureWorks database.
This query is working as expected with the IS operator:
select non empty [Measures].[Reseller Sales Amount] on 0,
Filter (NonEmpty({[Geography].[Country].[Country].ALLMEMBERS * [Geography].[City].[City].ALLMEMBERS}), [Geography].[City].Currentmember IS [Geography].[City].&[Seattle]&[WA]) on 1
from [Adventure Works]
This one uses a caption comparison (different result, as expected)
select non empty [Measures].[Reseller Sales Amount] on 0,
Filter (NonEmpty({[Geography].[Country].[Country].ALLMEMBERS}), [Geography].[City].Currentmember.MEMBER_CAPTION = 'Seattle') on 1
from [Adventure Works]
This one though, which should produce the same result as the previous query, does not return anything:
select non empty [Measures].[Reseller Sales Amount] on 0,
Filter (NonEmpty({[Geography].[Country].[Country].ALLMEMBERS }), [Geography].[City].Currentmember IS [Geography].[City].&[Seattle]&[WA]) on 1
from [Adventure Works]
Thanks.
In fact, this is a bit strange. For me, the most surprising result is the second one. No reference in the set to be filtered to the city, and nevertheless, a filter is applied. I would think the reason for the second result is that somehow "implicit overwrite" kicks in.
And probably, the second and third case are treated differently as the optimizer somehow choses different ways to interpret the statement. Normally, string operations like the reference to caption are less efficient than the IS operator which works on object identity.
It looks like most comments confirm that the result of the second query is a bug. Some more comments here in this other thread

MDX Query to Produce Revenue by Top N Advertiser

I need to create a report using SSRS 2008 that will show the top 10 advertisers by revenue. I wrote the MDX query in management studio as follows:
Select [Measures].[Value] on 0,
non empty
generate([Dim Industry].[SK Industry ID],
topcount([Dim Advertiser Branch].[Advertiser],
[Measures].[Value],bdesc),10)
on 1
from FuseCube
I get a parse error stating:
Query (5, 20) An expression was expected for the function argument and no expression
was detected.
My goal is to report the top 10 Advertisers, their associated branch and industry by Value (aka revenue). The remaining ranked advertisers should go into an "others" category so that I can sum the value and get a grand total.
How should I restructure the above MDX query to produce desired results? Is it advisable to create the above query as a named set as it will be used repeatedly?
TOPCOUNT syntax incorrect:
topcount([Dim Advertiser Branch].[Advertiser], [Measures].[Value],bdesc),10)
Vs
TopCount([Dim Advertiser Branch].[Advertiser], 10, [Measures].[Value]))