While doing some calculations for a client, I encountered a not so strange wish – to show an incremental number for each row of data. Although it seems pretty easy, I ended playing with it for several hours, because it had to be generic solution, the one that doesn’t depend on hierarchies placed on rows.
Finally I got it! Here it is.
MEMBER [Measures].[Count of Rows] AS
MEMBER [Measures].[Count of Hierarchies on Rows] AS
MEMBER [Measures].[Row Number] AS
"( " +
[Measures].[Count of Hierarchies on Rows] ) AS L,
CStr(L.CurrentOrdinal – 1) +
" , " ) +
, FORMAT_STRING = "#,#"
–[Measures].[Count of Rows],
–[Measures].[Count of Hierarchies on Rows],
} ON 0,
[Date].[Calendar].[Calendar Year].MEMBERS *
} ON 1
It needs a bit more tweaking to become bulletproof, but I’ll leave that for some other occasion.
A remark for Excel users. Beware that Excel sometimes tricks you and keeps hierarchies on columns although they look like they are on rows. If you’re using Excel as an OLAP client, make sure you put 2 measures on columns, that will force hierarchies placed on rows to actually appear there.