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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
iamprajot
Responsive Resident
Responsive Resident

Rank Table A according to Table B based on Decreasing Column

I want to Rank Table A according to Table B based on Decreasing Unit Price.

Something like this.

Table A   Table B 
SupplierIDUnitPriceRank SupplierIDCity
1811 1London
1182 2New Orleans
1103 3Ann Arbor
2191   
2122   
3161   
3102   
1 ACCEPTED SOLUTION

Hi @iamprajot,

 

The other columns affect the result. Try this formula please. I added another column in the sample.

Measure (or Calculated column) =
CALCULATE (
    RANKX ( ALL ( 'TableA'[UnitPrice] ), CALCULATE ( SUM ( 'TableA'[UnitPrice] ) ) ),
    ALLEXCEPT ( TableA, TableA[SupplierID], TableA[UnitPrice] )
)

Rank Table A according to Table B based on Decreasing Column2.jpg

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

Community Support Team _ Dale
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

6 REPLIES 6
v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @iamprajot,

 

Actually, the rank has nothing with table B, table A has everything. Please try this formula. It works as both a calculated column and a measure. ( The column "rank" could be an example. It should be deleted.)

 

Column / Measure =
RANKX ( ALL ( 'TableA'[UnitPrice] ), CALCULATE ( SUM ( 'TableA'[UnitPrice] ) ) )

Rank Table A according to Table B based on Decreasing Column.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

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

Hi,

Thanks for sparing time.

Result in screenshot seems good but I tried both Column/Measure but it is giving me 1 in the whole column.

Also I don't see the use of Supplier ID of Table A to categorise/group the Unit Price in the Query.

I am still curious how did that query worked for you.

Hi @iamprajot,

 

Actually grouping the Unit Price is the work of the function "RANKX". Please reference: https://msdn.microsoft.com/en-us/library/gg492185.aspx

 

If you use the formula as a Calculated Column, you need to delete the column "Rank", which I think is a description. If you use it as a measure, you need to add column "Supplier ID" and "Unit Price" in the report, which is the context. 

 

Maybe your table have other columns. Could you please post a complete sample and the snapshots of your results?

 

Best Regards!

Dale

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

Hi,

Rank Column is not actually there, it was a Result View that I showed.

I am afraid I cannot share the actual data, I hope you would understand but I assure you that the two sample tables I showed are exactly identical to what I have here.

Now I have

Table A which have two Columns Supplier ID & Unit Price &

Table B which have Column Supplier ID

Now what I wanted was to Rank Unit Prices according to the Supplier ID weather it is in Table A or Table B.

If I do not Rank it according to Supplier ID then the Unit Price will go on like 1, 2, 3 ......1000 and what I want is that for Supplier ID 1 Ranks should be 1,2,3 and then for Next Supplier ID 2 Rank should be like 1,2,3,4 (Limited to how many times Unit Prices are for a particular Supplier ID)

 

I think I have explained myself better now and

I am not sure I am going in the right direction or gonna hit a wall again but what I actually wanted was to get 3 Maximum prices for every supplier, that's why I needed to rank them so that I could pick first 3.

 

Thanks

Hi @iamprajot,

 

The other columns affect the result. Try this formula please. I added another column in the sample.

Measure (or Calculated column) =
CALCULATE (
    RANKX ( ALL ( 'TableA'[UnitPrice] ), CALCULATE ( SUM ( 'TableA'[UnitPrice] ) ) ),
    ALLEXCEPT ( TableA, TableA[SupplierID], TableA[UnitPrice] )
)

Rank Table A according to Table B based on Decreasing Column2.jpg

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

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

Remarkable !

Thanks

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors