【问题标题】:Get Top 5 by Different years MDX按不同年份获得前 5 名 MDX
【发布时间】:2020-05-01 21:49:00
【问题描述】:

我有按年份排名前 5 位的客户,我想创建一个查询,在不同年份每年同时获取此信息,我的意思是:

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]

1996 年前 5 名

我能把 1996 年和 1997 年的前 5 名放在一起吗?

【问题讨论】:

    标签: sql-server ssas mdx mdxstudio mdxclient


    【解决方案1】:

    你可以使用Generate函数如下:

    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
    

    这样您就可以以同样的方式检索每个可用年份的 TOP 5:

    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
    

    希望对您有所帮助。

    【讨论】:

    • 致敬,这是 Generate 函数的一种巧妙用法。太棒了,简直太棒了。
    【解决方案2】:

    试试这个

    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 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多