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
Roseventura
Responsive Resident
Responsive Resident

Problem with RANKX when calculating Gain/Loss between 2 Ranked columns

I'm trying to create a table that shows customers, LY Sales, TY Sales and Gain/Loss.  My customers are ranked by Sales (top 25, next 25, other) over a 2 year period (TY and LY).   When I try to use my filter to see only the customers in the 1-25 rank, the table on the left (below) WITHOUT the Gain/Loss measure displays only those customers (which is good).  But as soon as I add the Gain/Loss column, the table will display ALL the customers, regardless of rank.

 

How can I get the table on the right to display only those customer which I have filtered out?

 

Capture16.JPG

 

Sorry, I had to blank out the customers.

 

Thanks,

Rose

 

2 REPLIES 2
vanessafvg
Super User
Super User

@Roseventura please post your measures code





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Here are my measures:

 

Avg Total Sales = calculate( [Sales 2Y] + [Sales LY] + [Sales TY RR])/3

 

Sales 2Y =
calculate(
sum(PBI_AEP_Shipments_Multi[Ext Unit Price]),
filter(PBI_AEP_Shipments_Multi,
PBI_AEP_Shipments_Multi[Year]=[Year 2Y]))


Sales LY =
calculate(
sum(PBI_AEP_Shipments_Multi[Ext Unit Price]),
filter(PBI_AEP_Shipments_Multi,
PBI_AEP_Shipments_Multi[Year]=[Year LY]))


Sales TY RR =
CALCULATE([Sales TY]/[Current Month])*12


Sales LY by Rank =
CALCULATE( [Sales LY],
FILTER( VALUES( PBI_AEP_CustMaster135[CUSTOMER NAME - CODE]),
COUNTROWS(
FILTER( 'Customer Rank Group',
RANKX( ALL( PBI_AEP_CustMaster135[CUSTOMER NAME - CODE] ), [Avg Total Sales],, DESC ) >= 'Customer Rank Group'[Min]
&& RANKX( ALL( PBI_AEP_CustMaster135[CUSTOMER NAME - CODE] ), [Avg Total Sales],, DESC ) <= 'Customer Rank Group'[Max] ) )
> 0 ) )


Sales TY RR by Rank =
CALCULATE( [Sales TY RR],
FILTER( VALUES( PBI_AEP_CustMaster135[CUSTOMER NAME - CODE]),
COUNTROWS(
FILTER( 'Customer Rank Group',
RANKX( ALL( PBI_AEP_CustMaster135[CUSTOMER NAME - CODE] ), [Avg Total Sales],, DESC ) >= 'Customer Rank Group'[Min]
&& RANKX( ALL( PBI_AEP_CustMaster135[CUSTOMER NAME - CODE] ), [Avg Total Sales],, DESC ) <= 'Customer Rank Group'[Max] ) )
> 0 ) )


Gain/Loss TY v LY by Rank =
CALCULATE( [Gain/Loss TY v LY],
FILTER( VALUES( PBI_AEP_CustMaster135[CUSTOMER NAME - CODE] ),
COUNTROWS(
FILTER( 'Customer Rank Group',
RANKX( ALL( PBI_AEP_CustMaster135 ), [Avg Total Sales],, DESC ) >= 'Customer Rank Group'[Min]
&& RANKX( ALL( PBI_AEP_CustMaster135 ), [Avg Total Sales], , DESC ) <= 'Customer Rank Group'[Max] ) )
> 0 ) )

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.