1

I have a top 5 of Customers by year and I want to create a query that gets this information per year in different years at the same time, I mean:

select 
[Measures].[Ventas] 
on columns,
non empty
topcount
(
[Dim Cliente].[Company Name].Children,5,[Measures].[Ventas]
) 
on rows
from 
[DWH Northwind]
where 

[Dim Tiempo].[Año].&[1996]

TOP 5 1996

TOP 5 1996

Could I get Top 5 of 1996 and 1997 together separated per year?

MoazRub
  • 2,881
  • 2
  • 10
  • 20
Antonio Labra
  • 1,694
  • 2
  • 12
  • 21

2 Answers2

4

You could use the Generate function as following:

select 
  [Measures].[Ventas] on columns,

  non empty Generate(
    { [Dim Tiempo].[Año].&[1995], [Dim Tiempo].[Año].&[1996] } as yy,
    topcount (yy.currentMember * [Dim Cliente].[Company Name].Children,5,[Measures].[Ventas]) 
  ) on rows

from [DWH Northwind

This way you could retrieve the TOP 5 for each available years the same way:

select 
  [Measures].[Ventas] on columns,

  non empty Generate(
    [Dim Tiempo].[Año].members as yy,
    topcount (yy.currentMember * [Dim Cliente].[Company Name].Children,5,[Measures].[Ventas]) 
  ) on rows

from [DWH Northwind

Hope that helps.

Marc Polizzi
  • 9,275
  • 3
  • 36
  • 61
2

Try this

select 
[Measures].[Ventas] 
on columns,
non empty
{
topcount
(([Dim Tiempo].[Año].&[1996],[Dim Cliente].[Company Name].Children),5,[Measures].[Ventas]) 
,
topcount
(([Dim Tiempo].[Año].&[1997],[Dim Cliente].[Company Name].Children),5,[Measures].[Ventas]) 
}
on rows
from 
[DWH Northwind]
where 
MoazRub
  • 2,881
  • 2
  • 10
  • 20