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
wadda7
Helper I
Helper I

HELP IN LOOKUPVALUE

Hi everyone 

 

I need your help how to wite guery with lookupvalue or other fuction to update cloumn from anther table 

 

Table 1 allitems 

itemidname
01T-shirt
02Short

Table 2 inventtrans

itemidqtycostcategory
011402345678
0122402345678
0213304536235

the Reltaion between the 2 tables is (1 - *)

allitems.itemid = inventtrans.itemid  

I writed this query  in allitems table by adding new column category and update it from inventtrans table but did not work 

CATEGORY = LOOKUPVALUE(inventtrans[category],inventtrans[itemid],allitems[itemid])
 
1 ACCEPTED SOLUTION
edhans
Super User
Super User

Hi @wadda7 - you can use LOOKUPVALUE(), but I suggest the below is faster.

Category = 
MAXX(
    RELATEDTABLE('Inventory Transactions'),
    'Inventory Transactions'[category]
)

MAXX (or MAX) simply convert a table of the same value to one scalar value, so think of it like FIRST.

However, LOOKUPVALUE is this:

Category 2 = 
LOOKUPVALUE(
    'Inventory Transactions'[category],
    'Inventory Transactions'[itemid],
    'All Items'[itemid]
)

edhans_0-1631396989177.png

My PBIX is here if you want to review.







Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

8 REPLIES 8
Syndicate_Admin
Administrator
Administrator

Hello - this worked just fine for me.  I have attached the pbix.  If this didn't work for you, check the values in the itemid columns of both tables to ensure they really are the same.  It looks like your numbers are formatted as text, so the values may need to be trimmed/cleaned to remove trailing spaces or other whitespace characters.  That can easily be done in Power Query by selecting the column(s) > right-click > transform > clean/trim.

 

jennratten_1-1631395384558.png

 

 

jennratten_0-1631394487266.png

 

CATEGORY = lookupvalue ( inventtrans[category], inventtrans[itemid], allitems[itemid] )

 

Add a Column with LOOKUPVALUE.pbix 

edhans
Super User
Super User

Hi @wadda7 - you can use LOOKUPVALUE(), but I suggest the below is faster.

Category = 
MAXX(
    RELATEDTABLE('Inventory Transactions'),
    'Inventory Transactions'[category]
)

MAXX (or MAX) simply convert a table of the same value to one scalar value, so think of it like FIRST.

However, LOOKUPVALUE is this:

Category 2 = 
LOOKUPVALUE(
    'Inventory Transactions'[category],
    'Inventory Transactions'[itemid],
    'All Items'[itemid]
)

edhans_0-1631396989177.png

My PBIX is here if you want to review.







Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

this one work with me 

Category = 
MAXX(
    RELATEDTABLE('Inventory Transactions'),
    'Inventory Transactions'[category]
)

 

thank you 

Great @wadda7 - glad I was able to assist. LOOKUPVALUE is something many gravitate towards because users are used to VLOOKUP in Excel, but Power BI works differently and I rarely use LOOKUPVALUE.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting
jennratten
Super User
Super User

Hello - this worked just fine for me.  I have attached the pbix.  If this didn't work for you, check the values in the itemid columns of both tables to ensure they really are the same.  It looks like your numbers are formatted as text, so the values may need to be trimmed/cleaned to remove trailing spaces or other whitespace characters.  That can easily be done in Power Query by selecting the column(s) > right-click > transform > clean/trim.

 

jennratten_1-1631395384558.png

 

 

jennratten_0-1631394487266.png

 

CATEGORY = lookupvalue ( inventtrans[category], inventtrans[itemid], allitems[itemid] )

 

Add a Column with LOOKUPVALUE.pbix 

Hello jennratten

Yes the itemid column is text type because ite has numbers and text like this 

itemid 

0965-22345ss

 

I did the trim and clean and I got this error 

 

wadda7_0-1631397422516.png

in allitems table the itemid is uniqe but in the inventtrans table the itemid can comes more than one time

Try taking a look at the pbix that I attached in the reply on Saturday.  That had the working sample. 

Did you trim and clean the columns in both tables?

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.

Top Solution Authors
Top Kudoed Authors