如何使用MDX SQL选择具有相同产品名称的多行的最大值?

问题描述 投票:0回答:2

使用RANK / ORDER编辑,建议的更改如下:

当前我返回所有销售产品的供应商的价格总和。

我想要的将返回产品名称,并返回对于每个产品具有相同产品的行具有最高最高价格的行的价格。

代码:

--Find the maximum price for each product offered in Madison
WITH MEMBER [Measures].[Max Value] AS MAX([Measures].[Price]) 

SELECT NON EMPTY {
    [Measures].[Max Value]} ON 0,
NON EMPTY { 
    ([Tb Product].[Name].[Name] ) }  ON ROWS 
FROM [DS715]
WHERE ([Tb Supplier].[City].&[Madison])

编辑:

WITH MEMBER [Measures].[Max Price RANK] AS 
RANK( ([Tb Product].[Name].currentmember), 
ORDER( ([Tb Product].[Name].currentmember), [Measures].[Price - Tb Transactions], BDESC) ) 

SELECT 
NON EMPTY { 
    [Measures].[Price - Tb Transactions] } ON COLUMNS, 
NON EMPTY { 
    filter([Tb Product].[Name].[Name], [Measures].[Max Price RANK] <2 )} ON ROWS 
FROM [DS715] 
WHERE ( [Tb Supplier].[City].&[Madison] )

现在每行仅一行,但数量很大

enter image description here

sql max ssas mdx
2个回答
1
投票
查询1

select { [Measures].[Internet Sales Amount] } on columns, non empty ([Product].[Category].[Category],[Product].[Subcategory].[Subcategory]) on rows from [Adventure Works]

结果Result 1

现在让我们修改查询以限制为具有最大Internet Sale的成员

WITH MEMBER [Measures].[Internet Sales Amount Rank] AS RANK( ([Product].[Category].currentmember,[Product].[Subcategory].CurrentMember), ORDER( ([Product].[Category].currentmember,[Product].[Subcategory].[Subcategory].Members) , [Measures].[Internet Sales Amount], BDESC) ) select non empty [Measures].[Internet Sales Amount] on columns, non empty ([Product].[Category].[Category],filter([Product].[Subcategory].[Subcategory],[Measures].[Internet Sales Amount Rank]<2)) on rows from [Adventure Works]

结果

enter image description here

-1
投票
[另一个用户似乎也有类似的问题。也许您可以提供预期输出的样本?
© www.soinside.com 2019 - 2024. All rights reserved.