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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
herbs
Regular Visitor

Looking up value from related table matching 2 columns

Evening,

 

I'm trying to add a value from a related table based on 2 columns values.

 

First Table (where I need the new column populated with coloured answer)

Unique CompanyRating 1Rating 2Rating 3Overall 
A(rating)(rating)(rating)(rating) 
B(rating)(rating)(rating)(rating) 

 

Related Table

Unique CompanyCategoryRating
ARating 1Good
ARating 2Satisfactory
ARating 3Very Good
AOverallGood
BRating 1Satisfactory
BRating 2Adequate
BRating 3Good
BOverallSatisfactory

 

I have tried using IF, Lookup and Switch but cannot get it quite right due to the multiple rows returning a result and breaking the query.

 

Any help appreciated 

 

1 ACCEPTED SOLUTION
v-zhangti
Community Support
Community Support

Hi, @herbs 

 

You can try the following methods.

Column:

Rating 1 = 
CALCULATE(MAX('Table 1'[Rating]),FILTER('Table 1',[Unique Company]=EARLIER('Table 2'[Unique Company])&&[Category]="Rating 1"))
Rating 2 = 
CALCULATE(MAX('Table 1'[Rating]),FILTER('Table 1',[Unique Company]=EARLIER('Table 2'[Unique Company])&&[Category]="Rating 2"))
Rating 3 = 
CALCULATE(MAX('Table 1'[Rating]),FILTER('Table 1',[Unique Company]=EARLIER('Table 2'[Unique Company])&&[Category]="Rating 3"))
Overall = 
CALCULATE(MAX('Table 1'[Rating]),FILTER('Table 1',[Unique Company]=EARLIER('Table 2'[Unique Company])&&[Category]="Overall"))

vzhangti_0-1655453083641.png

 

Measure:

Color 1 = 
IF(SELECTEDVALUE('Table 2'[Rating 1])="Good","Blue",IF(SELECTEDVALUE('Table 2'[Rating 1])="Satisfactory","Magenta"))
Color 2 = 
IF(SELECTEDVALUE('Table 2'[Rating 2])="Satisfactory","Purple",IF(SELECTEDVALUE('Table 2'[Rating 2])="Adequate","Brown"))
Color 3 = 
IF(SELECTEDVALUE('Table 2'[Rating 3])="Very Good","Green",IF(SELECTEDVALUE('Table 2'[Rating 3])="Good","Red"))
Color 4 = 
IF(SELECTEDVALUE('Table 2'[Overall])="Good","Orange",IF(SELECTEDVALUE('Table 2'[Overall])="Satisfactory","Black"))

vzhangti_1-1655453216569.pngvzhangti_2-1655453232407.png

Is this the result you expect?

vzhangti_3-1655453254829.png

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
herbs
Regular Visitor

Thanks will give this a go and report back

v-zhangti
Community Support
Community Support

Hi, @herbs 

 

You can try the following methods.

Column:

Rating 1 = 
CALCULATE(MAX('Table 1'[Rating]),FILTER('Table 1',[Unique Company]=EARLIER('Table 2'[Unique Company])&&[Category]="Rating 1"))
Rating 2 = 
CALCULATE(MAX('Table 1'[Rating]),FILTER('Table 1',[Unique Company]=EARLIER('Table 2'[Unique Company])&&[Category]="Rating 2"))
Rating 3 = 
CALCULATE(MAX('Table 1'[Rating]),FILTER('Table 1',[Unique Company]=EARLIER('Table 2'[Unique Company])&&[Category]="Rating 3"))
Overall = 
CALCULATE(MAX('Table 1'[Rating]),FILTER('Table 1',[Unique Company]=EARLIER('Table 2'[Unique Company])&&[Category]="Overall"))

vzhangti_0-1655453083641.png

 

Measure:

Color 1 = 
IF(SELECTEDVALUE('Table 2'[Rating 1])="Good","Blue",IF(SELECTEDVALUE('Table 2'[Rating 1])="Satisfactory","Magenta"))
Color 2 = 
IF(SELECTEDVALUE('Table 2'[Rating 2])="Satisfactory","Purple",IF(SELECTEDVALUE('Table 2'[Rating 2])="Adequate","Brown"))
Color 3 = 
IF(SELECTEDVALUE('Table 2'[Rating 3])="Very Good","Green",IF(SELECTEDVALUE('Table 2'[Rating 3])="Good","Red"))
Color 4 = 
IF(SELECTEDVALUE('Table 2'[Overall])="Good","Orange",IF(SELECTEDVALUE('Table 2'[Overall])="Satisfactory","Black"))

vzhangti_1-1655453216569.pngvzhangti_2-1655453232407.png

Is this the result you expect?

vzhangti_3-1655453254829.png

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello

 

Unfortunately it doesn't work which i think is due to the table it is going into rather than the formula itself (creating a circular reference)

 

To help:

 

Table "Existing" as it looks currently

Unique Company  
A  
B  

 

Table "Ratings" as it looks currrently

Unique CompanyCategoryRating
ACareGood
ATeamOutstanding
AHappyGood
BCareAdequate
BTeamAdequate
BHappyPoor
CCareOutstanding
CTeamOutstanding
CHappyGood

 

I need table "Existing" to look like

Uniqueness CompanyCareTeamHappy
AGoodOutstandingGood
BAdequate Adequate Poor
COutstanding Outstanding Good

 

Thanks again for your help so far

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attached pbix file.

It is for creating a new table.

 

Untitled.png

 

New Table = 
ADDCOLUMNS (
    VALUES ( Data[Unique Company] ),
    "@Rating 1",
        CALCULATE (
            MAXX ( FILTER ( Data, Data[Category] = "Rating 1" ), Data[Rating] )
        ),
    "@Rating 2",
        CALCULATE (
            MAXX ( FILTER ( Data, Data[Category] = "Rating 2" ), Data[Rating] )
        ),
    "@Rating 3",
        CALCULATE (
            MAXX ( FILTER ( Data, Data[Category] = "Rating 3" ), Data[Rating] )
        ),
    "@Overall", CALCULATE ( MAXX ( FILTER ( Data, Data[Category] = "Overall" ), Data[Rating] ) )
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi,

 

thanks for the reply.

 

I have the 2 tables already - its the lookup query that is needed.

 

Thanks

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors