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
jmandhare
Frequent Visitor

Dynamic Ranking - Contract Type, Contract Name, and Total Amount - Rankx

Hello All,

 

I am currently facing an issue with creating a dynamic rank. I am still at the beginning phase of DAX so not able to crack how rankx works. 
Problem:

I have two tables view_contracts and view_payments


View_contracts  has the following columns in it
contracts_id   contract_name   contract_type

1201                     ABC                   On_call

2311                     DEF                    On-call
5402                     GHI                    MD

7402                     JKL                    PS


View_Payments has the following columns in it:
contracts_id   Total Amount     Approved_at_date    Status

1201                     400                   01.01.2022           Approved

1201                     200                   02.01.2022           Decline
1201                     100                   03.02.2022           Approved

2311                     4000                 01.01.2022           Approved

2311                     8000                 05.01.2022           Approved

5402                     9000                 01.01.2022           Approved
7402                     2000                 01.01.2022           Approved


The result I want to achieve:

I want to rank sum of view_payments[total amount] of each view_payments[Contract_id] by View_Contracts[Contract_type] and it should be dynamic- so if I change the view_payments[Approved_at_date] filter it should change the visual accordingly and as per those dates assigning new ranks and showcase View_Contracts[contract_names] and view_payments[total amount] approved in those days.
Here is the result I want to showcase if i consider filter view_payments[approved_at_date] between 01.01.2022 to 02.01.2022  && view_payments[status] = 'Approved':

Contract Type       Contract Name  Total Amount   Rank
On-Call                   ABC                     500                  2
On-Call                   DEF                      4000                1

MD                         GHI                      9000                 1

PS                            JKL                      2000                 1

Note: Approved_at_date and status column filter from the view_payments table will vary as per user needs. Based on those filters the RANK values should change under each contract_type as per the total amount.

Looking forward to your response.

 

1 ACCEPTED SOLUTION
jmandhare
Frequent Visitor

I guess no one able to find the solution for this yet. I was able to crack it myself. Just posting it over here if anyone wants to know the solution for it.

For this, you need to create two measures in the view_contracts table:

 
ISCategory (Require for Rank by Contract Type) = COUNTROWS('view_contracts') = CALCULATE(COUNTROWS('view_contracts'),ALL('view_contracts'), VALUES('view_contracts'[contract_type]))
 
Rankx by contract_type = IF( [ISCategory (Require for Rank by Contract Type)], RANKX( ALLSELECTED(view_contracts[contract_type]),CALCULATE(SUM(view_payments[total_amount]))), RANKX(ALLSELECTED(view_contracts[contract_name]),CALCULATE(SUM(view_payments[total_amount])),,DESC,Skip))
 
jmandhare_0-1656364611392.png

 

I have to redact some information. I hope it helps someone who is looking for it.

 

Regards,

JM

 

 

View solution in original post

1 REPLY 1
jmandhare
Frequent Visitor

I guess no one able to find the solution for this yet. I was able to crack it myself. Just posting it over here if anyone wants to know the solution for it.

For this, you need to create two measures in the view_contracts table:

 
ISCategory (Require for Rank by Contract Type) = COUNTROWS('view_contracts') = CALCULATE(COUNTROWS('view_contracts'),ALL('view_contracts'), VALUES('view_contracts'[contract_type]))
 
Rankx by contract_type = IF( [ISCategory (Require for Rank by Contract Type)], RANKX( ALLSELECTED(view_contracts[contract_type]),CALCULATE(SUM(view_payments[total_amount]))), RANKX(ALLSELECTED(view_contracts[contract_name]),CALCULATE(SUM(view_payments[total_amount])),,DESC,Skip))
 
jmandhare_0-1656364611392.png

 

I have to redact some information. I hope it helps someone who is looking for it.

 

Regards,

JM

 

 

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.