Monday, February 20, 2012

MDX Max function - can I retrieve information about the max number

I am trying to write a report for SSRS using an SSAS cube. I need to get the maximum number of received product at any one day by receival site. And, I also need to get the date the maximum occurred. At the moment I can get the maximum in any one day by site using the following:

with member [Measures].[Max Rec Tonnes] as Max(descendants([Calendar].[Fiscal Current by Week].currentmember,[Calendar].[Fiscal Current by Week].[Fiscal Day],self),[Measures].[Receival Tonnes])

select {[Measures].[Max Rec Tonnes]} on columns,

{descendants([Site Storage].[Active Sites].[Active Flag].&[True],[Site Storage].[Active Sites].[Site ID],self)} on rows

from [cube]

where [Calendar].[Fiscal Current by Week].[Fiscal Year].&[1]

Any ideas how I can get the date that the max occurred?

This would probably accomplish what you want (since I understand you want the day for each site with the max value of Receival Tonnes.

Select

{[Measures].[Max Rec Tonnes]} on columns,

Generate(

[Site Storage].[Active Sites].[Site ID].Members as [SiteSet],

TopCount(

([SiteSet].CurrentMember, [Calendar].[Fiscal Current by Week].[Fiscal Day].Members), 1,

[Measures].[Receival Tonnes]

)

)

on rows

from [cube]

where [Calendar].[Fiscal Current by Week].[Fiscal Year].&[1]

|||Thanks! That works really well. Now I just have to go back through my mdx books and try to understand what generate means!!

No comments:

Post a Comment