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

Dynamic Fields based on a chosen value

I want to display related fields based on what year I select. Let's say I have the said fields, named CG_2016, CG_2017, CG_2018, CG_2019, CG_2020. I have a dropdown of the said years, when I select 2020, I want to display the data for the fields, CG_2018, CG_2019, and CG 2020. I'm trying to do this in a gallery. 

To illustrate:

If I choose 2020, my Gallery would look like this:

ThisItem.CG_2018      ThisItem.CG_2019      ThisItem.CG_2020

 

If I choose 2019, my gallery would look like this:

 

ThisItem.CG_2017      ThisItem.CG_2018      ThisItem.CG_2019

 

I know I can simply do this by using an if statement for the visibility but my data table is expected to grow through the years, thus I was wondering if there are other possible solutions. Please help and thank you in advance.

 

1 ACCEPTED SOLUTION

Accepted Solutions
v-siky-msft
Community Support
Community Support

Hi @santoscp_mwci ,

 

If my understanding is correct, you are seeking a way to reference the column dynamically, e.g. Variable, right?

However, it is not supported in PowerApps currently, please vote for this existing idea . 

You have to hardcode the column into the expression. If you want more streamlined code, I would suggest you try with Switch function, which is much simpler than If function.

Siwtch(DropdownName.Selected.Value, "2020", ThisItem.CG_2020, "2019", ThisItem.CG_2019)

Hope this helps.
Sik

View solution in original post

1 REPLY 1
v-siky-msft
Community Support
Community Support

Hi @santoscp_mwci ,

 

If my understanding is correct, you are seeking a way to reference the column dynamically, e.g. Variable, right?

However, it is not supported in PowerApps currently, please vote for this existing idea . 

You have to hardcode the column into the expression. If you want more streamlined code, I would suggest you try with Switch function, which is much simpler than If function.

Siwtch(DropdownName.Selected.Value, "2020", ThisItem.CG_2020, "2019", ThisItem.CG_2019)

Hope this helps.
Sik

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,156)