cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ArminSimon
Helper II
Helper II

Use a variable as an identifier

Hi all,

 

Is there a way to use a variable in a formula as a column-identifier?

The following example runs well:

 

Set(varExample,Lookup(tblLabelText,ID=varID).Hospitality)

 

 

But I need a solution like:

 

Set(varCategory,Lookup(tblCategory,ID=varCatID);
Set(varExample,Lookup(tblLabelText,ID=varID).<varCategory>)

 

 

I try to use one screen for multiple categories in an app and, since a column may have different meanings in each category, I use a 'match'-table.

As an example: Using the column 'date' in the category 'hospitality' should label the text field with 'date of service' whereas in category 'overnight stay' it should label it 'date of stay'.

 

To understand here are the used table definitions:

tblLabelText

Title
(column name in data table)
hospitalityovernight stay
"date""date of service""date of stay"
"reason""reason of hosting""reason of stay"
.........

 

tblCategory

ID

Title

1

Hospitality

2

Overnight stay

3

travel ticket

...

...

 

Hope I explained my issue correct and someone is able to point me to a solution.

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
v-yujincui-msft
Community Support
Community Support

Hi @ArminSimon ,

 

Do you want to dynamically reference the column name by using variable in Power Apps?

I am afraid that there is no directly way to achieve this in Power Apps currently. It is not possible to refer to a column name with a variable or the return value of other functions.

There is a post in the ideas forum about this that you can vote on.

Patch - Referance a column name via a variable - Power Platform Community (microsoft.com)

 

If you find another way to achieve your needs, you might consider mark your answer as a 'solution' to close the case.

 

Best Regards,

Charlie Choi

View solution in original post

5 REPLIES 5
PowerRanger
Super User
Super User

@ArminSimon If I understood it correctly your main issue is that depending on the category your label text should change. 

On the label use something like this for the text property:

 

Switch(
    varCategory,
    "hospitality",
    "date of service",
    "overnight stay",
    "date of stay"
)

 

Please click Accept as solution 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 giving it Thumbs Up.




​Please click Accept as solution 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 giving it Thumbs Up.

Hi @PowerRanger ,

thanks for fast reply!

I forgot to mention, that SWITCH was my first thought as well. But since there are multiple commands within each of the switch elements and only be different by the identifier, I hoped there may exist a simpler method.

To explain it a bit further: This is code inside a FORM with a lot of elements a search and replace in VS Code looks much simpler as to put a Switch inside each element. Not to have a look to performance behaviour, especially on mobiles, at that time 😉

@ArminSimon 

What about this:

On the screen where your form is place the SWITCH command in the OnVisible function.

Switch(
    varCategory,
    "hospitality",
    Set(varLabelText1,"date of service");
    Set(varLabelText2,"...some text"),
    "overnight stay",
    Set(varLabelText1,"...some other text");
    Set(varLabelText2,"...new label text")
)

 

On your form set the label Text-Property to the corresponding variable.

So you only have the switch once defined!

 

Please click Accept as solution 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 giving it Thumbs Up.




​Please click Accept as solution 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 giving it Thumbs Up.

Thanks!

I understand, there is no way to use a variable directly or indirectly to reference a 'column'.

I am pretty at the start of this app at this point of time, so I'll come over this from the other side: I will redesign my tables... remove the tblLabelText and insert the content within the tblCategories directly as columns...

Thanks for your ideas!

Cheers

v-yujincui-msft
Community Support
Community Support

Hi @ArminSimon ,

 

Do you want to dynamically reference the column name by using variable in Power Apps?

I am afraid that there is no directly way to achieve this in Power Apps currently. It is not possible to refer to a column name with a variable or the return value of other functions.

There is a post in the ideas forum about this that you can vote on.

Patch - Referance a column name via a variable - Power Platform Community (microsoft.com)

 

If you find another way to achieve your needs, you might consider mark your answer as a 'solution' to close the case.

 

Best Regards,

Charlie Choi

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Changes to Ideas Coming

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (4,855)