简体   繁体   中英

MDX: How to get dimension count

I execute this query and gives me this error:

Infinite Recursion Detected: The loop of dependencies is: Direct Reporting->Direct Reporting.

Can anybody help me?

WITH
    MEMBER [Measures].[Direct Reporting] AS COUNT([Employee].[Employees].Members, EXCLUDEEMPTY)
SELECT
    {[Measures].[Direct Reporting]} ON COLUMNS,
    {[Geography].[Country].AllMembers} ON ROWS
FROM [Adventure Works]

You've picked a special type of hierarchy: a parent/child hierarchy.

Here is an example of a count against the advWks cube:

WITH 
  MEMBER [Measures].[aCount] AS 
    Sum
    (
      (
        [Customer].[Customer].[Customer]
       ,[Customer].[Customer Geography].CurrentMember
      )
     ,IIF
      (
        [Measures].[Internet Order Quantity] > 50
       ,1
       ,0
      )
    ) 
SELECT 
  {
    [Measures].[Direct Reporting]
   ,[Measures].[Internet Order Count]
  } ON COLUMNS
 ,{[Customer].[Customer Geography].[Country].MEMBERS} ON ROWS
FROM [Adventure Works];

Specifying Count with EXCLUDEEMPTY means the engine needs to evaluate the cube's cells referenced by each member of the dimension and the current [Measures]. Not 100% sure about SSAS behavior but it seems the current [Measures] is the calc. measure being defined itself: hence the infinite loop.

To fix it, you can explicitly define the [Measures]:

WITH MEMBER [Measures].[Direct Reporting] AS COUNT( { [Measures].[use-here-your-measure] } * [Employee].[Employees].Members, EXCLUDEEMPTY)

Or perhaps use the NonEmpty function:

AS Count( NonEmpty( [Employee].[Employees].Members, [Measures].[use-here-your-measure] ))

Hope that helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM