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.
Hello together,
im trying to create a RANKX over a few orders that are sorted by Date.
The Raw Data looks like this:
Customer | Order-Number | Date |
A | 1a2b3c | 01.01.1999 |
A | 1a2b3c | 01.01.2000 |
A | 2a2b3c | 01.01.2000 |
A | 3a2b3c | 01.01.2000 |
B | 1a2b3c | 01.01.2000 |
B | 2a2b3c | 01.01.2001 |
B | 3a2b3c | 01.01.2001 |
B | 3a2b3c | 01.01.2001 |
The result i need looks like this:
Customer | Order-Number | Date | RANK |
A | 1a2b3c | 01.01.1999 | 1 |
A | 1a2b3c | 01.01.1999 | 1 |
A | 2a2b3c | 01.01.2000 | 2 |
A | 3a2b3c | 01.01.2000 | 3 |
B | 1a2b3c | 01.01.2000 | 1 |
B | 2a2b3c | 01.01.2001 | 2 |
B | 3a2b3c | 01.01.2001 | 3 |
B | 3a2b3c | 01.01.2001 | 3 |
The ranking starts again for every customer and is depending on the order-number in combination with the date.
I have written this code:
Customer | Order-Number | Date | RANK |
A | 1a2b3c | 01.01.1999 | 1 |
A | 1a2b3c | 01.01.1999 | 1 |
A | 2a2b3c | 01.01.2000 | 2 |
A | 3a2b3c | 01.01.2000 | 2 |
B | 1a2b3c | 01.01.2000 | 1 |
B | 2a2b3c | 01.01.2001 | 2 |
B | 3a2b3c | 01.01.2001 | 2 |
B | 3a2b3c | 01.01.2001 | 2 |
Customer | Order-Number | Date | RANK |
A | 1a2b3c | 01.01.1999 | 1 |
A | 1a2b3c | 01.01.1999 | 1 |
A | 2a2b3c | 01.01.2000 | 2 |
A | 3a2b3c | 01.01.2000 | 3 |
B | 1a2b3c | 01.01.2000 | 1 |
B | 2a2b3c | 01.01.2001 | 2 |
B | 3a2b3c | 01.01.2001 | 3 |
B | 3a2b3c | 01.01.2001 | 3 |
Solved! Go to Solution.
Here is a column expression that shows one way to do it.
Rank =
VAR thiscustomer = Orders[Customer]
VAR thisorder = Orders[Order-Number]
VAR thisdate = Orders[Date]
VAR stringtorank =
FORMAT ( thisdate, "YYYYMMDD" ) & thisorder
VAR thiscustomertable =
FILTER ( Orders, Orders[Customer] = thiscustomer )
VAR withstringstorank =
ADDCOLUMNS (
thiscustomertable,
"cStringtoRank", FORMAT ( Orders[Date], "YYYYMMDD" ) & Orders[Order-Number]
)
VAR result =
RANKX ( withstringstorank, [cStringtoRank], stringtorank, aSC )
RETURN
result
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Here is a column expression that shows one way to do it.
Rank =
VAR thiscustomer = Orders[Customer]
VAR thisorder = Orders[Order-Number]
VAR thisdate = Orders[Date]
VAR stringtorank =
FORMAT ( thisdate, "YYYYMMDD" ) & thisorder
VAR thiscustomertable =
FILTER ( Orders, Orders[Customer] = thiscustomer )
VAR withstringstorank =
ADDCOLUMNS (
thiscustomertable,
"cStringtoRank", FORMAT ( Orders[Date], "YYYYMMDD" ) & Orders[Order-Number]
)
VAR result =
RANKX ( withstringstorank, [cStringtoRank], stringtorank, aSC )
RETURN
result
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
Thank you, this is perfekt!
Just had to add DENSE behinde the ASC but nice solution 🙂
@Limerick , Try like
Ranking = RANKX(
FILTER(ALL('Table'),
'Table'[Customer] = EARLIER('Table'[Customer]) ) ,
'Table'[Order-Number],,ASC,Dense)
Hello @amitchandak ,
thank you for your answer.
Unfortunately, as I mentioned before, I cant Rank by the Order-Number itself.
It is important that the order goes by the date.
Best regards 🙂
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 |
---|---|
103 | |
101 | |
78 | |
69 | |
63 |
User | Count |
---|---|
141 | |
106 | |
101 | |
85 | |
72 |