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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Lobo1908
Helper I
Helper I

Rank the string according to the highest rank value in it.

Hi, 

 

I have a lookup table with a list of codes and a rank assigned against each code.
The lookup table looks as follows:

CodeRank 
DI9001   1
DI2102   1
DI0303   2
DI0404   2
DI6005   3
DI5006   3 
DI0307   3
DI0018   4
DI0019   4
DI0020   4

 

I also have a data table with a string of codes assigned to parts. 

Please see below:

 

Part #Codes 
Part 1 DI9001 DI2102 DI6005
Part 2DI9001 DI0020 DI5006
Part 3DI9001
Part 4DI5006
Part 5DI0307
Part 6 
Part 7DI9001 DI0020
Part 8DI9001 DI0303
Part 9DI0307 DI0020
Part 10DI0020 DIV090

 

 

Please note that in the string there are values that should be ingored as they are not present in the lookup table.

In this eg it is DIV090.

 

What I'm looking for is for power bi to review the stirng of codes and assigned rank to the part based on the highest ranked code in the string according to the lookup table

 

Solution should look as follow.

 

 

Part #Codes Rank
Part 1 DI9001 DI2102 DI6005   3
Part 2DI9001 DI0020 DI5006   4
Part 3DI9001   1
Part 4DI5006   3
Part 5DI0307   3
Part 6  
Part 7DI9001 DI0020   4
Part 8DI9001 DI0303   2
Part 9DI0307 DI0020   4
Part 10DI0020 DIV090   4

 

 

Could someone support please.

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @Lobo1908 

the solution consists 3 steps:

1) split the codes column to rows with Power Query, 

2) connect the splitted table with the lookup table

3) get the expected RankTable

 

here comes the details:

1) split to rows

image.png

2) connect with the lookup table

FreemanZ_1-1670250186538.png

 

3) create a new table with this:

RankTable =
ADDCOLUMNS(
    VALUES(TableName[PartNo]),
    "Rank",
    CALCULATE(
        MAXX(
            TableName,
            RELATED(Lookup[Rank])
        )
    )
)

 

the result looks like this:

FreemanZ_0-1670250162869.png

 

View solution in original post

1 REPLY 1
FreemanZ
Super User
Super User

hi @Lobo1908 

the solution consists 3 steps:

1) split the codes column to rows with Power Query, 

2) connect the splitted table with the lookup table

3) get the expected RankTable

 

here comes the details:

1) split to rows

image.png

2) connect with the lookup table

FreemanZ_1-1670250186538.png

 

3) create a new table with this:

RankTable =
ADDCOLUMNS(
    VALUES(TableName[PartNo]),
    "Rank",
    CALCULATE(
        MAXX(
            TableName,
            RELATED(Lookup[Rank])
        )
    )
)

 

the result looks like this:

FreemanZ_0-1670250162869.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

Find out what's new and trending in the Fabric community.