DAX-RANK 函数

DAX - RANK Function

我有一个来自 WEBI 的 RANK 代码,需要在 DAX 中编写类似的代码,否则 MDX.Both 可以工作。但是DAX会更有用。

=Rank([OrderCount];([Category1];[Category2];[Category3])) 

我已经在 DAX 中尝试了以下代码,但它并不完全符合我的需要。

=RANK.EQ(table1[OrderCount];table1[OrderCount])

你能帮我写出类似的吗?

Grouping by Count. This is extra.

我不太擅长DAX,但是MDX方式如下:

with
Dynamic Set OrderedSet as
Order(
    NonEmptyCrossJoin(
        [Dim Product].[Subcategory Name].[Subcategory Name].Members,
        [Dim Product].[Category Name].[Category Name].Members
        [Measures].[Order Quantity],
        2
    ),
    [Measures].[Order Quantity],
    BDESC
)

Member [Measures].[Rank] as
Rank(

        ([Dim Product].[Subcategory Name].Currentmember, 
        [Dim Product].[Category Name].Currentmember),
        OrderedSet
)

select 
{[Measures].[Order Quantity],[Measures].[Rank]} on 0,
non empty OrderedSet on 1
from 
[Adventure Works DW2016CTP3]

密集等级:

with
Dynamic Set OrderedSet as
Order(
    NonEmptyCrossJoin(
      [Dim Product].[Subcategory Name].[Subcategory Name].Members,
      [Dim Product].[Category Name].[Category Name].Members,
      [Measures].[Order Quantity],
       2
    ),
    [Measures].[Order Quantity],
    BDESC
)

Dynamic Set DenseOrderedSet as
Order(
    NonEmpty(
       OrderedSet,
       [Measures].[RankFirstMatch]
    ),
    [Measures].[Order Quantity],
    BDESC
)

Member [Measures].[Rank] as
Rank(
  ([Dim Product].[Subcategory Name].Currentmember,[Dim Product].[Category Name].CurrentMember),
  OrderedSet
)

Member [Measures].[RankFirstMatch] as
IIF(
    [Measures].[Order Quantity] 
    =
    (
        OrderedSet.Item([Measures].[Rank] -2),
        [Measures].[Order Quantity]
    ),
    NULL,
    [Measures].[Rank]
)

Member [Measures].[RankDenseSet] as
Rank(
  ([Dim Product].[Subcategory Name].Currentmember,[Dim Product].[Category Name].CurrentMember),
  DenseOrderedSet
)


Member [Measures].[DenseRank] as
IIF(
    [Measures].[RankDenseSet] = 0,
    (OrderedSet.Item([Measures].[Rank] -2),[Measures].[DenseRank]),
    [Measures].[RankDenseSet]
)


select {[Measures].[Order Quantity],[Measures].[Rank],[Measures].[RankFirstMatch],[Measures].[RankDenseSet],[Measures].[DenseRank]} on 0,
non empty OrderedSet on 1
from [Adventure Works DW2016CTP3]

这是针对您的问题的 DAX 衡量指标:

Rank =
IF (
    HASONEVALUE ( YourTableName[ProductName] ),
    RANKX (
        ALL ( YourTableName ),
        CALCULATE ( SUM ( YourTableName[Order Quantity] ) ),
        ,
        ,
        DENSE
    )
)

IF (HASONEVALUE ( YourTableName[ProductName] ).... 部分将消除您的总计显示 1