cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Shahin1
Helper I
Helper I

Identify column name and patch

Hi I have 30 columns named from 1 to 30 ... I have an input drop-down from 1 to 30 .. if the user selects number 2 ... And gives a value in textinput ... This value should get patched in that column '2'.

If user selects 30 and enters textinput.. this text input value should get patched under column '30'. 

 

Simply user should select the column as well as enter the data into that particular column..

I have tried many ways but could not fix it.

Can someone help me with this.

Thanks in advance.

4 REPLIES 4
KvB1
Solution Specialist
Solution Specialist

Unfortunately, I don't think its possible to have a dynamic value for the column you want to patch in a formula.

 

You can get around this by integrating all 30 columns in your Patch formula, but use an If( statement connected to your dropdown value to determine whether the column gets updated or not

Can you please give the formula which might be helpful for me

zmorek
Super User
Super User

Assuming you will not add more columns in the future, you could use a (big ugly) switch case:

Switch(
Dropdown1.Selected.Value,
1, Patch(DataSource, Record, {Column1: TextInput1.Text}),
2, Patch(DataSource, Record, {Column2: TextInput1.Text}),
etc.
)

RandyHayes
Super User
Super User

@Shahin1 

Sure, you can do this fairly easily from the dropdown items.

 

You have not mentioned how a particular record is chosen for your scenario, so I will make an assumption on that and you can change as needed.

 

For your Dropdown, have an Items property of:

With(LookUp(yourDatasource, yourRecordLookupCriteria),
    Table(
        {Column: "1", Data: col1, Update: {col1: TextInputConrol.Text}},
        {Column: "2", Data: col2, Update: {col2: TextInputConrol.Text}},
        {Column: "3", Data: col3, Update: {col3: TextInputConrol.Text}},
        ...etc...
        {Column: "30", Data: col30, Update: {col30: TextInputConrol.Text}}
    )
)

Replace the LookUp part with a record variable if you already have one.  Also change the column names as needed.

 

Then for your TextInput control, set the Default property to:  yourDropdown.Selected.Data

 

And, for your Update/Submit button, use the following formula on the OnSelect action:

UpdateIf(
    yourDataSource, 
    ID=yourrecordID,
    yourDropDown.Selected.Update
) 

This should give you what you are looking for.

 

One word to note on this, the Dropdown and lose its selection as PowerApps re-evaluates the Items formula on it when you update, so to avoid that, add the following formula to the OnChange action of the Dropdown:  UpdateContext({lclSel: Self.Selected.Column})  Then set the Default property of the dropdown to: lclSel

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,324)