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 / Cannot use “If” to con...
Power Apps
Unanswered

Cannot use “If” to control the width of the image in a Gallary

(0) ShareShare
ReportReport
Posted on by 23

My app refers to a SharePoint list. There is a column of people in the list (with different numbers of people). I need to display the photos and names of these people and other information in the list. So I created two libraries, one of which is nested in the other. As shown below,

屏幕截图 2021-09-08 185847.png

 

 

Gallery5 is used to display other information in a specific row,
Gallery6 is used to display the pictures and names of people in the row

 

I want to adjust the size of their photos according to the number of people, so I created a Textlabel (Label18_1) in Gallery5 to store the number of people (CountRows(ThisItem.Nominee))

 

I set the width of the Image in Gallery6 to: If(Label18_1.Text="1",80,50).

 

But when I refreshed the page, in the template with multiple photos,  the width of images photos is still 80.

 

@RandyHayes 

 

Categories:
  • SafaK Profile Picture
    62 on at

    Yes, this is because you are comparing and Integer with string 🙂 
    you are setting the value of the Text to .. CountRows(ThisItem.Nominee) //which is an integer, and then you are comparing the value with a string Label18_1.Text="1", 

    so you have two options; 
    1. Set the width of the image to ->    If(CountRows(ThisItem.Nominee)=1,80,50).

    2. Add Text property to set the value as Text in the text box, to compare it as a string ->   Text(CountRows(ThisItem.Nominee))


  • StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    Hi @Alexis_M 

     

    Your formula looks good. Can you convert to a number using Value?

     

    If(Value(ChildGalleryCount.Text) <= 1,80,50)

     

    In this example, I have 2 items on my sub-gallery displays the image smaller

    StalinPonnusamy_0-1631104497124.png

     

     

  • Alexis_M Profile Picture
    23 on at

    Thanks for your reply.

     

    Option 1 does not work, cause "ThisItem.Nominee" is the value of Item of Gallery5 (child gallery). I can't use it as the image's property.

     

    Option 2 does not work too, after I refreshed the webpage, the width of all the images are still 80.

     

    I guess this problem is like this question,  but I don't know how to use the "if error" in this situation.

     

    @SafaK 

     

  • Alexis_M Profile Picture
    23 on at

    Thanks! I tried this solution, but it doesn't work. After I save the app or refresh the webpage or reopen the app, all of the width are still 80 

     

    I guess this problem is like this question.  but I don't know how to use the "iferror" in this situation.

     

    @StalinPonnusamy 

  • StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    Hi @Alexis_M

     

    Let me explain how this works in my sample.

     

    • Insert a label (ChildGalleryCount) in the main gallery and set Text as CountRows(ThisItem.Nominee)
    • ChildGalleryCount has a count of sub-gallery count for this specific item
    • Set Image width property on the sub gallery to
    • If(Value(ChildGalleryCount.Text) <= 1,80,50)

     

    Count 2 is a label(ChildGalleryCount) that shows the count

    StalinPonnusamy_0-1631130114890.png

     

  • Alexis_M Profile Picture
    23 on at

    Thanks! But this is exactly what I did before. It works when you just set it up, but when you refresh the page or restart the app it will go wrong

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

#2
WarrenBelz Profile Picture

WarrenBelz 204 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 122

Last 30 days Overall leaderboard