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 / Trouble with using dat...
Power Apps
Answered

Trouble with using data from one source to create a new record in second source (SQL)

(0) ShareShare
ReportReport
Posted on by 5

 

I am trying to use the results of on data source (SQL) to manage another data source (SQL).

 

In SQLdb1, I have a standard SQL view that contains store location information (LocationNumber, LocationName, LocationStreet, LocationCity, LocationState, LocationZip). I have a second SQL database, SQLdb2, that stores (LocationNumber, Username, Password). 

 

I'm trying to build an application where a user can filter down to a location by filtering a gallery with drop downs. The drop downs are driven by SQLdb1.LocationState that filters SQLdb1.LocationCity, that filters a gallery with SQLdb1 as it's data source. So far, I've been able to create this, but what I'm trying to do is have a user click a location in the gallery and go to a form with the corresponding data from the second database (SQLdb2) using the LocationNumber as the common attribute.

 

Not every LocationNumber in SQLdb1 has a record in SQLdb2. If there is a corresponding record I would like it in edit mode, if there isn't a corresponding record I would like it to be in new mode. 

 

I've tried some patch syntax, and couldn't get it to work. And I've tried a form and couldn't get it to work either. 

 

Any and all comments and recommendations greatly appreciated. 

 

Thanks!

Categories:
  • Verified answer
    timl Profile Picture
    37,409 Super User 2026 Season 2 on at

    Hi @dcasner 

    You can do this with a form. The button on the gallery control that binds to SQLdb1 would look up the corresponding record in SQLdb2. If the record exists, the formula would open the form in edit mode. If it doesn't exist, it would open the form in new mode.

    Let's say that you create a form called Form1 and you add it to a screen called DB2screen.

    The formula that you would add to your gallery button would look something like this:

    If (CountRows(Filter('[dbo].[SQLDB2Table]',
     ThisItem.LocationNumber = LocationNumber) > 0,
     NewForm(Form1),
     EditForm(Form1)
    );
    Navigate(DB2Screen)
    
    

    You would set the DataSource property of Form1 to '[dbo].[SQLDB2Table]', and the Item property to..

     Lookup('[dbo].[SQLDB2Table]', LocationNumber=YourGalleryControl.Selected.LocationNumber)

     

  • dcasner Profile Picture
    5 on at

    @timlThat did the trick, thank you so much.

  • timl Profile Picture
    37,409 Super User 2026 Season 2 on at

    You're welcome @dcasner! Glad to be of help.

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 234 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard