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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
eyeball
Frequent Visitor

Using Rank in a table

Hi,

I'm trying to get to grips with the RANK function but I seem to be having a bit of trouble getting it to work.  I have a table that stores opportunities for both contacts and companies and I would like to get the top ten ranked opportunites for companies only.  To complicate matters slightly, the value column may hold NULL, 0.00 or a positive value (such as 124.16)

 

So the table would look a little like this:

 

accountid   contactid   value

1                 Null           12

2                 Null           0.00

Null            1                3

3                 Null           Null

4                 Null           45

Null            2                23

5                 Null           2.3

 

The output that I would like to achieve is:

 

accountid   value   rank

4                 45       1

1                 12       2

5                 2.3      3

etc.

 

Any help would be greatly apreciated!

 

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@eyeball

 

hi, please try this: (Is a @Sean version with little changes)

 

Ranking =
IF (
    FIRSTNONBLANK ( Table1[AccountId], Table1[AccountId] ) <> BLANK (),
    RANKX (
        FILTER ( ALL ( Table1 ), Table1[AccountId] <> BLANK () ),
        CALCULATE ( SUM ( Table1[Value] ) )
    )
)

 




Lima - Peru

View solution in original post

4 REPLIES 4
Sean
Community Champion
Community Champion

@eyeball

 

How about this...

Rank Measure =
IF (
    HASONEVALUE ( 'Table'[accountid] ),
    IF (
        ISBLANK ( MIN ( 'Table'[accountid] ) ),
        BLANK (),
        RANKX (
            FILTER ( ALL ( 'Table' ), 'Table'[accountid] <> BLANK () ),
            CALCULATE ( SUM ( 'Table'[value] ) )
        )
    )
)

Here's the result...

 

Rank Measure No Blanks.png

 

Good Luck! Smiley Happy

 

EDIT: @Vvelarde's IF (... below takes care of the text format @eyeball

(the Rank itself remains the same just the condition is changed)

 

Rank Measure No Blanks2.png

Thanks for this!! I've been trying to get Rank to work for a while now and this soution was perfect.

eyeball
Frequent Visitor

Hi Sean,

Many Thanks for this, it looks good!  The only problem I've got now is that the Id is actually a guid (sorry, should have mentioned that) so the min function is seeing it as a string...

Vvelarde
Community Champion
Community Champion

@eyeball

 

hi, please try this: (Is a @Sean version with little changes)

 

Ranking =
IF (
    FIRSTNONBLANK ( Table1[AccountId], Table1[AccountId] ) <> BLANK (),
    RANKX (
        FILTER ( ALL ( Table1 ), Table1[AccountId] <> BLANK () ),
        CALCULATE ( SUM ( Table1[Value] ) )
    )
)

 




Lima - Peru

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors