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 / Assigning DataTable co...
Power Apps
Answered

Assigning DataTable control to a local variable

(0) ShareShare
ReportReport
Posted on by

Hello Community,

 

Looking for a hint.

1) I have two DataTables Controls on the same screen (both filled with same External DataSource only filtering different data; I want to have both on a the same time).

2) Same Actions for both Controls are possible.

3) To reduce coding I thought I would save Controls into Local Variable and selecting with Radio which one is active.

UpdateContext({vl_TableInFocus:Blank()});
If(Self.Selected.Value = "In",UpdateContext({vl_TableInFocus:'DayInFocusTable-In'}));
If(Self.Selected.Value = "Out",UpdateContext({vl_TableInFocus:'DayInFocusTable-Out'}))

 

4) So my intenion doesn't work => system reports type type missmatch (i.e., Incompatible Type). Even if I clear the variable prior to change (as shown above).

<= imidiately after I have two out of three upper lines active, PA reports errors in program structure and App doesn't perform
<= if I use only second line (i.e., assigning DataTable to a variable once and calling variable later on) PA App performs as expected

 

Would it be possible in some other way (e.g., passing Control only as a name to a variable; if so, how to call it later on)?

 

Am I way off?!

 

Tnxs

br

@RMC-Pro

 

Categories:
  • GarethPrisk Profile Picture
    2,828 on at

    If you're trying to set the Visible property of the data tables with a variable, then you'll just need a Boolean variable and then set it on the Visible properties of each.

     

    The Self function only works on controls, and as you saw - you cannot put a control itself in a variable.

     

    Instead you just need to define the logic for when each is shown, and then you can either have the been set explicitly from a user action, or indirectly. To do it indirectly, set the Visible property equal to the value of a Toggle, for example, and have it's Default value be set dynamically.

  • Verified answer
    RMC-Pro Profile Picture
    on at

    Hello @GarethPrisk ,

    not what I need.

     

    1) I am showing both Controls at the same time.

    2) I just wanted to spare some coding - not having to write same Actions for each table and checking which one is in user's Focus; i.e., Radio Button (it is that Action is performed only on the Control that is in Focus).

     

    But as you stressed, it seems assigning DataTable to a variable is not possible. So, probably I will have to do it always with "If checking which Control is in Focus".

     

    (I will wait just a bit longer, if someone else comes up with a solution, otherwise I will mark this comment as a solution).

     

    Tnxs

    br

    @RMC-Pro 

  • v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @RMC-Pro ,

    Do you want to check which control is on focus?

    I'm afraid it's not supported to save control in a variable.

    You could save data as variable. Control is just a container of the data.

    What's more, I do not think there's property that could represent whether control is on focus.

     

    I suggest you set every control's OnSelect button to justify which control is on focus.

    Because if one control is clicked, it is on focus.

    You could set like this:

    control1's OnSelect:

    Set(var,"control1")

    control2's OnSelect:

     

    Set(var,"control2")

     

    control3's OnSelect:

     

    Set(var,"control3")

     

    control4's OnSelect:

     

    Set(var,"control4")

     

    ....

    Others are similar.

     

    You could justify which control is just being clicked based on the variable value.

     

    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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 405 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 368

#3
WarrenBelz Profile Picture

WarrenBelz 244 Most Valuable Professional

Last 30 days Overall leaderboard