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
adnyesh
Regular Visitor

Change Rank Dynamically by user selected Filter

I am using a RANKX function in which i am passing the following statement 

 

Rank = RANKX(FILTER(ParentData,ParentData[Customer]="XYZ"),VALUE(ParentData[TurnAroundTime]),,ASC,Skip)

 

This is providing rank according to all the elements with Customer= XYZ.

Now this is working fine since the value No is static and rank column is created when the column is created. 

 

 

But i want the user to select the customer from the report filter. The value will reflect in the RANKX query on the run time and ranking will be done according to the filtered rows. 

 

e.g. 

Rank = RANKX(FILTER(ParentData,ParentData[Customer]="{Value from selected Filter}"),VALUE(ParentData[TurnAroundTime]),,ASC,Skip)

1 ACCEPTED SOLUTION

@adnyesh

 

Try to add an index column and create a measure as below.

 

RANK =
MINX (
    FILTER (
        SELECTCOLUMNS (
            ALLSELECTED ( ParentData ),
            "index", ParentData[Index],
            "rank", RANKX ( ALLSELECTED ( ParentData ), ParentData[Turn Around Time],, DESC, DENSE )
        ),
        [index] = MAX ( ParentData[Index] )
    ),
    [rank]
)

 

 Capture.PNG

 

Capture.PNG

 

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

is it possible to create a slicer for this measure. For example to choose the Top 10?

Sushmach109
Helper I
Helper I

Hi Team,

 

For Large data, this measure is not working .

For small data it is working.

May I know any similar formula for column instead of measure (OR) any similar formula that can be used in query editor?

Eric_Zhang
Employee
Employee

@adnyesh

 

I don' quite get your scenario, maybe you can try a dax as below, it ranks customer individually.

 

Rank =
RANKX (
    FILTER ( ParentData, EARLIER ( ParentData[Customer] ) = ParentData[Customer] ),
    VALUE ( ParentData[TurnAroundTime] ),
    ,
    ASC,
    SKIP
)

If it is not your case, please be more specific by posting sample data and expected output.

 

Thanks for the prompt reply, the ranking needs to be changed according the filters applied by the user at the runtime 

 

Lets consider the below scenario 

 

No Filters Selected 

 

Sr NoCustomer Name Turn Around TimeDateRank
1XYZ1016-Sep5
2XYZ516-Sep6
3XYZ2117-Sep2
4ABC2016-Sep3
5ABC2516-Sep1
6ABC1517-Sep4
7ABC1017-Sep5
8ABC2017-Sep3

 

When Selected Filter :   Customer Name = ABC 

 

Sr NoCustomer Name Turn Around TimeDateRank
1XYZ1016-Sep 
2XYZ516-Sep 
3XYZ2117-Sep 
4ABC2016-Sep2
5ABC2516-Sep1
6ABC1517-Sep3
7ABC1017-Sep4
8ABC2017-Sep2

 

 

Filter : Customer Name = ABC & Date = 17 Sep

 

Sr NoCustomer Name Turn Around TimeDateRank
1XYZ1016-Sep 
2XYZ516-Sep 
3XYZ2117-Sep 
4ABC2016-Sep 
5ABC2516-Sep 
6ABC1517-Sep2
7ABC1017-Sep3
8ABC2017-Sep1

 

Filter  Date = 17 Sep 

 

Sr NoCustomer Name Turn Around TimeDateRank
1XYZ1016-Sep 
2XYZ516-Sep 
3XYZ2117-Sep1
4ABC2016-Sep 
5ABC2516-Sep 
6ABC1517-Sep3
7ABC1017-Sep4
8ABC2017-Sep2

 

 

 

@adnyesh

 

Try to add an index column and create a measure as below.

 

RANK =
MINX (
    FILTER (
        SELECTCOLUMNS (
            ALLSELECTED ( ParentData ),
            "index", ParentData[Index],
            "rank", RANKX ( ALLSELECTED ( ParentData ), ParentData[Turn Around Time],, DESC, DENSE )
        ),
        [index] = MAX ( ParentData[Index] )
    ),
    [rank]
)

 

 Capture.PNG

 

Capture.PNG

 

Anonymous
Not applicable

@Eric_Zhang 

Hello, I am trying to solve nearly the same problem. Thanks for answer.
Why do we need index column any other unique column would do the trick? or is it need to be ordinal?

regards,

This is a great post and has helped me with my pattern I am trying to solve.

 

However the only difference is that I need to have the ranking value reset for each Customer.

 

So if I have both Customer ABC and XYZ selected then each would be ranked Individually not all together. The RANK Values would be 1, 2 and 1,2 for both customers.

 

Any ideas how I can do this. I have been searching now and over a day.

 

Thanks in advance.

@Eric_Zhang

 

Thanks for the reply, to elaborate the requirement i would give the below example of how the ranking needs to be done. The ranking would change according to the filters selected by the user at the runtime.

 

For e.g. 

 

No Filter Selected

 

Customer Name  Session   TAT      Date         Rank

XYZ                        1             20      11Sep         4

XYZ                        2             15      11Sep         5

XYZ                        3             25      12Sep         1

ABC                       4              10     11Sep         6

ABC                       5              15     11Sep         5

ABC                       6              20     12Sep         4  

ABC                       7              23     12Sep         2         

ABC                       8              22     12Sep         3

 

 

 

Filter :Customer Name = ABC

 

Customer Name  Session   TAT      Date         Rank

XYZ                        1             20      11Sep         

XYZ                        2             15      11Sep        

XYZ                        3             25      12Sep         

ABC                       4              10     11Sep          5

ABC                       5              15     11Sep          4

ABC                       6              20     12Sep          3 

ABC                       7              23     12Sep          1        

ABC                       8              22     12Sep          2

 

 

Filter :Customer Name = ABC  & Date = 11 Sep 

 

Customer Name  Session   TAT      Date         Rank

XYZ                        1             20      11Sep         

XYZ                        2             15      11Sep        

XYZ                        3             25      12Sep         

ABC                       4              10     11Sep         2 

ABC                       5              15     11Sep         1

ABC                       6              20     12Sep           

ABC                       7              23     12Sep                  

ABC                       8              22     12Sep          

 

 

 

Filter :Date = 12 Sep 

 

Customer Name  Session   TAT      Date         Rank

XYZ                        1             20      11Sep         

XYZ                        2             15      11Sep        

XYZ                        3             25      12Sep         1  

ABC                       4              10     11Sep          

ABC                       5              15     11Sep         

ABC                       6              20     12Sep          4 

ABC                       7              23     12Sep          2        

ABC                       8              22     12Sep          3

 

Hope it clarifies

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.