Forum Discussion
rankx dax
Hi all,
I would like to see this (rank_desired):
I can only use DAX.
I hope somebody can help me. Thank you!
Regards, Elmer
9 Replies
- AilleryO
Memorable Member
Hi,
It would help us if you could tell us what is the logic of your ranking,
and could you please post some datas (without any sensitive data) we can copy and paste.
It should be a RANKX without forgetting to remove filters unwanted with ALL function (at least on Dpt, and dates...).
Hope it helps otherwise please give us more details
- powerbifuddaa
Helper II
Hi, shown are all the mutations of employer A. The logic of my ranking is: employer A is in what department on what startdate.
Customer StartDate EndDate department rank_desired A 1-1-2014 31-8-2021 100026 1 A 1-9-2021 31-12-2021 100026 1 A 1-1-2022 31-1-2022 100026 1 A 1-2-2022 28-2-2022 100026 1 A 1-3-2022 30-6-2022 100545 2 A 1-7-2022 31-8-2022 100545 2 A 1-9-2022 1-3-2023 100545 2 A 2-3-2023 5-3-2023 100565 3 A 6-3-2023 31-3-2023 100545 4 A 1-4-2023 2-10-2023 100545 4 A 3-10-2023 31-12-2099 100545 4 Desired with earliest startdate and latest enddate:
If you need more information, please let me know.
Thanx, Elmer
- ChiragGarg2512
Solution Sage
powerbifuddaa , try this dax measure
rank_desired = rankx(`TableName`, sumx('TableName', department), 1, Dense)
- powerbifuddaa
Helper II
Thank you for your answer. It did not work (yet). I get this message:
After using "value" it showed 2 for every line
- AilleryO
Memorable Member
Hi,
If I understood your needs :
Latest Date in Dpt =
VAR CurrDpt = SELECTEDVALUE( TableEmployee[department] )
RETURN
CALCULATE( LASTDATE( TableEmployee[EndDate] ) , ALL(TableEmployee) , TableEmployee[department]=CurrDpt )andEarliest Date in Dpt =
VAR CurrDpt = SELECTEDVALUE( TableEmployee[department] )
RETURN
CALCULATE( FIRSTDATE( TableEmployee[StartDate] ) , ALL(TableEmployee) , TableEmployee[department]=CurrDpt )you should get this :Let us know if it works
- powerbifuddaa
Helper II
Thank you AilleryO
I already got this result with earliest and latest.
What I am really trying to achieve is:
Most people go from department 1,2,3,4
But there are also people who go 1,2,3,2 (like in this case)
Hope you have another idea. Thank you. Regards, Elmer
- ThxAlot
Super User
Nothing to do with RANKX(). Simplest table grouping in PQ does the trick.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ddBBCsAgDATAv3huINmo1WPfUfz/N2ppU1PE25IdVvA8wxG2ICQEltijCpWeIfeZmZFD20xVa7oSLNk9BrzM8qRgDcrIk9Jviyk7lWJyancvlqWqX/PM6owwmvRHeaA8Gl1PCUVrQMILpa6yX63VuXYB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Customer = _t, StartDate = _t, EndDate = _t, Department = _t]), Grouped = Table.AddIndexColumn(Table.Group(Source, "Department", {"Grp", each _}, GroupKind.Local),"SN",1,1), #"Expanded Grp" = Table.ExpandTableColumn(Grouped, "Grp", {"Customer", "StartDate", "EndDate"}, {"Customer", "StartDate", "EndDate"}) in #"Expanded Grp"- AilleryO
Memorable Member
Thanks you for your proposal but powerbifuddaa specify that he can use only DAX
so a Power Query solution might not be valid for him.
- powerbifuddaa
Helper II
ThxAlot: If you could tell me how to do this in dax, I would be very gratefull! ThxAlot. Regards, Elmer