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:
I have the same question (0)
  • mdevaney Profile Picture
    29,991 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,991 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,991 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,991 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,991 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 551

#2
WarrenBelz Profile Picture

WarrenBelz 430 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 298

Last 30 days Overall leaderboard