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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
rschaudhr
Resolver II
Resolver II

Index Match Ranking top 3

I would like to rank the top three values from each row and place it in the 1st, 2nd and 3rd row. In the figure below it shows for row 1 (for example), D has the highest value of 90 and it will show up in the 1st column. 20 is the second largest number will show up in 2nd column and so on for the 3rd column. The excel sheet is using formula of index match and large. Is there a way to do this in Power BI. 

 

rschaudhr_0-1611786551927.png

Thanks in advance 

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Here is one way to do this.

 

1.  Add an index and unpivot your data in the query editor.  I mocked up some data to demonstrate.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmMgNlGK1YkGkhAeSNQQLGIIloOJxsYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t, D = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}, {"D", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Row", 1, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Row"}, "Attribute", "Value")
in
#"Unpivoted Other Columns"

 

I called the table "AD"

 

2.  Make a second DAX table to hold your Rank values with an expression like this

 

RankTable = GENERATESERIES(1,3,1)
 
3.  Make this measure
 

Letter At Rank =
VAR vThisRank =
    SELECTEDVALUE ( RankTable[Value] )
VAR vSummary =
    ADDCOLUMNS (
        VALUES ( AD[Attribute] ),
        "cRank",
            RANKX (
                ALLSELECTED ( AD[Attribute] ),
                CALCULATE (
                    SUM ( AD[Value] )
                )
            )
    )
RETURN
    MINX (
        FILTER (
            vSummary,
            [cRank] = vThisRank
        ),
        AD[Attribute]
    )

 

4.  Make a matrix visual with the RankValues on columns, the AD[Attribute] column on rows and the measure on values to get this result.

 
 
 
 
 

Screenshot 2021-01-27 185323.png

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This will depend upon how the raw data is structured.  Share the link from where i can download your PBI file.


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

Here is one way to do this.

 

1.  Add an index and unpivot your data in the query editor.  I mocked up some data to demonstrate.  To see how it works, just create a blank query, go to Advanced Editor, and replace the text there with the M code below.

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUTICYmMgNlGK1YkGkhAeSNQQLGIIloOJxsYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [A = _t, B = _t, C = _t, D = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"A", Int64.Type}, {"B", Int64.Type}, {"C", Int64.Type}, {"D", Int64.Type}}),
#"Added Index" = Table.AddIndexColumn(#"Changed Type", "Row", 1, 1, Int64.Type),
#"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Row"}, "Attribute", "Value")
in
#"Unpivoted Other Columns"

 

I called the table "AD"

 

2.  Make a second DAX table to hold your Rank values with an expression like this

 

RankTable = GENERATESERIES(1,3,1)
 
3.  Make this measure
 

Letter At Rank =
VAR vThisRank =
    SELECTEDVALUE ( RankTable[Value] )
VAR vSummary =
    ADDCOLUMNS (
        VALUES ( AD[Attribute] ),
        "cRank",
            RANKX (
                ALLSELECTED ( AD[Attribute] ),
                CALCULATE (
                    SUM ( AD[Value] )
                )
            )
    )
RETURN
    MINX (
        FILTER (
            vSummary,
            [cRank] = vThisRank
        ),
        AD[Attribute]
    )

 

4.  Make a matrix visual with the RankValues on columns, the AD[Attribute] column on rows and the measure on values to get this result.

 
 
 
 
 

Screenshot 2021-01-27 185323.png

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Hi Pat,

 

You solution looks good. I incorporated the solution on my pbi file. It shows some gaps inbetween. I have provided my snapshot of the issue. Would you know what the issue and solution would be?

 

rschaudhr_0-1611847646399.png

 

Thanks in advance.

I will accept this solution because it did address my original question. However, it did not solve the next ask. I will see if I can find that solution.

 

Thank you for your help.

 

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.