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
Nobie
Helper II
Helper II

Rank on Calculated measure

Hi , 
 I need help plz provide the solution.
Below is a pseudo data for understanding and currently working in Direct query .
i have line and stacked bar chart . 

in x-axis I have 2 dimension Product and checks. Checks contains T,F,N values.
In columns y axis I have a calculated measure sales and  Legend is category columns.
I have several filters and paramters applied.
I am trying to create a rank function ,
code:    RANKS( 
                        SUMMARIZE( ALLSELECTED( 'Table'),  'Table'[Product],'Table[Checks],'Table'[Category]),
                       [Sales], ,DESC,DENSE)
but for 2 product i am getting same rank and but 2 product didn't have the same values .

Nobie_0-1685556487051.png

Please help in these.

 

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @Nobie 

You can refer to the following measure

Measure = var a=SUMMARIZE(ALLSELECTED('Table'),[Product],"Sum",SUM('Table'[Sales]))
var b=ADDCOLUMNS(a,"Rank",RANKX(a,[Sum],,DESC,Dense))
return MAXX(FILTER(b,[Product] in VALUES('Table'[Product])),[Rank])

Output

vxinruzhumsft_0-1686020418889.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
v-xinruzhu-msft
Community Support
Community Support

Hi @Nobie 

You can refer to the following measure

Measure = var a=SUMMARIZE(ALLSELECTED('Table'),[Product],"Sum",SUM('Table'[Sales]))
var b=ADDCOLUMNS(a,"Rank",RANKX(a,[Sum],,DESC,Dense))
return MAXX(FILTER(b,[Product] in VALUES('Table'[Product])),[Rank])

Output

vxinruzhumsft_0-1686020418889.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Can u plz tell me what does statement after return doing?

vanessafvg
Super User
Super User

can you provide some sample data with your expected solution?





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!




i have attached a excel .
basically i want the rank on the basis on Product on basis on sales and line and checks to be ignored .

Nobie_0-1685597585801.png

 

Hi thanks, but where is the attachment?  I need the data in text format to do this. 





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!




this is the table .

ProductLineChecksSales
Product AL1N2601
Product AL1N 
Product AL1T23
Product AL2N 
ProductBL1N538
ProductBl1T130
ProductBL2N 
Product CL1N277
Product CL1T15
Product CL2N 

this is the output table

ProductLineChecksSalesRANKS
Product AL1N26011
Product AL1N 1
Product AL1T231
Product AL2N 1
ProductBL1N5382
ProductBl1T1302
ProductBL2N 2
Product CL1N2773
Product CL1T153
Product CL2N 3

below is the summary

Product salesRanks
Product A26241
Product B6682
Product C2923



hi see attached.  you will need a product table for this solution that needs to be joined to your table.

vanessafvg_1-1685735095622.png

 

Product Rank =
IF (
ISINSCOPE ( 'Product'[Product] ),
RANKX ( ALLSELECTED ( 'Product'[Product] ), CALCULATE ( [total sales] ) )
)

 

the inscope is to prevent the rank from showing at the total level

 





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!




Hi, Thanks for the help that didn't work
this didn't worked. I am attaching google drive link excel 

when you said it didn't work, please make sure you explain what it is your are expecting so we on the same page.  I am assuming you mean its saying rank 1,3 and you wanting rank 1,2.

 

all you need to do is change your rank to allselected rather than all and then it will only use the selected values.  Otherwise it will scan all your data regardless of what you are selecting.

 

RNK =
RANKX (
ALLSELECTED ( 'data 1'[Product], 'data 1'[Product] ),
CALCULATE ( [Sum Of Sales], ALLEXCEPT ( 'data 1', 'data 1'[Product] ) ),
,
DESC,
DENSE
)

 





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!




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.

Top Solution Authors