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

Win a FREE 3 Day Ticket to FabCon Vienna. Apply now

Reply
Anonymous
Not applicable

Power Query Look Up Value From Another Table Based On Two Criteria

Hello. I am not that expereinced with Power Query so need some help please.

 

I have a deails table that has over 5M rows with multiple rows using the same key. I have already referenced that table to create a summary table and merged it with another table for added information.

 

Now I want to lookup a value from the details table based on criteria.

 

In the image below, I am trying to populate the column AAAA Answer in the summary table based on

 

IF "Summary Table" [Category] = "People"

THEN return the value in "Details Table"[Answer] for the rows that have "AAAA" in the column "Details Table"[Question]

 

jroger911_0-1671226743396.png

 

Thanks in advance.

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUSpIzS/ISQUyTJRidaKVTM3MLUCiOYnJCEFLA0MjTKXGJqZmqEpjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, Category = _t, Count = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Key", Int64.Type}, {"Category", type text}, {"Count", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Category]="people" 
then
Table.SelectRows(
Table.SelectRows( DETAILSTABLE, each [Question] = "AAAA" ),
((x)=>x[Key]=[Key]))[Answer]{0}
else " ")
in
    #"Added Custom"

Output:

vjianbolimsft_0-1672221132883.png

Best Regards,

Jianbo Li

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

4 REPLIES 4
v-jianboli-msft
Community Support
Community Support

Hi @Anonymous ,

 

Please try:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNlHSUSpIzS/ISQUyTJRidaKVTM3MLUCiOYnJCEFLA0MjTKXGJqZmqEpjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Key = _t, Category = _t, Count = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Key", Int64.Type}, {"Category", type text}, {"Count", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [Category]="people" 
then
Table.SelectRows(
Table.SelectRows( DETAILSTABLE, each [Question] = "AAAA" ),
((x)=>x[Key]=[Key]))[Answer]{0}
else " ")
in
    #"Added Custom"

Output:

vjianbolimsft_0-1672221132883.png

Best Regards,

Jianbo Li

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

A bit cleaner without the nested Table.SelectRows:

 

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", 
   each 
     if [Category]="people" then
        let
           search_key = [Key]
        in 
           Table.SelectRows( DETAILSTABLE, each [Question] = "AAAA" and [Key]=search_key))[Answer]{0}
      else 
         null
)

 

Retruning a space is not a good practice, use null instead. If nulls mess up queries down the road, use an empty string "".

 

and if you are sure there is always only 1 answer retrunred:

 

 

#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", 
   each 
     if [Category]="people" then
        let
           search_key = [Key]
        in 
           DETAILSTABLE{[Question = "AAAA", Key = search_key]}[Answer]
      else 
         null
)

 

 

 

amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

calculate(Max(Table[Answer]), filter(Table, Table[Question] ="AAAA"))

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks @amitchandak but I am not looking for a measure. I need it as a column in the table, but I do not want to use a calculated column becuase it will impact performance of the report. This is why I am looking for a solution in the query editor. Any thoughts?

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.