cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors