Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
robertosangi
Helper I
Helper I

Ranking values comparing two weeks

Hi, 

 

I have one question regarding the possibility to rank values based on a comparison between weeks.

 

Here the problem: I have this kind of table:

robertosangi_0-1646901240353.png


First of all i want to have first column as Wn and second column ad Wn-1, it is possible to do that? 
Thanks

Secondly I want to add two more columns. Each of them must rank (from 1 to n) the position of the highest value. In this example:
1. Palermo
2. Siracusa

....

Then, when I have the indexed value per each of the Wn and Wn-1 column I want to ad a sort of comparison between this index that shows if one unit performed better or worst respect the two last weeks.
In excel I cal use triangles up and down for indicate that. I want to buil somethink like this:

robertosangi_1-1646902024768.png

 

 

Thank you in advance

1 ACCEPTED SOLUTION

Seems is not working anyway @johnt75 

 

Those are now the formulas but the results seems wrong because i filtered the current week table manually and results 433 count and not 2264 as per measure 

robertosangi_0-1646920300175.png


Could you please rewrite formulas as you expected? Thanks

 

View solution in original post

13 REPLIES 13
johnt75
Super User
Super User

Assuming that you have a date table, and assuming that you already have a measure which calculates PdL for the current week, then you can create additional measures as below

PdL Prev Week = CALCULATE( [PdL], DATEADD( 'Date'[Date], -7, DAY) )

Rank This Week = RANKX( 'Table', [PdL] )

Rank Last Week = RANKX( 'Table', [PdL Prev Week] )

Change in Rank = [Rank This Week] - [Rank Last Week]

Once you've added all these to a table visual you can use conditional formatting on the Change in Rank column to add icons

Hi @johnt75 

 

I didn't have a table for date. I have only a column from which I calculate weeks (WEEKNUM) as follow: 

robertosangi_0-1646910206689.png

robertosangi_1-1646910224015.png


looking at this condition, how should i proceed?

Thanks

The safest option would be to create a date table and link that to the date column in your data table.

It would be possible to amend my code to work with a week number column, but it would be fiddly. Firstly you'd need to either change your current Week column so that it was only the week number, without the "Week " text, then you could change the measure to look at week - 1, but you'd run into problems when going over year boundaries when the week number resets. You'd also need to cater for situations where the week number could be 53, not 52.

Safer and easier to create a date table.

Perfect @johnt75 , i'll try. Which is the measure expression for calculating PdL for the current week?

Because actually this is the result: 

robertosangi_0-1646913106458.png

 

With the following measures:

PdLCurrentWeek = CALCULATE([PdL],DATEADD('Date'[Date],7,DAY))

PdLLastWeek = CALCULATE([PdL],DATEADD('Date'[Date],-7,DAY))

RankCurrentWeek = RANKX('Date',[PdLCurrentWeek])

RankLastWeek = RANKX('Date',[PdLLastWeek])

RankDifference = [RankCurrentWeek]-[RankLastWeek]



Thanks

which measure is in the Wn column on that visual? that's the one you should use for as the base measure for calculating PdL for current week.

also, I think the RANKX functions need the data table as a parameter, not the Date table

This are the values @johnt75 :

robertosangi_0-1646917662507.png

 

Wn = PdLCurrentWeek

Wn-1 = PdlLastWeek

 

You need the RANKX functions to work over the UT table, not the Date table

Seems is not working anyway @johnt75 

 

Those are now the formulas but the results seems wrong because i filtered the current week table manually and results 433 count and not 2264 as per measure 

robertosangi_0-1646920300175.png


Could you please rewrite formulas as you expected? Thanks

 

Is it possible to share your pbix file ?

@johnt75 unfortunatelly is not possible. Maybe could be possible to have a short meeting with screen sharing

I solved the measurement problem. Only rank doesn't Work... Here the situation:

robertosangi_0-1646926432277.png

 

IF(
HASONEVALUE(
Table name (unita)
),
RANKX(
ALL(
table name of unita (unita)
),
pdlcurrentweek measure
)
)

Hi @VIJAYKUMART, unfortunatelly doesn't work

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.