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 / Object keyed by variable
Power Apps
Answered

Object keyed by variable

(0) ShareShare
ReportReport
Posted on by 7

Is there any correct way to do something like:

 
Set(obj,{1:"one",2:"two",3:"three"})
Set(k,2)
 
obj[k] (would return "two")
 
(Please dont tell me the only way is to make a series of if statements)
Categories:
  • jhall Profile Picture
    636 on at

    @mdennis wrote:

    Is there any correct way to do something like:

     
    Set(obj,{1:"one",2:"two",3:"three"})
    Set(k,2)
     
    obj[k] (would return "two")
     
    (Please dont tell me the only way is to make a series of if statements)

    LookUp() is the path, but you might need to alter your initial Collection slightly.  For example:  

    • ClearCollect(obj,{id:1,value:"one"},{id:2,value:"two"],{id:3,value:"three"})
    • Set(k,2)
    • LookUp(obj,id=k,value)   
      • (returns "two")

    It's possible this could be done w/o the Collection mod but I haven't tried it.

  • Pstork1 Profile Picture
    69,661 Most Valuable Professional on at

    To add to @jhall 's answer. The syntax you were trying to use is an array.  PowerApps doesn't support an Indexed array.  But as was suggested you can easily make an indexed collection of objects and then access those objects using the index.

  • Verified answer
    v-xida-msft Profile Picture
    Microsoft Employee on at

    Hi @mdennis ,

    Do you want to use the obj[k] formula to reference the value from your obj variable?

     

    Based on the formula that you mentioned, I think there is something wrong with it. Firstly, the obj[k] formula is not supported within PowerApps currently.

     

    In addition, the obj variable that you set within your app is an Object rather than an array. The obj[k] formula is used to reference values from an array.

     

    I have made a test on my side, please take a try with the following workaround:

    Set the OnStart property of the App control to following (initialize your obj variable):

    ClearCollect(obj, {Id:1, Value:"one"}, {Id:2, Value:"two"}, {Id:3, Value:"three"})

    Set the OnSelect property of a Button to following (press this button to set the k variable):

    Set(k, 2)

    Add a Label control within your app, set the Text property to following:

    LookUp(obj, Id = k, Value)

    More details about the LookUp function, please check the following article:

    LookUp function

     

    Best regards,

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
11manish Profile Picture

11manish 393 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 278 Most Valuable Professional

Last 30 days Overall leaderboard