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
BI_Analyticz
Helper V
Helper V

How to Fetch the First Values while doing Lookup

I have a situation like below. I want the Status values from Table B for Table A. Common column is Status ID. But in Table B I have 3 values for Status ID = 1.

 

I usually use LookUp --> Lookup(Table B.Name, Table A.Status ID, Table B.Status ID,""). How can I do it if I want all the 3 values from Table B. Yes it obviously makes Table A's one row in to 3 rows. How can we achieve this..?

 

BI_Analyticz_0-1623068467650.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @BI_Analyticz 

If you only want to get first value from each Status ID, you can add an Index column in Power Query.

My Sample:

Table A

1.png

Table B

2.png

Firstly Group all rows in Table B by [Status ID].

3.png

Add  Index M code in Advance Editor:

Indexed = Table.TransformColumns(#"Grouped Rows", {{"Row", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}})

The whole M code is as below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfIvSM1TitWBcJxz8otT4Ty3zIrUFDDPCFmhEUJhLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Status ID" = _t, Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Status ID", Int64.Type}, {"Name", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Status ID"}, {{"Row", each _, type table [Status ID=nullable number, Name=nullable text]}})
    ,Indexed = Table.TransformColumns(#"Grouped Rows", {{"Row", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}}),
    #"Expanded Row" = Table.ExpandTableColumn(Indexed, "Row", {"Name", "GroupIndex"}, {"Row.Name", "Row.GroupIndex"})
in
    #"Expanded Row"

New Table B:

4.png

Merge two tables and filter index =1.

5.png

Result is as below.

6.png

 

Best Regards,

Rico Zhou

 

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

6 REPLIES 6
Anonymous
Not applicable

Hi @BI_Analyticz 

If you only want to get first value from each Status ID, you can add an Index column in Power Query.

My Sample:

Table A

1.png

Table B

2.png

Firstly Group all rows in Table B by [Status ID].

3.png

Add  Index M code in Advance Editor:

Indexed = Table.TransformColumns(#"Grouped Rows", {{"Row", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}})

The whole M code is as below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUfIvSM1TitWBcJxz8otT4Ty3zIrUFDDPCFmhEUJhLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Status ID" = _t, Name = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Status ID", Int64.Type}, {"Name", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Status ID"}, {{"Row", each _, type table [Status ID=nullable number, Name=nullable text]}})
    ,Indexed = Table.TransformColumns(#"Grouped Rows", {{"Row", each Table.AddIndexColumn(_,"GroupIndex", 1, 1)}}),
    #"Expanded Row" = Table.ExpandTableColumn(Indexed, "Row", {"Name", "GroupIndex"}, {"Row.Name", "Row.GroupIndex"})
in
    #"Expanded Row"

New Table B:

4.png

Merge two tables and filter index =1.

5.png

Result is as below.

6.png

 

Best Regards,

Rico Zhou

 

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

 

 

Pragati11
Super User
Super User

Hi @BI_Analyticz ,

 

You will have to create a join between these 2 tables in Power Query Editor. See the blog below:

https://radacad.com/how-to-change-joining-types-in-power-bi-and-power-query

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

@Pragati11  Is there a way to pick the the first value from Table B?

Hi @BI_Analyticz ,

 

To get just the first value, you can use FIRSTNONBLANK dax function. See the details below:

https://docs.microsoft.com/en-us/dax/firstnonblank-function-dax

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

I am unable to use FIRSTNONBLANK in Merge or in Lookup

Hi @BI_Analyticz ,

 

You don't use FIRSTNONBLANK with LOOKUP function.

Check the following thread on how to use this function:

https://community.powerbi.com/t5/Desktop/Lookupvalue-only-first-result/m-p/244009

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.