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
AldoMF
Frequent Visitor

Rank by company in different Periods

Hi,

 

I have a set of data for some companies for 5 different periods. I'd like to know the rank of each company in each period. The data should look like this:

 

COMPANYPeriod 1RankPeriod 2RankPeriod 3RankPeriod 4RankPeriod 5Rank
A9,46719,81917,93018,125111,5991
B4,97825,42024,32324,24725,4402
C4,16434,40934,08632,82433,9053
D1,79742,03141,84241,72141,7804
E50554795501533264115
F34273517279748153846
G2389238919410186102977
H34363478339622382978
I1631020210236832972369
J335839562129200922510

 

I have a rank maeasure like this: 

Rank = RANKX(
ALLNOBLANKROW('IDC Print Prelim'[IDC Company]),
CALCULATE(
SUM('IDC Print Prelim'[Units K]))
)
 
However, when I want to show the rank for company A in a card for period 5 I get that it's #2 qhen in reality is #1. The other issue I've found is that my rank formula takes into account ALL the data so if I'd like to show Company C in period 5 it should come as 3 but instead it comes as 4. I'd like to know how can I calculate the rank of the companies depending on the period and this to be dinamic because all the companies sell similar products that are categorizes and I'd like to drill down on the different categories to see their rank on those product categories.
 
Is this possible?
 
Thanks in advance
5 REPLIES 5
harshnathani
Community Champion
Community Champion

Hi @AldoMF ,

 

Unpivot your table like shown below.

 

1.jpg

 

Post this you can create a Calculated Column

Rank = RANKX(FILTER('Table','Table'[Period] = EARLIER('Table'[Period])),'Table'[Value])

 

2.JPG

 

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

 

amitchandak
Super User
Super User

@AldoMF , Try like

Rank = RANKX(
allselected('IDC Print Prelim'[IDC Company]),
CALCULATE(
SUM('IDC Print Prelim'[Units K]))
)

 

or

Rank = RANKX(
filter(allselected('IDC Print Prelim'[IDC Company],'IDC Print Prelim'[period]) [period] =max([period])),
CALCULATE(
SUM('IDC Print Prelim'[Units K]))
)

 

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/3...

Thank you, the first option returns 1 always, no matter what company I show on the card

The second option marks me error in this part: 
'IDC Print Prelim'[period]) [period] =max([period])),

 

Thank you again for your help

Anonymous
Not applicable

Your table has to be unpivoted first to the form: Company|Period|Value. This is the T table. Then, you can create a measure:

[Total Value] = SUM( T[Value] )

[Rank] = 
IF( ISINSCOPE( T[Company] ),
    RANKX(
        ALLSELECTED( T[Company] ),
        [Total Value],,DESC,Dense
    )
)

This is so-called 'top-level measure' and should never be used in any iterators only in visuals (to know why please read about ALLSELECTED on www.sqlbi.com)

 

Now, if you put your companies on rows and periods on columns and drop the [Rank] measure onto the canvas, you'll get exactly what you've shown above.

Thank you but I think that's not what I need. I need a measure that gives me a rank for the company in a certain period of time and that rank and company's information will be showed in a multi row card. If I use your method, the rank in teh card will always be 1 as I'm selecting one company 

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.