Search code examples
tfsssasmdxreportbuilder

Report Builder: How do MDX filter expressions work in Query Designer?


I'm trying to write some reports against a TFS cube. I'd like to utilize query builder since I'm fairly new to MDX and I'd prefer not to write the entire query; however, it doesn't seem very easy to inject MDX into the query designer's dimension filter expressions. Is there a special syntax to enter them in?

For instance, say I want to show the top 10 heaviest code churn dates in a certain date range. In the query designer:

  • I drop in a Date dimension and mark it as a parameter.
  • I drop in the Version Control Changeset, set hierarchy to Changeset Id, operator to MDX.
  • I then use the filter expression builder to construct TOPCOUNT([Version Control Changeset].[Changeset ID], 10, [Measures].[Total Churn])
  • Back in the query designer, I set Date, Changeset ID, and Total Churn to be my columns.

The generated query is as follows:

SELECT NON EMPTY { [Measures].[Total Churn] } ON COLUMNS, NON EMPTY { ([Date].[Date].[Date].ALLMEMBERS * [Version Control Changeset].[Changeset ID].[Changeset ID].ALLMEMBERS ) } DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS FROM ( SELECT ( TOPCOUNT([Version Control Changeset].[Changeset ID], 10, [Measures].[Total Churn]) ) ON COLUMNS FROM ( SELECT ( STRTOSET(@DateYearMonthDateHierarchy, CONSTRAINED) ) ON COLUMNS FROM [Code Churn])) WHERE ( IIF( STRTOSET(@DateYearMonthDateHierarchy, CONSTRAINED).Count = 1, STRTOSET(@DateYearMonthDateHierarchy, CONSTRAINED), [Date].[Year - Month - Date Hierarchy].currentmember ) ) CELL PROPERTIES VALUE, BACK_COLOR, FORE_COLOR, FORMATTED_VALUE, FORMAT_STRING, FONT_NAME, FONT_SIZE, FONT_FLAGS

However, both in the query designer's preview area and when I run the report, it's as if the TOPCOUNT isn't being applied and instead of seeing the top 10, I see all of them. The expression parses correctly; it just doesn't seem to do anything. Is there an easy gotcha that I've missed?

Thanks!


Solution

  • Based on your goal...to show the top 10 heaviest code churn dates in a certain date range

    I think your MDX expression is wrong...

    TOPCOUNT([Version Control Changeset].[Changeset ID], 10, [Measures].[Total Churn])
    

    Try this instead...

    TOPCOUNT(
         (  
            [Date].[Date].[Date].ALLMEMBERS *
            [Version Control Changeset].[Changeset ID]
         )
        ,10
        ,[Measures].[Total Churn]
    )
    

    ...also, I have found this utility very useful when working with MDX generated from the MS integrated query designers.