How to calculate ranking for subcategory?
(如何计算子类别的排名?)
Say we have sample data with the following expected results: (假设我们有以下预期结果的示例数据:)
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcisqzSwpVtJRSiwoyEkF0oZgHKuDJJWUmAeEQIYJEBuhypXn56QlpRYVVQLZpkBsjCqdnAGVMwNrB8mFpaanliQm5aSC5AvySxJL8lGsRZFPTiwqyi8BWwuzGkU+Py8zPw9Im0OsjgUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Category = _t, Subcategory = _t, Sales = _t, Results = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Category", type text}, {"Subcategory", type text}, {"Sales", Int64.Type}, {"Results", Int64.Type}})
in
#"Changed Type"
Calculating Rank for on column is a snap:
(快速计算列上的排名:)
RankSubcategory =
RANKX (
ALL ( MyTable[Subcategory] ),
[SalesMeasure],
,
ASC,
SKIP
)
I have roamed for hints there:
(我漫游了那里的提示:)
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
(https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures)
I got the following code:
(我得到以下代码:)
RankSubcategory =
RANKX (
FILTER (
ALL (
'MyTable'[Category],
'MyTable'[Subcategory]
),
'MyTable'[Category]
= MAX ( 'MyTable'[Category] )
),
CALCULATE (
SUM ( 'MyTable'[Sales] )
)
)
It give expected results.
(它给出了预期的结果。)
I have no idea how it works. (我不知道它是如何工作的。)
Can you please shed light on that? (你能说明一下吗?)
ask by Przemyslaw Remin translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…