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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Dee
Helper III
Helper III

Compare if value exists on another table based on a column id

Hello,

 

I happen to have two tables where am trying to compare whether the values are the same based on the unique id.

 

example:

 

Table 1

id product value alt1 alt2

aaa oranges 50  60 70

bbb bananas 70 90 80

ccc grapes 10 20 30

 

Table 2

id product value alt1 alt2

aaa oranges 50  60 70

bbb pears 70 80 90

 

 

I need help on how to compare the info as similar based on the id and return:

output would look something like this:

 

id value

aaa exists

bbb different

ccc missing

 

any help would be highly appreciated.

TIA

4 REPLIES 4
v-lid-msft
Community Support
Community Support

Hi @Dee ,

 

 

We can create a  calculate column to meet your requirement.

values =

VAR lookup_ =
    LOOKUPVALUE ( Table2[product], Table2[id], Table1[id] )
RETURN
    IF (
        ISBLANK ( lookup_ ),
        "missing",
        IF ( [product] = lookup_, "exists", "different" )
)

 

Or

 

Value_2 =
VAR i = [id]
VAR p = [product]
VAR n1 =
    CALCULATE ( COUNTROWS ( 'Table2' ), 'Table2'[id] = i )
VAR n2 =
    CALCULATE ( COUNTROWS ( 'Table2' ), 'Table2'[id] = i, 'Table2'[product] = p )
RETURN
    IF ( n1 = 0, "Missing", IF ( n2 = 1, "exists", "different" ) )

 

 

 

 

BTW, pbix as attached.


Best regards,

 

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-lid-msft 

 

Thank you so much for this detailed explanation.

 

However, how do I tweak the second formula, that compares multiple columns in a row.

 

eg in the example based on The id, I want to ensure also the product, value, alt1, and alt2 are also evaluated, so as to return the formula and not just the product.

 

Ps. These items all have to appear in the same row of the IDs, for the result to be "exists", if one is missing "Difference" if the Id doesn't appear in both tables "missing" Thank you once more for your help.

Greg_Deckler
Super User
Super User

Sounds like you need LOOKUPVALUE or a combination of MAXX(FILTER(...)...)


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Can this same thing be accomplished in Power Query?  ...to see if a record exists in one table and then perform calculation if it does.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.