我不知道如何防止每个产品显示多行。
这是我的代码:
-- For each product find the city where it is offered at the lowest price
WITH MEMBER [Measures].[MIN Price] AS MIN([Measures].[Price])
SELECT NON EMPTY {
[Measures].[MIN Price] } ON COLUMNS,
NON EMPTY {
([Tb Product].[Name].[Name].ALLMEMBERS * [Tb Supplier].[City].[City].ALLMEMBERS ) } ON ROWS
FROM [DS715]
以下是结果的屏幕截图。
我不想显示每个城市,而只显示价格最低的城市
我希望查询返回:
Boat Wausau 3013.17
Computer Springfield 450.89
Gas Wausau 2.28
Milk Madison 3.88
Orange Wausau 1.89
TV Wausau 189.99
编辑:尝试使用下面的代码对订单和等级进行排序,但现在每个产品名称均显示一个巨型数字
代码:
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] )
答案 0 :(得分:0)
尝试生成语句:
https://docs.microsoft.com/en-us/sql/mdx/generate-mdx?view=sql-server-ver15
SELECT
{[Measures].[Price]}
ON COLUMNS,
{
Generate([Tb Product].[Name].[Name].ALLMEMBERS, // foreach product
[Tb Product].[Name].CURRENTMEMBER * // cross the product
BOTTOMCOUNT([Tb Supplier].[City].[City].ALLMEMBERS, 1, // with bottom 1 city
([Tb Product].[Name].CURRENTMEMBER, [Measures].[Price])) // by product and price
)
}
ON ROWS
FROM [DS715]
答案 1 :(得分:0)
您的代码不起作用,因为您错误地使用了Rank。进行以下修饰
WITH MEMBER [Measures].[Max Price RANK] AS
RANK( ([Tb Product].[Name].currentmember,[Tb Supplier].[City].currentmember),
ORDER( ([Tb Product].[Name].currentmember,[Tb Supplier].[City].[City].members), [Measures].[Price - Tb Transactions], BDESC)
)
SELECT
NON EMPTY {
[Measures].[Price - Tb Transactions] } ON COLUMNS,
NON EMPTY {
([Tb Product].[Name].[Name],filter([Tb Supplier].[City].[City], [Measures].[Max Price RANK] <2 )}
ON ROWS
FROM [DS715]