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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
330SMG
Frequent Visitor

Issue with Rankx measure in Table

Hi

I have the following Measure created.  

Top5 Customers = CALCULATE([Total Orders],
FILTER(VALUES(DimCustomer[FirstName]),
IF(RANKX(ALL(DimCustomer[FirstName]),[Total Orders],,DESC)<=5,[Total Orders],BLANK())))
Total Orders is another measue I created Summing the orders
When I place this in a table for visualization I am unable to see the names of the top 5 order customers, I just get a total.  Where is this breaking?
1 ACCEPTED SOLUTION

@330SMG this is the measure for top 5 first names:

 

 

Top5 First Names = 
    CALCULATE(
        [Total Orders],
        FILTER(
            VALUES(DimCustomer[FirstName]),
            IF(RANKX(ALL(DimCustomer[FirstName]),[Total Orders],,DESC)<=5,[Total Orders],BLANK())
        )
    )

 

 


After you created the measure you need to make sure to put the right column in the visual (In this case. [FirstName], in the previous case [CustomerKey]). That is why in both cases I get the right result with the same data you have.

SpartaBI_2-1653643473252.png

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

View solution in original post

14 REPLIES 14
SpartaBI
Community Champion
Community Champion

@330SMG I tested your measure on my sample data and it's working:

SpartaBI_0-1653570427567.png

Also created a 2nd version, so you can try it, but if the 1st one didn't work then good chance this won't work neither:

Top5 Customers 2 =
CALCULATE(
[Sales Amount],
KEEPFILTERS( TOPN(5, ALLSELECTED(Customer[CustomerKey]), [Sales Amount] ) )
)
Just replace my column names with yours. 
1. Is [First Name] a unique key in your customer table?
2. Maybe you don't have a proper relatioship between dim customers and the fact?



So I changed it to the column that is the join between the tables Customer Key and same thing, it just shows the total in the visulization not the top 5.  

Oh and I tried your TopN Dax,  Same thing.  My joins all apear correct, but obviously they art not.  I am realitively new to BI and am really stumped by this.  I need to understand the mechanism on why it is not creating individual entries.  I have worked with SQL and Excel for a long time and I am a little lost on this error.

 

SpartaBI
Community Champion
Community Champion

@330SMG can you maybe share the file? It's really hard to say what is broken without looking at it in this case.

P.S.
Check out my showcase report:
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543
Give it a thumbs up if you liked it 🙂

Ok How do I share the file?  I am really new to the world of BI.

That report is impressive.

SpartaBI
Community Champion
Community Champion

@330SMG you can put in something like dropbox and share the link here or put it in your onedrive / gdrive and make that file public and put the link here.

Thanks for the compliment 🙂 Please give it a like 🙏

SpartaBI
Community Champion
Community Champion

@330SMG you used it with first name instead of key. 

SpartaBI_0-1653591377445.png

 

Top5 Customers = CALCULATE([Total Orders],
FILTER(VALUES(DimCustomer[CustomerKey]),
IF(RANKX(ALL(DimCustomer[CustomerKey]),[Total Orders],,DESC)<=5,[Total Orders],BLANK())))


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Yes I did that as an experiment and it did not work.  It is supposed to be by first name.  I should have reverted it before sharing.

SpartaBI
Community Champion
Community Champion

@330SMG didn't get what you mean.
1) With customer key it's working fo you right?
2) You want top 5 by first name?

No It did not work with customer key only getting that total not the list of people.

yes I need by first name.  

SpartaBI
Community Champion
Community Champion

Ok, no worries. It's late here so let's continue tomorrow 🙂

Please go check out my reportt and kudos it if you liked it 🙂

@330SMG this is the measure for top 5 first names:

 

 

Top5 First Names = 
    CALCULATE(
        [Total Orders],
        FILTER(
            VALUES(DimCustomer[FirstName]),
            IF(RANKX(ALL(DimCustomer[FirstName]),[Total Orders],,DESC)<=5,[Total Orders],BLANK())
        )
    )

 

 


After you created the measure you need to make sure to put the right column in the visual (In this case. [FirstName], in the previous case [CustomerKey]). That is why in both cases I get the right result with the same data you have.

SpartaBI_2-1653643473252.png

 


2022-05-19 17_30_22-Re_ Need help on DAX function with measure vs colu... - Microsoft Power BI Commu.png

Showcase Report – Contoso By SpartaBI


SpartaBI_3-1652115470761.png   SpartaBI_1-1652115142093.png   SpartaBI_2-1652115154505.png

Full-Logo11.png

Thanks, I just over thought it.

SpartaBI
Community Champion
Community Champion

@330SMG my pleasure

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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