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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

LOOKUP with different columns in the same excel sheet

Hi,

 

I am new to power BI. I am trying to do lookup function for the below scenario.

 

File - 1

Column 1 - Product Category (Which has codes, blanks, #)

Column 2 - Big C

 

File - 2

Column 1 - Category Group Code

Column 2 - Market Code

Column 3 - Category Code

Column 4 - Division Code

Column 5 - Sub division 2 Code

Column 6 - Big C

 

What i need is

I need Big C in File 1 by comparing the product category column of File 1 with Columns 1 to 5 in File 2 and bring in Big C which is there in File 2.

Also note that, every month the File 2 data changes and its not constant

In excel - we do based on Iferrer and V-lookup. when i try in power bi, it is giving me an error.

Please help

 

Thanks in advance!

Regards,

Vaishnavi

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi Vaishu0508,

You could try to unpivot table 2, then merge table 1 and table two, you could refer to below M code 

Table 1

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnYzNjAwUNJRUorVAfEMjQ1NkXlG5giegYERgmOKrMvMEMKJBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"PCAT " = _t, #"Big C" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PCAT ", type text}, {"Big C", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"PCAT "}, t2, {"Value"}, "t2", JoinKind.LeftOuter),
    #"Expanded t2" = Table.ExpandTableColumn(#"Merged Queries", "t2", {"Big C"}, {"t2.Big C"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded t2",{"Big C"})
in
    #"Removed Columns"

Table 2

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnYzNjAwUNIBMgyNDU2hDCNzIMMjPzdVwTmxKFUpVgek0ASqzsjAEEwbGBiBVLkpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Division Code" = _t, #"Category Code" = _t, #"Market Code" = _t, #"Big C" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Division Code", type text}, {"Category Code", type text}, {"Market Code", type text}, {"Big C", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Big C"}, "Attribute", "Value")
in
    #"Unpivoted Columns"

Best Regards,
Zoe Zhi

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

7 REPLIES 7
dax
Community Support
Community Support

Hi Vaishu0508,

You could try to create relationship between two sheets, then add column from two sheets in same table to see whetehr it work or not. Or you also could use merge query by M code to see whether it work or not. By the way, if possible, could you please inform me detailed information (such as your sample data and your expected output)? Then I will help you more correctly.

Please do mask sensitive data before uploading.

Thanks for your understanding and support.
Best Regards,
Zoe Zhi

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

 

Anonymous
Not applicable

 

Hi,

Please find below.

 

Table 1

 

PCAT             Big C

CF3000

CF1315

CF1327

 

 

Table 2

 

Division Code        Category Code            Market Code               Big C

CF3000                  CF1315                        CF1327                       Home Care

 

Regards,

Vaishnavi 

dax
Community Support
Community Support

Hi Vaishu0508,

You could try to unpivot table 2, then merge table 1 and table two, you could refer to below M code 

Table 1

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnYzNjAwUNJRUorVAfEMjQ1NkXlG5giegYERgmOKrMvMEMKJBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"PCAT " = _t, #"Big C" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"PCAT ", type text}, {"Big C", type text}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type", {"PCAT "}, t2, {"Value"}, "t2", JoinKind.LeftOuter),
    #"Expanded t2" = Table.ExpandTableColumn(#"Merged Queries", "t2", {"Big C"}, {"t2.Big C"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded t2",{"Big C"})
in
    #"Removed Columns"

Table 2

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnYzNjAwUNIBMgyNDU2hDCNzIMMjPzdVwTmxKFUpVgek0ASqzsjAEEwbGBiBVLkpxcYCAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"Division Code" = _t, #"Category Code" = _t, #"Market Code" = _t, #"Big C" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Division Code", type text}, {"Category Code", type text}, {"Market Code", type text}, {"Big C", type text}}),
    #"Unpivoted Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Big C"}, "Attribute", "Value")
in
    #"Unpivoted Columns"

Best Regards,
Zoe Zhi

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

 

 

Anonymous
Not applicable

Thank you so much.

 

I have done the Unpivot and lookup.

 

Regards,

Vaishnavi

kentyler
Solution Sage
Solution Sage

You could do a lookup in dax, looking up each column from file 2 in the product category field of file 1. You would store the results in VAR statements in your measure.

Then you would use a SWITCH statement to see  which VAR had been found, and the SWITCH would return the big C if one of the VARs was true.
you would probably use this function 

LOOKUPVALUE

  • 03/12/2019
  • 2 minutes to read
      •  
     
    •  

Returns the value in result_columnName for the row that meets all criteria specified by search_columnName and search_value.

Syntax

DAXCopy
 
LOOKUPVALUE( <result_columnName>, <search_columnName>, <search_value>[, <search_columnName>, <search_value>]…[, <alternateResult>])   

Parameters

Term Definition
result_columnNameThe name of an existing column that contains the value you want to return. The column must be named using standard DAX syntax, usually, fully qualified. It cannot be an expression.
search_columnNameThe name of an existing column, in the same table as result_columnName or in a related table, over which the look-up is performed. The column must be named using standard DAX syntax, usually, fully qualified. It cannot be an expression.
search_valueA scalar expression that does not refer to any column in the same table being searched.
alternateResult(Optional) The value returned when the context for result_columnName has been filtered down to zero or more than one distinct value. When not provided, the function returns BLANK() when result_columnName is filtered down to zero value or an error when more than one distinct value.

and here is SWITCH

Evaluates an expression against a list of values and returns one of multiple possible result expressions.

Syntax

DAXCopy
 
SWITCH(<expression>, <value>, <result>[, <value>, <result>]…[, <else>])  

Parameters

Term Definition
expressionAny DAX expression that returns a single scalar value, where the expression is to be evaluated multiple times (for each row/context).
valueA constant value to be matched with the results of expression.
resultAny scalar expression to be evaluated if the results of expression match the corresponding value.
elseAny scalar expression to be evaluated if the result of expression doesn't match any of the value arguments.

 





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Can you create a sample for both tables?

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

Anonymous
Not applicable

Hi,

 

I have posted a sample in the same post as reply as to another person. Please check

 

Regards,

Vaishnavi

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors