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 / Gallery adds an extra ...
Power Apps
Answered

Gallery adds an extra row after saving

(1) ShareShare
ReportReport
Posted on by 6

Hi everyone,

I am implementing an Editable Grid in Power Apps following Reza Dorrani's technique (using a collection to track changes and patching back to a SharePoint list).

The setup:

  • Gallery Items: Connected to a SharePoint List

  • New Record Button: Uses Patch('List', Defaults('List'), { ... }) to initialize a new row.

  • Save Button: Uses Patch with ShowColumns and a collection of updates.

The issue:
When I click the "Save" button, the app correctly saves the data I entered, but it also creates an additional blank record (or keeps the initialized record empty) in my SharePoint list. Even though I have some validations, these "ghost" rows persist.

I've tried using ForAll to filter out blank rows before patching, but since the "New" button creates the record in SharePoint immediately to get an ID, I end up with empty rows if the user doesn't fill them correctly or if the Save logic triggers a refresh.

What I need:
How can I ensure that only rows with a valid MaterialCode (CodigoMaterial) are kept in SharePoint when the user hits Save, and why is Power Apps triggering an extra blank entry? 

The fields of Descripción and Und. are dependent dropdowns (Depend on the CodigoMaterial field) and they work with the Distinct() and Filter() functions,

I am attaching a video of the behavior. Any help would be appreciated!

Categories:
I have the same question (0)
  • Suggested answer
    Kalathiya Profile Picture
    2,456 Super User 2026 Season 1 on at
    Hello @KB-29011523-0
     
    Please try below code: 
     
    Add the following code to the OnChange property of the dropdown and TextInput controls to update the collection whenever the user changes a value:
    If(IsBlank(LookUp(colEditableGrid,ID=ThisItem.ID)),
        Collect(
            colEditableGrid,
            {
                ID:ThisItem.ID,
                CodigoMaterial: [@Dropdown1].Selected.Value, //[@Dropdown1].Selected.Value - Replace it with your control name and column name 
                Descripción: [@Dropdown1].Selected.Value, //[@Dropdown1].Selected.Value - Replace it with your control name and column name 
                ConsumoReal: [@TextInput1].Text //[@TextInput1].Text - Replace it with your control name and column name 
            }
        ),
        Patch(
            colEditableGrid, 
            {ID:ThisItem.ID},
            {
                
                CodigoMaterial: [@Dropdown1].Selected.Value, //[@Dropdown1].Selected.Value - Replace it with your control name and column name 
                Descripción: [@Dropdown1].Selected.Value, //[@Dropdown1].Selected.Value - Replace it with your control name and column name 
                ConsumoReal:[@TextInput1].Text  //[@TextInput1].Text - Replace it with your control name and column name
            }
        )
    );
     
    OnSelect of Submit button: 
    ForAll(Filter(colEditableGrid,ID >=1) As _obj, 
        Patch('List',
            {ID:_obj.ID}, 
                { 
                    Column1:_obj.CodigoMaterial, 
                    Column2:_obj.ConsumoReal 
                } 
        )
    );
    Clear(colEditableGrid);
    
    
    //Replace with list and column with your actual column and list name. 
     
     
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,963 Moderator on at
     
    Very nice video thank you.
     
    What we would need to see and note is
    1) Is this a form or are you doing a patch?
    2) need to see the actual code doing the create, but it appears to be accidentally doing a double Patch/Submit
     
    We can review your code in the button etc and anything else that reloads the Gallery. The question also is, is there a real blank row in the back end, or is what is happening is
     
    1) you click to add a new row
    2) it adds it
    3) you update it
    4) you click save
    and Save automatically causes your code to also trigger as if someone clicked the Add a Row button.
     
    You can check this pretty easy (aside from sharing the code) by doing this.
    Please follow these steps to look into Live Monitor for possible errors

    1. Please go to PowerApps.com in the environment published
    2. Please click the Apps menu option on the left
    3. Find your App in the list and Click the ... at the end
    4. Click Details ==> Live Monitor
    5. Once it opens up, click Play Published App
    6. When that Tab Opens, Play your App, Cause the issue
    7. Go back to Live Monitor Tab

    In this instance you can then go to Filter and type in Patch, or Submit etc, or just scan through the lines. It will tell you which controls were triggered, which actions like patch or submit happened, and you should be able to see the thing that added the blank row (again as if your add a row button was clicked).



     
  • Suggested answer
    Assisted by AI
    VASANTH KUMAR BALMADI Profile Picture
    322 on at

    This is a very common side-effect of the “Reza editable grid pattern”, and you’ve already identified the root cause correctly.

    The problem is not your Save button — it’s the moment you create the record.

    ✅ Why the “ghost” record is created

    This line is the real issue:

    Patch(
        'Materials',
        Defaults('Materials'),
        { ... }
    )
    

    When you do this on New Row, Power Apps:

    1. Immediately creates a row in SharePoint

    2. SharePoint assigns an ID

    3. The row exists permanently

    4. Your editable grid only updates it later

    So if the user:

    • clicks New

    • doesn’t enter required values

    • navigates away

    • Save refreshes the gallery

    ➡ that empty SharePoint row cannot be rolled back.

    Power Apps has no transaction support.

    That’s why validations and filtering during Save don’t help — the record already exists.

    🔴 This is expected behavior (not a bug)

    Reza’s demo works because:

    • users always complete the row

    • demos don’t cover abandoned rows

    • SharePoint has no draft state

    In real production apps, this pattern must be slightly modified.

    ✅ Correct and safe architecture

    ❌ Do NOT create SharePoint records on “New Row”

    ✅ Create rows only in a local collection

    Then create SharePoint records only on Save.

    ✅ The correct editable grid pattern

    Step 1 — Load data

    ClearCollect(
        colGrid,
        'Materials'
    );
    

    Step 2 — New row button

    ⚠️ No Patch here

    Collect(
        colGrid,
        {
            ID: Blank(),
            CodigoMaterial: Blank(),
            Descripción: Blank(),
            Und: Blank(),
            IsNew: true,
            IsDirty: true
        }
    );
    

    This row exists only in memory.

    Step 3 — Track edits

    On each input control:

    Patch(
        colGrid,
        ThisItem,
        {
            CodigoMaterial: Self.Selected.Value,
            IsDirty: true
        }
    );
    

    Your dependent dropdowns will still work normally.

    Step 4 — Save button logic

    This is the critical part.

    ForAll(
        Filter(
            colGrid,
            !IsBlank(CodigoMaterial) &&
            IsDirty = true
        ),
        If(
            IsNew,
            Patch(
                'Materials',
                Defaults('Materials'),
                {
                    CodigoMaterial: CodigoMaterial,
                    Descripción: Descripción,
                    Und: Und
                }
            ),
            Patch(
                'Materials',
                LookUp('Materials', ID = ThisRecord.ID),
                {
                    CodigoMaterial: CodigoMaterial,
                    Descripción: Descripción,
                    Und: Und
                }
            )
        )
    );
    

    ✅ Why this works

    Problem Fix
    Blank rows created No early Patch
    Empty SharePoint records Created only on Save
    Abandoned rows Never reach SharePoint
    Validations Work properly
    Dependent dropdowns Still function
    Performance Much better
    Data integrity Guaranteed

    ✅ Key rule (important)

    Never Patch Defaults() until the user clicks Save.

    That single rule eliminates 100% of ghost rows.

    ✅ If you absolutely must create the ID early

    (rare case — usually not needed)

    Then you must clean up on Save:

    RemoveIf(
        'Materials',
        IsBlank(CodigoMaterial)
    );
    

    …but this is risky and not recommended.

    ✅ Why Power Apps “creates extra rows”

    It isn’t actually creating extra rows.

    It’s doing exactly what you told it to do:

    Patch(Defaults(List))
    

    SharePoint has no concept of:

    • draft

    • pending

    • unsaved record

    Once created, it exists.

    ✅ Final recommendation

    ✔ Use collection-first editable grid

    ✔ Patch SharePoint only on Save

    ✔ Create records only when required fields exist

    ✔ Never initialize SharePoint rows early

    ✅ Summary

    • Your logic is correct

    • Your validations are correct

    • The behavior is expected

    • The fix is architectural

    Create locally → validate → then patch.

    This is the production-safe version of Reza’s editable grid pattern.

  • BCBuizer Profile Picture
    22,833 Super User 2026 Season 1 on at
     
    I think your reply might be an AI-assisted post, but I do not see any tools or sources cited. Can you update the post to include your sources, or confirm this was not produced using AI?
     
    Please refer to the Use AI responsibly section of Writing effective responses in the community:
     
    Thank you!
  • Verified answer
    WarrenBelz Profile Picture
    155,838 Most Valuable Professional on at
    Firstly I note and support @BCBuizer's comment on the use of AI in @VASANTH KUMAR BALMADI's post.
     
    Also I have a blog on a model for an Editable Gallery that may be of some use to you here.
     
    Please Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider answering Yes to Was this reply helpful? or give it a Like
    Visit my blog
    Practical Power Apps    LinkedIn  
  • KB-29011523-0 Profile Picture
    6 on at
    Thank you for your help
    I tried what you said about checking the lines in Live Monitor but it didn't let me, it says that I don´t have a power app plan, thats odd because the rest of options work fine in power apps.
    Because of that I'm going to send you the code of the buttons, "Agregar Consumo" (Add Consumption), "Guardar Consumo" (Save Consumption) (they both have a patch), and another two button that I have inside the gallery, one for getting the changes of the controls and another one for deleting any register of the buttons.
    Hope you can check the files when you have time
    Thanking you for your support again
    Greetings to you Michael
     
     
     
     
     

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 424

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
11manish Profile Picture

11manish 290

Last 30 days Overall leaderboard