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
SaurabhDas85
New Member

Unable to use RANKX () to calculate rank for both Category and Sub-Category

Hi,

 

I have a datasets of "Company_Sales Invoice Line", "Company_Item" and "Company_Product Group". I have applied RANKX() to calculate rank for both Product Group (Category) and Item (Sub-Category). However, it is not giving me the desired result.

 

Request someone to highlight what am I doing wrong here. Measure 1 is just calculation of the Invoice Qty which is mentioned in the data set as KGs. So it has been converted to Metric Tonnes by dividing by 1000.

 

Mentioned below is the DAX code that I am using and attached herewith is the photo of my dashboard where Rank of Products are not showing of correctly whereas the same is shown correctly for the item level.

Snapshot of the dashboardSnapshot of the dashboard

Measure 1

Invoice_Qty = CALCULATE(DIVIDE(SUM('Company_Sales Invoice Line'[NetInvQty]),1000),FILTER('Company_Sales Invoice Line','Company_Sales Invoice Line'[Posting Date]<today()))
 
Measure 2
PRODRANK = RANKX(all('Company_Product Group'[Code]),[Invoice_Qty],,DESC)
 
Measure 3
DynamicRank =
SWITCH(TRUE(),
    HASONEFILTER('Company_Item'[No_]),
    RANKX(all('Company_Item'[No_]),[Invoice_Qty],,DESC),    
    ISINSCOPE('Company_Product Group'[Code]),
    [PRODRANK]
)
1 ACCEPTED SOLUTION

Hi,

You may download my solution file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

16 REPLIES 16
Ashish_Mathur
Super User
Super User

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Access Denied message


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Please confirm the email id which I have to give access to 

Make the file accessible to everyone.  I would not like to share my e-mail address.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi,

You may download my solution file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks a lot for the solution.

 

However, I also want to know what was wrong that I was doing. I was using the following code and the hierarchy was also correct i.e first the sub-category and then the category. Then was it not giving the desired result.

 

Measure 2
PRODRANK = RANKX(all('Company_Product Group'[Code]),[Invoice_Qty],,DESC)
 
Measure 3
DynamicRank =
SWITCH(TRUE(),
    HASONEFILTER('Company_Item'[No_]),
    RANKX(all('Company_Item'[No_]),[Invoice_Qty],,DESC),    
    ISINSCOPE('Company_Product Group'[Code]),
    [PRODRANK]
)

 

It's done. No need to reply anymore

You are welcome.  It was with the filter condition of amount > 0.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Try this one please

amitchandak
Super User
Super User

@SaurabhDas85 ,Based on what I got

The order should be reverse of the hierarchy, use isinscope at both places

 

IsInScope - Switch Rank at different levels: https://youtu.be/kh0gezKICEM

Please share your email id as well

Can you please do the changes in the file and share it with me. Something is there that I am not doing correctly

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.