3
votes

I'm a SSAS newbie and i'm trying to query a cube to retrieve data against aome measure groups order by date. The date range i wish to specify in my query. The query I'm using is this:-

SELECT
{
    [Measures].[Measure1],
    [Measures].[Measure2],
    [Measures].[Measure3]
} 
ON COLUMNS,
NON EMPTY{
   [Date].[AllMembers]
         } 
ON ROWS
FROM (SELECT ( STRTOMEMBER('2/23/2013', CONSTRAINED) : 
STRTOMEMBER('3/1/2013', CONSTRAINED) ) ON COLUMNS 
FROM   [MyCube])

However it gives me the following error
Query (10, 16) The restrictions imposed by the CONSTRAINED flag in the STRTOMEMBER function were violated.

I tried removing the constrained keyword and then even strtomember function. But in each cases i got the following errors respectively
Query (10, 16) The STRTOMEMBER function expects a member expression for the 1 argument. A string or numeric expression was used.
and
*Query (10, 14) The : function expects a member expression for the 1 argument. A string or numeric expression was used. *

I can understand from the last two errors that i need to include the constraint keyword. But can anyone tell me why this query wont execute?

3
SELECT NON EMPTY { [Measures].[Stock Entry Main Count], [Measures].[Quantity1], [Measures].[Quantity2] } ON COLUMNS, NON EMPTY { ([Master Store].[Store Code].[Store Code].ALLMEMBERS * [Master SOS].[Name].[Name].ALLMEMBERS * [Stock Entry Main].[Textentrydate].[Textentrydate].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT { STRTOMEMBER(@FromStockEntryMainTextentrydate) : STRTOMEMBER(@ToStockEntryMainTextentrydate) } ON COLUMNS FROM [Testka])Sharmaji TM

3 Answers

2
votes

The string that you pass as the member expression must be a fully-qualified member name, or resolve to one. Use the same format as you did in the SELECT.

For example:

STRTOMEMBER('[Date].[2/23/2013]', CONSTRAINED)

Edit: I just noticed the syntax of your range select looks wrong -- you need to use {...}, not (...).

SELECT { 
    STRTOMEMBER('2/23/2013', CONSTRAINED) : 
    STRTOMEMBER('3/1/2013', CONSTRAINED) }
1
votes

Please execute below script. Extract your date dimension attribute copy it by right clicking and paste it in STRTOMEMBER value.

It will works fine.

 SELECT NON EMPTY { [Measures].[Internet Sales Amount] } ON COLUMNS 
 FROM ( SELECT ( STRTOMEMBER('[Date].[Date].&[20050701]')  : 
 STRTOMEMBER('[Date].[Date].&[20061007]') )  ON COLUMNS 
 FROM [Adventure Works]) 
1
votes
FROM ( SELECT (
   STRTOMEMBER(@FromDateCalendarDate, CONSTRAINED) :
   STRTOMEMBER(@ToDateCalendarDate, CONSTRAINED) ) ON COLUMNS