web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Lookup Table Column Value
Power Apps
Answered

Lookup Table Column Value

(0) ShareShare
ReportReport
Posted on by 353

Hello all,

 

I have 2 SQL Tables, they are connected via PK,FK concept. First table has the PK and the second table has the FK. I have a gallery based on the second table, now I want to lookup a record into the first table (connected via a ORDER_ID) for a column named STATUS and if the value is "DENIED", I want this record to populate the gallery. How may i go about doing this? 

 

Thanks

 

Categories:
  • mdevaney Profile Picture
    29,993 Moderator on at

    @mmattar 

    Put this code in the Items property of your gallery.

     

    SQL_Table_1

     

    Place this code in the Text property of a label in your gallery.

     

    LookUp(SQL_Table_2, PrimaryKeyColumn = ThisItem.ForeignKeyColumn, Status)

     

    Note: of course my sample table names and columns will need to be replaced by your own.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • mmattar Profile Picture
    353 on at

    Hey thanks for the reply, may i add. I want the gallery to consist of items from the second table that only show if the status of those items looked up in table 1 are "DENIED" that way my users know that these particular items need to be edited. 

  • mdevaney Profile Picture
    29,993 Moderator on at

    @mmattar 

    Wait... did you want to show Table2 in the gallery?  My bad.

     

    Put this code in the Items property of your gallery.

    Filter(
     AddColumns(
     SQL_Table_2,
     "myStatus",
     LookUp(SQL_Table_1, PrimaryKeyColumn = ThisItem.ForeignKeyColumn, Status)
     ),
     myStatus="DENIED"
    )

     

    Another idea is: you could make a SQL view to accomplish this and load it into the gallery instead.

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

  • mmattar Profile Picture
    353 on at

    So I am getting an error at ThisItem.Fk (Name isn't valid, This identifier isnt recongized and invalid use "."). Also when you "status" for the result of the lookup, is that the same as mystatus

     

    Filter(
         AddColumns(
              '[dbo].[sqlTable2]',
              "mystatus",
               LookUp('[dbo].[sqlTable1]',PK= ThisItem.Fk, status)
         ),
         mystatus="DENIED"
    )

  • mdevaney Profile Picture
    29,993 Moderator on at

    @mmattar 
    Please show a screenshot of the errors in the formula bar.  I need to see what is being highlighted 🙂

  • mmattar Profile Picture
    353 on at
    Capture.PNG
  • mdevaney Profile Picture
    29,993 Moderator on at

    @mmattar 
    Please show the whole formula.  The surrounding code may be important here too.

  • mmattar Profile Picture
    353 on at

    yup no problem

    Capture.PNG
    Capture.PNG
  • Verified answer
    mdevaney Profile Picture
    29,993 Moderator on at

    @mmattar 
    OK, I see what was wrong with my code.  ThisItem was an invalid reference.  Sometimes its tough figure these things out when we are not sitting beside one another.

     

    Filter(
     AddColumns(
     SQL_Table_2,
     "myStatus",
     LookUp(SQL_Table_1, PrimaryKeyColumn = SQL_Table_2[@ForeignKeyColumn], Status)
     ),
     myStatus="DENIED"
    )

     

    ---
    Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 243 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 204 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard