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 / Patch combination of p...
Power Apps
Answered

Patch combination of pairs

(0) ShareShare
ReportReport
Posted on by 30

Hello,

 

My power app has two Combo Box:

Combo Box 1 Name: ComboBox_USR_Logon

Connected to SQL table: D_Users

Layout: Double

Primary Text: USR_LogonName VARCHAR(50)

Secondary text: USR_FullName VARCHAR(50)

SearchField: USR_FullName

 

Combo Box 2 Name: ComboBox_selectUGP

Connected to SQL table: D_Groups

Layout: Double

Primary Text: UGP_Nr VARCHAR(50)

Secondary text: UPG_Name VARCHAR(50)

SearchField: UGP_Name

 

I need a button with a function that will write to the SQL Table all combinations of the selected UGP_Nr.

A pair of UGP_Nr combinations must be separated by *

 

Table for writing:

Name: GroupsCombination_per_User

It has two fields:

Field1: USR_LogonName VARCHAR(50)

Field2: UGP_Nr_Combinations VARCHAR(50)

 

Sample data:

ComboBox_USR_Logon: USER1

ComboBox_selectUGP: 2000, 2351, 1345

 

The table should be written in the following form:

USER1, 2000*2351

USER1, 2351*2000

USER1, 2351*1345

USER1, 1345*2351

USER1, 1345*2000

USER1, 2000*1345

 

Categories:
I have the same question (0)
  • victorcp Profile Picture
    2,350 Moderator on at

    Hi,

     

    You can create a collection with all the combination, to do that I created two loops to iterate over all the selected items if the positions is diferent it will add that item to the collection and then Patch it to your database.

     

    Here is the code:

    Clear(colCombination);
    With(
     {vCountSelected:CountRows(ComboBox_selectUGP.SelectedItems), vItems:ComboBox_selectUGP.SelectedItems},
     ForAll(
     Sequence(vCountSelected) As vIterator1,
     ForAll(
     Sequence(vCountSelected) As vIterator2,
     If(
     vIterator1.Value<>vIterator2.Value,
     Collect(
     colCombination, 
     {
     USR_LogonName: ComboBox_USR_Logon.Selected.USR_LogonName,
     UGP_Nr_Combinations:Index(vItems,vIterator1.Value).Value & "*" & Index(vItems,vIterator2.Value).Value
     }
     )
     )
     )
     )
    );
    
    Patch(
     GroupsCombination_per_User,
     colCombination
    );

     

    Any doubts please let me know

  • SlyFox Profile Picture
    30 on at

    Hi,

    The function returned an error, the screenshot in the attachment 

    Screenshot 2023-04-03 101157.jpg
    Screenshot 2023-04-03 101319.jpg
  • Verified answer
    victorcp Profile Picture
    2,350 Moderator on at

    Sorry my mistake, value is not recognize because it doesn't exist, I have corrected the formula:

     

    Clear(colCombination);
    With(
     {vCountSelected:CountRows(ComboBox_selectUGP.SelectedItems), vItems:ComboBox_selectUGP.SelectedItems},
     ForAll(
     Sequence(vCountSelected) As vIterator1,
     ForAll(
     Sequence(vCountSelected) As vIterator2,
     If(
     vIterator1.Value<>vIterator2.Value,
     Collect(
     colCombination, 
     {
     USR_LogonName: ComboBox_USR_Logon.Selected.USR_LogonName,
     UGP_Nr_Combinations:Index(vItems,vIterator1.Value).UGP_Nr & "*" & Index(vItems,vIterator2.Value).UGP_Nr
     }
     )
     )
     )
     )
    );
    
    Patch(
     GroupsCombination_per_User,
     colCombination
    );

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard