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 / Replacement of a SQL v...
Power Apps
Answered

Replacement of a SQL view - CRUD against a table

(0) ShareShare
ReportReport
Posted on by 180

Hi there, so this is a bit difficult to explain but I'll try my best so make it sound as simple as possible:

 

Data Source = SQL

Amount of Rows = more than 2000 rows

Amount of Tables: 10+ (but for this scenario only 2)

 

Good to know: since I need more than 2000 rows, and since my Contracts table contains quite some Foreign Keys, I created a View in SQL where I basically (Left) Join the tables together. For example, in the table below you see Country. But in my Contracts table I have a column called Fk_Country and that is linked to my Countries table which has a Column named Country_Name. With the View I merged them together. The problem is that I can't delete or write against my View.... so here is my problem:

 

So this app which I'm creating is based on Contracts. And every Contract could have Insurances within the Contract.

So my Contracts table could look like this:

Contract IDNameCountryCreated DateCreated ByPk_Contract
AlphaContractAGermany22/06/2021John Doe55
BravoMercedesMexico18/07/2020Michael Brook70


Now let's say I want to add an Insurance to Bravo, I then click on the second row and then I click on a button on my page, which brings me to another screen.

 

This screen contains a Form which shows me details of Contract = Bravo, and beneath it, it shows me a Data Table. The OnVisible page of that screen looks like this:

ClearCollect(MemoryInsurancesView; Filter(InsurancesView; Fk_Contract = 'DataTable_Contracts'.Selected.Pk_Contract))


InsurancesView = the View I created in SQL, which uses the table Insurances, but the table Insurances contain Fk_Status, but since I need the Status_Name from the Statuses table... I created the InsurancesView which merges the Status_Name into Insurances by using the InsurancesView

MemoryInsurancesView = my collection based on my View from SQL.

 

Now the problem is that if someone wants to delete an Insurance from a Contract, it is not possible, since you can't delete anything from a View. When I try this:

ClearCollect(Insurances; Filter(InsurancesView; Fk_Contract = 'DataTable_Contracts'.Selected.Pk_Contract))


Then it DOES work, but I miss my LookUp columns such as Status_Name. I tried to leave Fk_Status in it and do a LookUp on the column itself, but I can't get it to work. And the formula that did work did not show me the correct Status_Name, the keys did not match.

 

I also tried the following:

 

ClearCollect(
 InsuranceMemory;
 Filter(AddColumns(
 Insurances;
 "StatusName";
 LookUp(Statusses; Fk_Status= Pk_Status ;Status_Name)
 ); Fk_Contract = DataTable_Contracts.Selected.Pk_Contract)
);;

 But this does not show me any rows at all... so I'm a bit lost and nobody from my company can help me out. So I hope one of you guys could give me a push into the right direction? Thanks in advance! If you need any more info, please let me know.

Summary: think of a receipt: a person goes to a store and buys some socks, shirts and pants. The receipt is 1 row, which is called "ReceiptID = ABC". ABC has 3 products attached to it. So when I click on ABC from my Receipts table, I go to the Products table. On top I see in a form which Receipt I am viewing (Receipt ABC) and below in a DataTable which Products are attached to it. If I want to delete Socks from the receipt, I want to select it and delete it so that Receipt ABC has no more Socks attached to it.

Problem: I am using Views from SQL and I can't delete against it. When using the standard table straight from SQL, the columns with Fk_Status etc. show up instead of Status_Name which make it confusing for the End User of my app.

Categories:
  • Verified answer
    PaulD1 Profile Picture
    2,914 on at

    Seems like a straight forward 1-to-many relationship. In your View make sure you include the ID (primary key) for the related info (insurance or receipt in your examples) then do:

    Remove(tblReceipt, LookUp(ID = ReceiptID))

    In this case ReceiptID comes from your related Receipts table and has been rename ReceiptID in your SQL view.

    After removing the record from your source table, rerun your ClearCollect on your View to populate with the latest data (i.e. without the record you just removed).

    So, in short, perform Creates, Updates, Deletes against the tables and then rerun your Views to show the latest dataset.

  • Gjakova Profile Picture
    180 on at

    Thanks for your reply, I did not try your solution yet but today I found out that one of the reasons why my Remove function does not work is because some of the Tables that I'm using to remove rows in it, are System-Versioned. Since I can't use triggers combined with Power Apps, would you happen to know if there is an alternative? Basically when rows get deleted from let's say my Insurances or Contracts tables, I want those rows to move to my History table. Since Triggers are not possible with Power Apps, I used System-Versioned, but this also seems to cause problems.

  • Gjakova Profile Picture
    180 on at

    It seems that your solution works. I did the following:

    Remove(tblReceipt, LookUp(tblReceipt, Pk_Receipt = ThisRecord.Pk_Receipt));
    Remove(MemInsuranceView, DataTable_Contracts_Receipts.Selected);
    Set(ShowPopUp_ConfirmDelete, false)

    I will try it out tomorrow at a few other tables, but is sounds promising. Many thanks!

  • Verified answer
    Gjakova Profile Picture
    180 on at

    The formula to help me delete the row from SQL was: 

    Remove(tblReceipt, LookUp(tblReceipt, Pk_Receipt = DataTable_Receipts.Selected.Pk_Receipt));

    This also works if your SQL tables have System-Versioning on it (using System-Versioning since SQL tables with triggers don't work in PowerApps).

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

#2
M Bilal Khan Profile Picture

M Bilal Khan 283

#3
Mohsin Ali Profile Picture

Mohsin Ali 221

Last 30 days Overall leaderboard