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
Anonymous
Not applicable

How to have lookup values in another table with condition?

Hi There,

 

I have two source of table which i would like to combine my data.

 

Table 1 contains information of the actual spend of the product code and the sourcing status. The principal name has an error for all code that has 'Single' as their sourcing status:

CodeSpendPrincipalSourcing Status
10101000AgentSingle
10132000AgentSingle
10431400AgentSingle
1238300AgentSingle
12692344Principal AMultiple
12693045Principal DMultiple
1138450Principal AMultiple
1138130Principal BMultiple
1123450Principal CMultiple
1123444Principal DMultiple

 

Table 2 has the correct principal information:

CodePrincipalSourcing Status
1010Principal ASingle
1013Principal BSingle
1043Principal CSingle
1238Principal ASingle
1269Principal AMultiple
1269Principal DMultiple
1138Principal AMultiple
1138Principal BMultiple
1123Principal CMultiple
1123Principal DMultiple

 

How do i use Lookupvalue function to get the principal value for code that has "Single" status? Lookupvalue will return error if it lookup for code that has "Multiple" status as it will return multiple value where a single value is expected. 

 

Desired output:

CodeSpendPrincipalCorrect Principal
10101000AgentPrincipal A
10132000AgentPrincipal B
10431400AgentPrincipal C
1238300AgentPrincipal A
12692344Principal APrincipal A
12693045Principal DPrincipal D
1138450Principal APrincipal A
1138130Principal BPrincipal B
1123450Principal CPrincipal C
1123444Principal DPrincipal D
1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

To create a calculated column in Table 1.

Column = 
IF (
    'Table1'[Sourcing Status] = "Single",
    LOOKUPVALUE ( Table2[Principal], Table2[Code], Table1[Code] ),
    Table1[Principal]
)

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

3 REPLIES 3
v-frfei-msft
Community Support
Community Support

Hi @Anonymous ,

 

To create a calculated column in Table 1.

Column = 
IF (
    'Table1'[Sourcing Status] = "Single",
    LOOKUPVALUE ( Table2[Principal], Table2[Code], Table1[Code] ),
    Table1[Principal]
)

Capture.PNG

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
Anonymous
Not applicable

hI @Anonymous 
Try the following measure

Measure =
VAR __complete = "Single"
RETURN
CALCULATE(
MAX( Table2[Principal] ),
CUSTOMERS[Sourcing Status] = __complete
)
 a little trick I learned this week
 
Thanks!
Anonymous
Not applicable

Hi @Anonymous ,

 

The solution you proposed only returns one principal from Table 2.

 

Now the  code with the "Multiple" status is also returning Principal C, whereas i originally wanted the previous correct principal to remain. 

 

Any ideas on how to solve this?

 

 

 

Correct Principal Case Study.PNG

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.