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

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.

Reply
AuroraNI
Helper III
Helper III

difference based on dynamic rank

Hi,

I have the below table in PBI and I would like another column in this table that calculates the time differences between 1st place and all the other runners, and this would change based on the event slicer.

present.JPG

below image is how I would like it to display:

required.JPG

Thanks to anyone who can provide some assistance!

1 ACCEPTED SOLUTION

@AuroraNI 

 

Thanks for the file. It made things easier.

This works:

Dif Rank.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

13 REPLIES 13
V-lianl-msft
Community Support
Community Support

Hi @AuroraNI ,

 

Create a calculated column as "dynamic rank"

rank = RANKX(FILTER('Table',EARLIER('Table'[event])='Table'[event]),'Table'[time],,ASC)

Then create a measure like this:

Measure = var _rank = SELECTEDVALUE('Table'[rank])
var _event = SELECTEDVALUE('Table'[event])
var diff = CALCULATE(MAX('Table'[time]),FILTER(ALL('Table'),'Table'[rank]=_rank-1&&'Table'[event]=_event))
var current_ = MAX('Table'[time])
return IF(ISBLANK(diff),0,current_-diff)

V-lianl-msft_0-1604973332030.pngV-lianl-msft_1-1604973345053.png

 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

hi @V-lianl-msft thank you for taking the time to help me.  I would like the measure to calculate the time from rank =1 so the time difference gets bigger as the rank increases like below:

AuroraNI_0-1604994456679.png

Thank you for your help.

amitchandak
Super User
Super User

@AuroraNI , Create a new column like

New colum =

var _1 = minx(filter(Table, event =earlier([event]) && [Time] > earlier([Time])), [Time])

return

if(isblank( _1),0, _1 -[Time])

 

Hi @amitchandak thank you for taking the time to repond and help me.  The column calculates the time difference from the next runner. 

present 2.JPG

 

I would like the time difference to be calculated always from the no.1 Rank runner like below

required.JPG

sorry if that was not clear in my last post

Thank you for the help.

 

hi @amitchandak thank you again for helping, in the initial post.  Would you have time to look at my 2nd question please?  Thank you.

Olly

@AuroraNI 

You can try:

Dif vs Rank 1 = 
VAR R1Time = CALCULATE([Time], 
              FILTER(ALLSELECTED(Table, Table [Event]), [Rank] = 1)
RETURN
[Time] - R1Time

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi @PaulDBrown 

Thank you for taking the time to help me!  It is much appreciated.

When I try this I get the below:

AuroraNI_0-1604939484264.png

 

@AuroraNI 

The error in [Time] is because you need to use a measure, such as:
Time = AVERAGE(Table [Time])

For the ALLSELECTED error, change the expression to ALLSELECTED(Table[Event])





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thank you @PaulDBrown 

I have tried and it seems to be working on the first row but not on the rest

AuroraNI_0-1604951543530.png

 

@AuroraNI

Sorry, you need to use the "name" field in the ALLSELECTED (no the "event" field)

Also, if you are using a field from a dimension Table, you need to use the field in the ALLSELECTED from the corresponding field.

In the following example I'm ranking by sales and calculating the difference vs the smallest sales number.

The field used in the rank measure, the visual, and the [Dif vs rank 1] all come from the Dim Item table (dimension table; not the fact table) The field you use must be consistent throughout. (so either your name field is from the fact table or from the dimension table)

Dif Rank.JPG





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






hi @PaulDBrown thanks, I think they are all consistent as they are from the same table

AuroraNI_0-1604997671729.png

AuroraNI_1-1604997685252.pngAuroraNI_2-1604997715505.png

Here is a link to the PBI file in case I am missing something.https://drive.google.com/file/d/1BKO6MVDCPCKLIJCVRd8jySxc7qV-vBRH/view?usp=sharing 

 

@AuroraNI 

 

Thanks for the file. It made things easier.

This works:

Dif Rank.JPG

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






hi @PaulDBrown thank you very much for you help!  It is much appreciated!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.