Skip to main content

Notifications

Community site session details

Community site session details

Session Id : lStKreqvgdUUk928gzuTqj
Power Apps - Building Power Apps
Unanswered

Access a Collection property Dynamically with Variable

Like (0) ShareShare
ReportReport
Posted on 12 Apr 2022 07:33:55 by

 

Hi Power Platform Community, do you know if it is possible to access a collection property dynamically in power apps?

 

rico98_0-1649748640859.jpeg

 

I have the following myMonth property that I want to use to dynamically access the value of a property.

 

and accessing it simply gives me an error like this:

rico98_1-1649748640859.jpeg

 

I am basically trying to reproduce a transposed table. 

Happy for any workaround to being introduced. Thank you.

 

Regards,

Rico.

 

  • Suggested answer
    BostonSailor Profile Picture
    150 on 07 Sep 2024 at 15:48:21
    Access a Collection property Dynamically with Variable
    You can't in Power Apps, but you can in Power Automate. I face this often when a custom connector returns a JSON dictionary rather than a JSON array.
     
    SampleArray:
    [
      {"Key": "ABCD", "Value": 1},
      {"Key": "EFGH", "Value": 2}
    ]
     
    SampleDictionary:
    {
      "ABCD":
        {"Value": 1},
      "EFGH":
        {"Value": 2}
    }
     
    To find a value in the array, I might:
    LookUp(SampleArray, Key="ABCD").Value
     
    If the key I want is a constant, then I could do this in the dictionary:
    SampleDictionary.ABCD.Value
     
    But let's say the key I want is a string variable called MyKey. I might want to say:
    SampleDictionary.MyKey.Value   // That surely won't work
    LookUp(SampleDictionary, Key=MyKey).Value  // That won't work either, as the dictionary is not a table
     
    In desperation, I end up writing a short Power Automate flow, passing the dictionary (or whatever) into the flow as a JSON string.
    After whatever massaging is needed to create Compose actions with my dictionary and my key, I can then use an expression like this:
    Outputs('SampleDictionary')?[Outputs('MyKey')]
    and get value(s) from that as...
    Outputs('SampleDictionary')?[Outputs('MyKey')]?['Value']
     
    If you haven't already, it may require a new learning curve to get familiar with Power Automate (whose language bears no resemblance to Power Fx). But as far as I know it's the only way to do it. 
     
     
     
  • WarrenBelz Profile Picture
    146,670 Most Valuable Professional on 16 Apr 2022 at 05:41:53
    Re: Access a Collection property Dynamically with Variable

    @Anonymous ,

    If you want confirmation on @C-Papa 's explanation of dynamic referral of Power Apps elements such as Field, List or Control names, then it is absolutely correct - you simply cannot do it.

  • Community Power Platform Member Profile Picture
    on 12 Apr 2022 at 09:31:33
    Re: Access a Collection property Dynamically with Variable

    Thank you so much for your detailed suggestion and explanation.

    I will take this into consideration. Have a great day.

  • C-Papa Profile Picture
    1,836 on 12 Apr 2022 at 09:29:21
    Re: Access a Collection property Dynamically with Variable

    In that case i think you are unlikely to get an app that works for them through PowerApps. By doing it the way i suggested you will still get the correct data, it will also allow you to filter much better and your table will not be so large. you have to remember that if your table is growing in columns year on year you will get to a point where its not useable. i can't see this being a scalable approach. 

     

    if you google "powerapps select column dynamically" you will see lots of threads where this has previously been talked about. Good luck

  • Community Power Platform Member Profile Picture
    on 12 Apr 2022 at 09:19:12
    Re: Access a Collection property Dynamically with Variable

    Thanks for your suggestion.

     

    But this is the business requirements, they want to be able to add a new month as a column.

     

    Regards,

    Rico.

  • C-Papa Profile Picture
    1,836 on 12 Apr 2022 at 09:17:12
    Re: Access a Collection property Dynamically with Variable

    You can't pass the column name dynamically into the function. you would need to use the If or Switch function to change the formula for all of the months, but this isn't really scalable. I would have probably done it a bit differently by having a "Date" column rather than a new column for every year. This would allow you to filter the database based on a date and return the values you need, which would all be in one column.  Concat() would then work as expected. 

  • Community Power Platform Member Profile Picture
    on 12 Apr 2022 at 08:59:01
    Re: Access a Collection property Dynamically with Variable

    Thanks for your suggestion. I tried something like you suggested, but still not getting the right value.

     

    Basically, I want to get this value:

    rico98_0-1649753874427.png

     

    But I am getting the following value instead:

    rico98_1-1649753923791.png

    Is there anything that I did wrong.

    I tried without the Text function too.

     

     

  • C-Papa Profile Picture
    1,836 on 12 Apr 2022 at 08:22:53
    Re: Access a Collection property Dynamically with Variable

    hi, you need to use the Concat() function to do this. something like Concat(Table1,Text(myMonth,"dd-mm-yyyy"),", ")

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,670 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,015 Most Valuable Professional

Leaderboard