Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hello, I want to create Rank in M-query. I have Participant ID and there status completed,Not completed,Deleted and Date Time of that Status. I want to create Rank based on below criteria: If Participant ID found duplicate for Completed I'd rank start with 1 for each Completed ID(New I'd start from 1). Not completed start from A. Deleted start from 1001. I want to create Rank during M-query
You need to sort your table by the Participant ID and then by the Date Time of the status to make sure that the rank is applied in the correct order.
Then you need to add a custom column that assigns a starting rank based on the status.
You will group your data by Participant ID and then apply the ranking logic within each group. This is where you will also reset the rank for each new 'Completed' ID.
Inside the for exampleGroup Byfor example operation, you'll need to create a custom column that applies the ranking logic based on the category rank you've defined.
For 'Completed', you'll increment numerically.
For 'Not Completed' and 'Deleted', you might need to handle these as special cases, depending on how you want to increment them ('A', 'B', 'C', ... for 'Not Completed' and numeric for 'Deleted').
Since M-query doesn't have a direct function for ranking with such specific conditions, you'll often need to use a combination of for exampleTable.AddIndexColumnfor example (to add a numeric index) and custom logic to reset and apply ranks based on your rule.
let
Source = TableSource, // put your source table here
SortedTable = Table.Sort(Source, {{"Participant ID", Order.Ascending}, {"Date Time", Order.Ascending}}),
AddCategoryRank = Table.AddColumn(SortedTable, "Category Rank", each if [Status] = "Completed" then 1 else if [Status] = "Not Completed" then "A" else 1001),
Grouped = Table.Group(AddCategoryRank, "Participant ID", {"Data", each _, type table}),
Ranked = Table.TransformColumns(Grouped, {"Data", each Table.AddIndexColumn(_, "Rank", 1, 1, Int64.Type)})
in
Ranked
Error :A cyclic reference was encountered during evaluation
Can you share some data of your original column ?
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 56 | |
| 39 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 73 | |
| 70 | |
| 37 | |
| 35 | |
| 26 |