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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MidtownMo
Helper I
Helper I

How to create a measure for rank change between two years

Hi.  I have a table shown here where I used the RANKX function to create a measure to show the rank of a metric.  In this table I have calendar years going across the top.  Now I want to create another measure that would calculate the change in rank either between 2017 and 2021 or between 2018 and 2021.  Any suggestions?  Thanks in advance.

MidtownMo_0-1648334294085.png

 

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @MidtownMo ,

 

I had to write three separate measures to return the rank of only 2017, 2018, and 2021, but I'm afraid that didn't fit into the matrix table, so I modified the visual column. Use a custom table or a manually entered table.

Measure = 
var _1 = RANKX(ALLSELECTED('Fact table'[ID]),CALCULATE(CALCULATE(SUM('Fact table'[Values]),FILTER('Fact table',format([Date],"yyyy")=SELECTEDVALUE(AxisTable[column])))))
var _2017 = RANKX(ALLSELECTED('Fact table'[ID]),calculate(CALCULATE(SUM('Fact table'[Values]),FILTER('Fact table',[Date].[Year]=2017))))
var _2018 = RANKX(ALLSELECTED('Fact table'[ID]),calculate(CALCULATE(SUM('Fact table'[Values]),FILTER('Fact table',[Date].[Year]=2018))))
var _2021 = RANKX(ALLSELECTED('Fact table'[ID]),calculate(CALCULATE(SUM('Fact table'[Values]),FILTER('Fact table',[Date].[Year]=2021))))
return
SWITCH(SELECTEDVALUE(AxisTable[column]),"2021-2017",_2021-_2017,"2021-2018",_2021-_2018,_1)

Result:

vchenwuzmsft_0-1648525441822.png

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

View solution in original post

4 REPLIES 4
v-chenwuz-msft
Community Support
Community Support

Hi @MidtownMo ,

 

I had to write three separate measures to return the rank of only 2017, 2018, and 2021, but I'm afraid that didn't fit into the matrix table, so I modified the visual column. Use a custom table or a manually entered table.

Measure = 
var _1 = RANKX(ALLSELECTED('Fact table'[ID]),CALCULATE(CALCULATE(SUM('Fact table'[Values]),FILTER('Fact table',format([Date],"yyyy")=SELECTEDVALUE(AxisTable[column])))))
var _2017 = RANKX(ALLSELECTED('Fact table'[ID]),calculate(CALCULATE(SUM('Fact table'[Values]),FILTER('Fact table',[Date].[Year]=2017))))
var _2018 = RANKX(ALLSELECTED('Fact table'[ID]),calculate(CALCULATE(SUM('Fact table'[Values]),FILTER('Fact table',[Date].[Year]=2018))))
var _2021 = RANKX(ALLSELECTED('Fact table'[ID]),calculate(CALCULATE(SUM('Fact table'[Values]),FILTER('Fact table',[Date].[Year]=2021))))
return
SWITCH(SELECTEDVALUE(AxisTable[column]),"2021-2017",_2021-_2017,"2021-2018",_2021-_2018,_1)

Result:

vchenwuzmsft_0-1648525441822.png

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

One follow up question:  I'd like the table to be sorted on either the 2021 column or the 2021-2017 column.  I tried clicking on the column headers to sort them but that appears to only work on a Total column (which is not in this table) or the ID column.  Is there a way to do this?  Thanks.

Thank you.  This was very helpful.  One of the tricks is to create an Axis Table that treats the years as text and includes the "2021-2017" and "2021-2018" column names.  It took me a few minutes to realize that but your including a .pbix example was great.  Thanks again!

MidtownMo
Helper I
Helper I

I should have said in this matrix visualization, not table.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.