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 / Variable not returning...
Power Apps
Answered

Variable not returning any results

(0) ShareShare
ReportReport
Posted on by 381

I am pulling my hair out trying to understand what i am doing wrong. 

 

I have a gallery which is reading distinct sharepoint value.  This gallery is called gal_Main

 

Distinct(DataSource, MetricTitle.Value)

 

This is being through a gallery which just 4 distinct values.  All good

 

I have placed a button called Button4 on the top of the gallery, as i want to create an expandable / collapsible section for each distinct value

 

On the On Select item of the button 4 , i have the following code 

 

If(
varButton = ThisItem.Result,
Set(
varButton,
show
),
varButton = ThisItem.Result
)

 

I have then nested another gallery inside the gal_Main called gal_Content

 

the gal_content should show all the values for that distinct value. On the Items property of gal_Content  i have 

 

Filter(DataSource ,Button4.Text = MetricTitle.Value)   where button4.text is the button i placed in gal_Main. Again, all good

 

This part all works fine. The button expands perfectly well.

 

But i want the button to collapse when a user selects it . 

 

I was hoping i could create a variable on the button using the code above, and then on the visible property on gal_Content place a switch statement, but for some reason the code on the button doesn't appear to do anything. 

 

I placed a text box to show the value of the variable varButton and its always just blank... its not returning anything. 

 

Hope i made sense. 

 

Can anyone please assist me?

Thanks

Categories:
  • Verified answer
    RusselThomas Profile Picture
    4,014 on at

    Hi @Vstar19 ,

    I think I understand what you're trying to do...

    If(
    varButton = ThisItem.Result,
    Set(varButton,show),
    varButton = ThisItem.Result
    )

    1: What is "show" in this formula?  Is it a boolean variable you've created somewhere else?

     

    2: The false portion of this logic condition isn't doing anything.  The logic resolves like this;

    "If varButton equals ThisItem.Result then make varbutton equal show, else false."

    Is that else false intended, or shouldn't you actually be using Set() again to set varButton=ThisItem.Result here?

    If(
    varButton = ThisItem.Result,
    Set(varButton,show),
    Set(varButton, ThisItem.Result)
    )

    I'm really not sure where show comes into it...is that another boolean to control overall visibility?  Do you need it?

     

    If I assume varButton is a variable that contains either the current expanded row distinct value, or nothing, then I imagine the behaviour as follows;

    • varButton starts off blank, nothing is expanded. 
    • You click on a row button, varButton becomes the value of that row and the sub-gallery for that row appears. 
    • You click on another row button, varButton becomes the value of the new row, the current sub-gallery disappears and the new one expands. 
    • if you click on the same row button as the one that is currently expanded, varButton becomes blank and the sub-gallery disappears.

    Logic on the button OnSelect: property would then look something like this;

    If(varButton=ThisItem.Result, 
     Set(varButton, Blank()),
     Set varButton=ThisItem.Result
    )

     Then on your sub-gallery Visible: property;

    varButton=ThisItem.Result

    Not sure if this helps, but hope it does 😊

    Kind regards,

    RT

  • Vstar19 Profile Picture
    381 on at

    Thank you very much. I spent hours tackling this but you explained it and made me understand. And now it works 🙂 Thanks

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 234 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 207 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 169

Last 30 days Overall leaderboard