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 / Choose a column depend...
Power Apps
Answered

Choose a column depending on the Header

(0) ShareShare
ReportReport
Posted on by 32

Hi everyone,

I am building an app in which I record some data from users inputs and depending on the chosen option in a dropdown list, I want to use that value to indicate the column name I am going to enter some data later. I've tried some other solutions and none of them worked. This is the last one I've tried, using a global variable but when I try to call it later it gets some error.

 

 

 

//Block in which, depending what data is saved if there is a previous order with the same Contract.
Set(Variable,Ddwn_device.SelectedText.Value);
If(
 //Condition for modifying an existing record
Not(IsBlank(LookUp(Registry,Contract=contract.Text))),Patch(Registry,LookUp(Registry,Contract=contract.Text),{Total_Quantity:LookUp(Registry,Contract=contract.Text,Total_Quantity)+Value(quantity.Text)},{Value(Variable):Value(quantity.Text)}),
 //Condition for creating a new record
Patch(Registry,Defaults(Registry),{Contract:contract.Text},{Date:Text(Date.SelectedDate)},{Customer:customer.Text},{Country:Ddwn_country.SelectedText.Value},{Requested_Date:Text(RequestedDate.SelectedDate)},{Condition:Ddwn_condition.SelectedText.Value},{Total_Quantity:quantity.Text}))

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Categories:
I have the same question (0)
  • Verified answer
    v-jefferni Profile Picture
    Microsoft Employee on at

    Hi @RC6 ,

     

    Column names should be static in your case. So, using variable is not an option. To accomplish your need, you can use a Switch function:

    //Block in which, depending what data is saved if there is a previous order with the same Contract.
    Set(Variable,Ddwn_device.Selected.Value);
    If(
     //Condition for modifying an existing record
    Not(IsBlank(LookUp(Registry,Contract=contract.Text))),Patch(Registry,LookUp(Registry,Contract=contract.Text),{Total_Quantity:LookUp(Registry,Contract=contract.Text,Total_Quantity)+Value(quantity.Text)},Switch(Variable, "Value1",{Value1:Value(quantity.Text)}, "Value2",{Value2:Value(quantity.Text)}, "Value3",{Value3:Value(quantity.Text)}, "Value4",{Value4:Value(quantity.Text)}, ...),
     //Condition for creating a new record
    Patch(Registry,Defaults(Registry),{Contract:contract.Text},{Date:Text(Date.SelectedDate)},{Customer:customer.Text},{Country:Ddwn_country.Selected.Value},{Requested_Date:Text(RequestedDate.SelectedDate)},{Condition:Ddwn_condition.Selected.Value},{Total_Quantity:quantity.Text}))

     

    Best regards,

  • RC6 Profile Picture
    32 on at

    Hi, sorry for the late answer, but I was really busy and kept this app aside for a while.

    Look, I've tried what you suggested here but didn't work. I got rid of the variable and used instead of a 'Switch' lots of nested conditionals (If) and it worked perfectly. The thing is that in the end I am always checking the same text input and the only thing that changes is the value. Due to this, I keep on with the 'switch' statement but it never works. 

    Nonetheless, it's clear that there must be some error with the way I am using the statement. So I'll keep on trying different options with 'switch' and if it doesn't work I'll go with the nested 'If' statements.

    Thanks so much.

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