Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi.
I can't seem to find an answer, simple question how would I show ranking of category over select period.
Right now, for the excerise I have it as follow:
Ranking Fruits = RANKX(ALL(Master[FruitName]),[Sum Value],,DESC,Dense)
Rank | FruitName | Sum Value |
1 | Apple | 500 |
2 | Pear | 439 |
3 | Banana | 350 |
4 | Oranges | 299 |
5 | Kiwi | 100 |
I want to be able to show the ranking in matrix with ranking in 1st column, the time period as column and for each time period it to display the category and not the ranking. Something like the below. Thanks.
Rank | Jan-21 | Feb-21 | Mar-21 |
1 | Apple | Banana | Pear |
2 | Pear | Apple | Oranges |
3 | Banana | Pear | Kiwi |
4 | Oranges | Oranges | Apple |
5 | Kiwi | Kiwi | Banana |
Solved! Go to Solution.
@Tevon713 OK, I did this with a disconnected Rankings table (just 1 - 5 in a single column called Rank) and then a "FruitsBasket" table. The measure is:
Fruit Rank =
VAR __Rank = MAX('Rankings'[Rank])
VAR __Table =
SUMMARIZE(
'FruitsBasket',
[FruitName],
"__Value",SUM([Value])
)
VAR __RankTable =
ADDCOLUMNS(
__Table,
"__Rank",RANKX(__Table,[__Value],,DESC)
)
RETURN
MAXX(FILTER(__RankTable,[__Rank] = __Rank),[FruitName])
This was my FruitsBasket table:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyElV0lHySszTNTIEMkwNDJRidRASbqlJEAkTNAnfxCKIhBFUIiA1sQjZJBNUcbhBxqjicHNgNjsl5gEhsknG6DJwszD0wE0zhMr4FyXmpacWIxtnhCEFNw9TCm4gzDvemeWZyKYZoorDjUITh5sD9kwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FruitName = _t, Month = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"FruitName", type text}, {"Month", type date}, {"Value", Int64.Type}})
in
#"Changed Type"
Rankings table:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyaKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Rank = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Rank", Int64.Type}})
in
#"Changed Type"
Hi,
I am not sure of how much i can help, but i would like to try. Share the link from where i can download your PBI file.
@Tevon713 OK, I did this with a disconnected Rankings table (just 1 - 5 in a single column called Rank) and then a "FruitsBasket" table. The measure is:
Fruit Rank =
VAR __Rank = MAX('Rankings'[Rank])
VAR __Table =
SUMMARIZE(
'FruitsBasket',
[FruitName],
"__Value",SUM([Value])
)
VAR __RankTable =
ADDCOLUMNS(
__Table,
"__Rank",RANKX(__Table,[__Value],,DESC)
)
RETURN
MAXX(FILTER(__RankTable,[__Rank] = __Rank),[FruitName])
This was my FruitsBasket table:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyElV0lHySszTNTIEMkwNDJRidRASbqlJEAkTNAnfxCKIhBFUIiA1sQjZJBNUcbhBxqjicHNgNjsl5gEhsknG6DJwszD0wE0zhMr4FyXmpacWIxtnhCEFNw9TCm4gzDvemeWZyKYZoorDjUITh5sD9kwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FruitName = _t, Month = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"FruitName", type text}, {"Month", type date}, {"Value", Int64.Type}})
in
#"Changed Type"
Rankings table:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlSK1YlWMgKTxmDSBEyaKsXGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Rank = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Rank", Int64.Type}})
in
#"Changed Type"
Just enlighted by some PQ guru the other day, I came up with a verbose method to calculate rank instead of sorting,
Rank = List.Count( List.PositionOf( list, value, Occurrence.All, each _>=value ) )
Just for fun, here's a PQ solution based on your hearty FruitBasket. Cheers!
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WciwoyElV0lHySszTNTIEMkwNDJRidRASbqlJEAkTNAnfxCKIhBFUIiA1sQjZJBNUcbhBxqjicHNgNjsl5gEhsknG6DJwszD0wE0zhMr4FyXmpacWIxtnhCEFNw9TCm4gzDvemeWZyKYZoorDjUITh5sD9kwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FruitName = _t, Month = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"FruitName", type text}, {"Month", type date}, {"Value", Int64.Type}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "YYYYMM", each Date.ToText([Month], "MMM yyyy")),
#"Grouped Rows" = Table.Group(#"Added Custom", {"YYYYMM"}, {{"ar", each _, type table [FruitName=nullable text, Month=nullable date, Value=nullable number, YYYYMM=text]}}),
#"Added Rank" = Table.TransformColumns(#"Grouped Rows", {"ar", (t) => Table.AddColumn(t, "Rank", (r) => List.Count(List.PositionOf(t[Value], r[Value], Occurrence.All, each _ >= r[Value])))}),
#"Expanded ar" = Table.ExpandTableColumn(#"Added Rank", "ar", {"FruitName", "Rank"}, {"FruitName", "Rank"}),
#"Pivoted Column" = Table.Pivot(#"Expanded ar", List.Distinct(#"Expanded ar"[YYYYMM]), "YYYYMM", "FruitName")
in
#"Pivoted Column"
Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension! |
DAX is simple, but NOT EASY! |
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
105 | |
88 | |
74 | |
66 |
User | Count |
---|---|
126 | |
111 | |
100 | |
83 | |
71 |