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 / If Statement to Define...
Power Apps
Answered

If Statement to Define Image Name

(0) ShareShare
ReportReport
Posted on by 175

Hi all.

 

I have a very long if statement that defines the image name of a specific image depending on a variable name. I have attached a txt file showing an example.

 

I know that a lookup against an excel table or sharepoint list could normally be used but I cant make a lookup work when trying to define an image name.

 

Any suggestions?

Categories:
  • eka24 Profile Picture
    20,925 on at

    Can you describe the issue in detail and if possible the formula you have.

    ------------

    If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

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

    Hi @barrymac20 ,

    Do you want to define different image names based on different situation?

    Could you tell me

    1)what does the image name mean in details? The image control's name? the image's name that you want to update?

    2)where does the image come from? what do you want to do with this image?

    3)the defining rule?

    I agree with @eka24 , I think you need to provide more details about your issue.

     

     

    Best regards,

  • barrymac20 Profile Picture
    175 on at

    I'm sorry Guys. I just realised the .txt file I tried to upload was rejected because of the file format. 

    I've now added a pdf version to the original post.

    @v-yutliu-msft 

     

    1)what does the image name mean in details? The image control's name? the image's name that you want to update?

    The image is embedded in a component. The component contains up to 16 images side by side.

    The images control name (relative to the uploaded file) is Section04Image. The names in the component range from Section01Image, Section02Image, ......... Section16Image

     

    2)where does the image come from? what do you want to do with this image?

    The image is imported to the powerapp itself.

    I show the image as part of the component.

     

    3)the defining rule?

    There are some defining rules for each "Section" but I have combined the required values in to a variable. The variable name relevant to the uploaded file is varSection04Image. You will see from the file that there is a large range of possible variables.

  • barrymac20 Profile Picture
    175 on at

    I have attached a sample of the component I spoke about above.

    Each vertical section as shown is a separate image. In this example there are 5 images shown (Section01Image, Section02Image, Section03Image, Section04Image, Section05Image). The remaining images (06 to 16) are hidden as they are not required here.

     

    Each of the vertical section images depends on the value of the variable (varSection01Image, varSection02Image, etc)

    GA Sample.JPG
  • barrymac20 Profile Picture
    175 on at

    Hi @v-yutliu-msft  and @eka24 

     

    Have you had a chance to take another look at my issue since I provided the additional information?

     

    Barry

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

    Hi @barrymac20 ,

    Do you want to decide which image display in the image control based on variable value?
    I've made a similar test and not met any problem.

    I think your key point should be about component.

    Please notice that: since the images are inside component, so only the variables inside the component could affect these image controls.

    If you set those variables outside component, the image controls will not affected by these variables.

    To solution is to pass these outside variables to component.

     

    1)if these variables are inside the component.

    In this situation, you need to create variables by using the controls inside the component.

    Just like this:
    insert some buttons inside the component, set their OnSelect:

    Set(varSection01Image,....)
    Set(varSection02Image,....)

    ....

    Then you could directly use these variables in your images.

    set the images' Image just like the formula that you used:

    Section01Image's Image:

    If(varSection01Image=....,....,....)

    Section02Image's Image:

     

    If(varSection02Image=....,....,....)

     

     

    2)If these variables are outside the component.

    It means that you use controls outside the component to create these variables.

    Then you need to pass these variables to component.

    How to pass these variables to component?
    Firstly, create 16 custom properties (input) in this component.

    Like this:

    6232.PNG

     

    Then set Section01Image's Image like this:

    If(Component1.varSection01Image=....,'xxx',
     Component1.varSection01Image=....,'xxx',
     ....)
    //component is this component name
    fill in variable value in "..."
    fill in image name in "xxx"

    set Section02Image's Image like this:

     

    If(Component1.varSection02Image=....,'xxx',
     Component1.varSection02Image=....,'xxx',
     ....)
    //component is this component name
    fill in variable value in "..."
    fill in image name in "xxx"

     

    ..... others are similar

    Outside the component, in the app insert this componnet.

    set the component's varSection01Image:

    varSection01Image

    //set component's varSection01Image to the variable's value

    set the component's varSection02Image:

     

    varSection02Image

     

    ..... others are similar

     

    Then images inside the component will change with the variable outside the component.

     

     

    Best regards,

  • barrymac20 Profile Picture
    175 on at

    Hi.

     

    Thanks for the detailed reply.

     

    Option 2 is how I have designed my app. 

    But my question is in relation to the the IF statement and if there is any way to simplify it?

     

    Is there a way to use a Lookup instead of an IF for images?

    i.e. Lookup variable name and return image name

     

    Barry

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

    Hi @barrymac20 ,

    If you want to use lookup function instead of if statement, firstly you need to create a collection to save all the uploaded pictures.

    For example, my uploaded images named : '1','2','3'

    Then use formula like this to save all these pics in a collection:

    ClearCollect(test10,{pic:'1'},{pic:'2'},{pic:'3'})

    Then set the image control's Image like this:

    Section01Image

    LookUp(test10, 
     Substitute(varSection01Image,
     First(Split(varSection01Image,"-")).Result&"-",""
     )
     in pic,pic
    )

    Section02Image

     

    LookUp(test10, 
     Substitute(varSection01Image,
     First(Split(varSection02Image,"-")).Result&"-",""
     )
     in pic,pic
    )

     

    Others are similar.

     

     

    Best regards,

  • barrymac20 Profile Picture
    175 on at

    This is a lot closer to what I need.

     

    Can you explain this formula a bit more as I don't really understand why we're substituting etc.

     

    LookUp(test10, 
     Substitute(varSection01Image,
     First(Split(varSection01Image,"-")).Result&"-",""
     )
     in pic,pic
    ) 

     

  • Verified answer
    barrymac20 Profile Picture
    175 on at

    This is how I made it work.

    I created a collection on App Start that pulls in the variable name and the corresponding image.

    ClearCollect(collGAImages,

    {variablename:"5000A-Cable-Top-NoMeter", picname:'4000A-Cable-Top-NoMeter'},

    {variablename:"5000A-Cable-Top-Meter", picname:'4000A-Cable-Top-Meter'},

    {variablename:"5000A-Busduct-Top-NoMeter", picname:'4000A-Busduct-Top-NoMeter'}, {variablename:"5000A-Busduct-Top-Meter", picname:'4000A-Busduct-Top-Meter'},

    {variablename:"5000A-Close Coupled Traffo - Left-Top-NoMeter", picname:'4000A-LHTransformer-Top-NoMeter'}, {variablename:"5000A-Close Coupled Traffo - Right-Top-NoMeter", picname:'4000A-RHTransformer-Top-NoMeter'}, {variablename:"5000A-Close Coupled Traffo - Left-Top-Meter", picname:'4000A-LHTransformer-Top-Meter'},

    {variablename:"5000A-Close Coupled Traffo - Right-Top-Meter", picname:'4000A-RHTransformer-Top-Meter'},

    .

    .

    .

    etc)

     

    Then, the Image properties for each image control are set to:

    Section 1 Image property - LookUp(collGAImages,varSection01Image in variablename,picname),

    Section 2 Image property - LookUp(collGAImages,varSection02Image in variablename,picname),

    Section 3 Image property - LookUp(collGAImages,varSection03Image in variablename,picname),

    and so on...

     

    So with the Collection loaded, as the "varSection01Image" variable changes the corresponding Image is pulled from the collection and used.

     

    I still don't understand the need for the Substitute function above but I have been able to use the basis of your suggestion.

    Note that I had tried a similar idea previously by storing the the lookup table in Excel but the use of the ' for the image names was causing me problems.

     

    Barry

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 190 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard