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

Community site session details

Session Id : cDBgotbvnrAzHW8JXW6HYi
Power Apps - Building Power Apps
Answered

How to avoide duplicate rows when Save data to Entity?

Like (0) ShareShare
ReportReport
Posted on 12 Dec 2019 15:23:31 by 120

Hi all!

 

I have a strange (for me) behavior of the Save button when I try to save data to the Entity.

 

In my solution I have following Entities:

1) Modules (just a list on Modules)

2) Aspects (in each Module there are several aspects, judges shoud put Points for aspects for students)

3) Score (Entity for saving Poins for each Aspect for each Student)

 

In my solution I have a Gallery for choosing Modul. After choosing module you can see Aspects from this Modul. And you can put Points (Stars) for each Aspect in this Modul.

Also I have a Button "Save".

There are examples (screenshots):

Module2.pngModule3.png

 

 

 

 

 

 

 

 

 

 

 

 

The code for the button "Save":

 

ForAll(
 Aspects_Gallery.AllItems,
 Collect(
 Score_Collect_data,
 {
 A:Aspect_Label.Text,
 B:Type_Label.Text,
 C:MaxPoint_Label.Text,
 D:Rating1.Value
 }
 )
);
ForAll(
 Score_Collect_data,
 Patch(
 Score_demo, 
 Defaults(Score_demo),
 {
 Score: "new", 
 Aspect_score: LookUp(Aspects_demo, Aspect=A), 
 Type_score: B, 
 Max_score: Value(C), 
 Score_Number: Value(D),
 Expert_score: LookUp(Experts_demo, Experts_demo=Expert_request_Dropdown.Selected.Experts_demo),
 Member_score: LookUp(Members_demo, Members_demo=Member_Dropdown.Selected.Members_demo),
 Prof_score: LookUp(Prof_demo, Prof_demo=Prof_request_Dropdown.Selected.Prof_demo),
 Modul_score: LookUp(Modules_demo, Modules_demo=ProfModules_Gallery.Selected.Modul.Modules_demo)
 } 
 )
);
Patch(
 'Modul-Expert-Member_demo', 
 Defaults('Modul-Expert-Member_demo'), 
 {Name: Concatenate(ProfModules_Gallery.Selected.Modul.Modules_demo, " - ", Expert_request_Dropdown.Selected.Expert, " - ", Member_Dropdown.Selected.Member)}
)

 

I expect the following user experience:

1) choose Modul

2) put stars for Module's Aspects

3) press Save button for saving Points to the Entity

4) choose second Module

5) put stars for the next module's Aspect

6) press Save button for saving Points for the second Module's Aspects

etc.

 

For 1-5 all works well. But when user press Save button for saving Points for second Module's Aspects I get a strange behavior: I got duplicate rows for first module's aspect. If I choose third Module and try to press Save button - I get again duplicate rows for 1st Module and for 2nd and etc.

 

Could you please help me to find the sollution how to save Points just for Aspects that I see now in the Aspect's Gallery?

 

Thanks!

Categories:
I have the same question (0)
  • KCh Profile Picture
    120 on 17 Dec 2019 at 13:21:20
    Re: How to avoide duplicate rows when Save data to Entity?

    @yashag2255 @v-xida-msft a big thanks for your support and answers!

     

    @v-xida-msft thank you very much! I really forgot to clear collection. So simply 🙂 Thanks again!!! 🙂

  • Verified answer
    v-xida-msft Profile Picture
    on 13 Dec 2019 at 05:45:01
    Re: How to avoide duplicate rows when Save data to Entity?

    HI @KCh ,

    Based on the issue that you mentioned, I think this issue is related to the Collect function within your formula.

     

    When you press the "Save" button firstly, the Aspects_Gallery Items data would be saved into the Score_Collect_data collection. When you press the "Save" button for your second Module, the Aspects_Gallery Items data for your second Module would be saved into your Score_Collect_data collection again, but the previous stored data for your first Module is not cleared from the  Score_Collect_data collection.

     

    As an alternative solution, I think the Clear function could achieve your needs. Please consider modify your formula as below:

    Clear(Score_Collect_data); // Add this formula
    ForAll(
     Aspects_Gallery.AllItems,
     Collect(
     Score_Collect_data,
     {
     A:Aspect_Label.Text,
     B:Type_Label.Text,
     C:MaxPoint_Label.Text,
     D:Rating1.Value
     }
     )
    );
    ForAll(
     Score_Collect_data,
     Patch(
     Score_demo, 
     Defaults(Score_demo),
     {
     Score: "new", 
     Aspect_score: LookUp(Aspects_demo, Aspect=A), 
     Type_score: B, 
     Max_score: Value(C), 
     Score_Number: Value(D),
     Expert_score: LookUp(Experts_demo, Experts_demo=Expert_request_Dropdown.Selected.Experts_demo),
     Member_score: LookUp(Members_demo, Members_demo=Member_Dropdown.Selected.Members_demo),
     Prof_score: LookUp(Prof_demo, Prof_demo=Prof_request_Dropdown.Selected.Prof_demo),
     Modul_score: LookUp(Modules_demo, Modules_demo=ProfModules_Gallery.Selected.Modul.Modules_demo)
     } 
     )
    );
    Patch(
     'Modul-Expert-Member_demo', 
     Defaults('Modul-Expert-Member_demo'), 
     {Name: Concatenate(ProfModules_Gallery.Selected.Modul.Modules_demo, " - ", Expert_request_Dropdown.Selected.Expert, " - ", Member_Dropdown.Selected.Member)}
    )

     

    Please consider take a try with above solution, check if the issue is solved.

     

    Best regards,

  • yashag2255 Profile Picture
    24,690 Super User 2024 Season 1 on 12 Dec 2019 at 15:37:29
    Re: How to avoide duplicate rows when Save data to Entity?

    Hey @KCh 

     

    Can you try to use the below expression:

    ForAll(
    Aspects_Gallery.AllItems,
    Patch(
    Score_demo, 
    Defaults(Score_demo),
    {
    Score: "new", 
    Aspect_score: LookUp(Aspects_demo, Aspect=Aspect_Label.Text), 
    Type_score: Type_Label.Text, 
    Max_score: Value(MaxPoint_Label.Text), 
    Score_Number: Value(Rating1.Value),
    Expert_score: LookUp(Experts_demo, Experts_demo=Expert_request_Dropdown.Selected.Experts_demo),
    Member_score: LookUp(Members_demo, Members_demo=Member_Dropdown.Selected.Members_demo),
    Prof_score: LookUp(Prof_demo, Prof_demo=Prof_request_Dropdown.Selected.Prof_demo),
    Modul_score: LookUp(Modules_demo, Modules_demo=ProfModules_Gallery.Selected.Modul.Modules_demo)
    } 
    )
    );Patch(
    'Modul-Expert-Member_demo', 
    Defaults('Modul-Expert-Member_demo'), 
    {Name: Concatenate(ProfModules_Gallery.Selected.Modul.Modules_demo, " - ", Expert_request_Dropdown.Selected.Expert, " - ", Member_Dropdown.Selected.Member)}
    )
    
    

    Hope this Helps!

    If this reply has answered your question or solved your issue, please mark this question as answered. Answered questions helps users in the future who may have the same issue or question quickly find a resolution via search. If you liked my response, please consider giving it a thumbs up. THANKS!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473

Loading complete