SSAS 2014 Trying to write a simple MDX query to slice by column not just by row

im Using Analysis Service for SQL Server 2014. im trying to write a simple query that cuts the amount both by Month on the row level and Vessel Tag on the column level. this get me row just fine, the second i try to cut the amount by column  [Voyage].[Vessel Tag] i get the below error. Whats the correct MDX syntax to slicing it by  [Voyage].[Vessel Tag] for column?

SELECT NON EMPTY { [Measures].[TCE] } ON COLUMNS,
              NON EMPTY { ([Date].[Month].[Month].ALLMEMBERS ) }  ON ROWS
FROM ( SELECT ( { [Date].[Year].&[2017] } ) ON COLUMNS
FROM [cube]) WHERE ( [Date].[Year].&[2017] )

"The query cannot be prepared: The query must have at least one axis.
The first axis of the query should not have multiple hierarchies,
nor should it reference any dimension other than the Measures dimension..
Parameter name: mdx (MDXQueryGenerator)"
Paul MaurielloSoftware Programmer Developer Analyst EngineerAsked:
Who is Participating?
 
Pawan KumarDatabase ExpertCommented:
One workaround for this...

Open the EXCEL -> connect to the cube -> get the data in one sheet -> Create the PIVOT as per your need -> then get the MDX query..

Refer -
http://sqlblog.com/blogs/marco_russo/archive/2007/01/18/display-the-mdx-query-of-an-excel-2007-pivottable.aspx
http://olappivottableextend.codeplex.com

you need to download the OLAP Pivot Table Extensions form http://olappivottableextend.codeplex.com ...
0
 
Paul MaurielloSoftware Programmer Developer Analyst EngineerAuthor Commented:
Thank you for the quick response. I did exactly that prior to posting but the resulting MDX query produced an error when I run it in the Management Studio. Does this MDX query need to be tweaked for SSMS compatibilty?

SELECT NON EMPTY Hierarchize({DrilldownLevel({[Voyage].[Vessel Tag].[All]},,,INCLUDE_CALC_MEMBERS)})  ON COLUMNS ,
             NON EMPTY Hierarchize({DrilldownLevel({[Date].[Month].[All]},,,INCLUDE_CALC_MEMBERS)})  ON ROWS
 FROM (SELECT ({[Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Marcinko],
                             [Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Holway],
                             [Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Franklin],
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Marcinko],
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Leong],
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Holway],
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco]}) ON COLUMNS  
FROM [cube]) WHERE ([Date].[Year].&[2017],[Measures].[TCE])


"The query cannot be prepared: The query must have at least one axis. The first axis of the query should not have multiple hierarchies, nor should it reference any dimension other than the Measures dimension... Parameter name: mdx (MDXQueryGenerator)
0
 
Pawan KumarDatabase ExpertCommented:
How about this ?

SELECT NON EMPTY Hierarchize({DrilldownLevel({[Voyage].[Vessel Tag].[All]})})  ON COLUMNS , 
             NON EMPTY Hierarchize({DrilldownLevel({[Date].[Month].[All]})})  ON ROWS 
 FROM (SELECT ({[Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Marcinko], 
                             [Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Holway],
                             [Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Franklin], 
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Marcinko],
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Leong],
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Holway], 
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco]}) ON COLUMNS  
FROM [cube]) WHERE ([Date].[Year].&[2017],[Measures].[TCE])

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Paul MaurielloSoftware Programmer Developer Analyst EngineerAuthor Commented:
No unfortunately still same error
0
 
Pawan KumarDatabase ExpertCommented:
Please try this ..not sure though..dont have cube with me,,

SELECT NON EMPTY Hierarchize({DrilldownLevel({[Voyage].[Vessel Tag].[All]},INCLUDE_CALC_MEMBERS)})  ON COLUMNS , 
             NON EMPTY Hierarchize({DrilldownLevel({[Date].[Month].[All]},INCLUDE_CALC_MEMBERS)})  ON ROWS 
 FROM (SELECT ({[Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Marcinko], 
                             [Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Holway],
                             [Voyage].[Vessel Tag].&[FCCSP, 20K DWT, Eco, Franklin], 
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Marcinko],
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Leong],
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco, Holway], 
                             [Voyage].[Vessel Tag].&[FCCI, 20K DWT, Eco]}) ON COLUMNS  
FROM [cube]) WHERE ([Date].[Year].&[2017],[Measures].[TCE])

Open in new window

0
 
Paul MaurielloSoftware Programmer Developer Analyst EngineerAuthor Commented:
I got a different error.

Query Preparation failed

Query(2,75) An expression was expected for the function argument and no expression was detected.
Query(1,76) An expression was expected for the function argument and no expression was detected.
0
 
Pawan KumarDatabase ExpertCommented:
This will not run in SSMS as it is looking for 3rd axis. IN SSMS we can not have 3rd axis.
0
 
Paul MaurielloSoftware Programmer Developer Analyst EngineerAuthor Commented:
So this MDX query wont even run in stored procedure form to produce a report? Or do you mean it wont execute only in the cube browser in SSMS?
0
 
Pawan KumarDatabase ExpertCommented:
I think the way we have written the query is a problem we have to modify it. Pls wait checking..
0
 
Paul MaurielloSoftware Programmer Developer Analyst EngineerAuthor Commented:
I got it. In the SQL Server 2014 Cube Browser it will not let you run an MDX Query that is sliced by column, However if you write the same query in a fresh MDX query window it will run fine, apparently its a limitation of the SQL Server 2014 cube browser itself. Hopefully it will be resolved in future versions. Your first response was actually correct thank you for your help :).
0
 
Pawan KumarDatabase ExpertCommented:
Oh..... :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.