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 / Left function error
Power Apps
Answered

Left function error

(0) ShareShare
ReportReport
Posted on by 2

I am trying to set image in the gallery based on condition, But not working, No error no image on display

please guide what is the error making: 

 

Switch(
 Left(ThisItem.Model,1),
 "B",
 Bulldozer,
 "E",
 Excavator
)

 

Categories:
I have the same question (0)
  • Ami K Profile Picture
    15,689 Super User 2024 Season 1 on at

    @MIA27 - 

     

    1. What is your data source? (SharePoint, SQL, Dataverse etc)
    2. What is the data type for Model? Is that an actual field in your data source?
    3. Are you certain that your image file names in your code exactly match the image file names in the Media Pane? I see you have correctly excluded the image extension (png, jpeg etc).
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @MIA27,

     

    The function looks ok - using this approach however is case sensitive. Could it be possible that the Model starts with a lower case instead of an upper case?

     

    Switch(
     //Lower avoids case sensitivity by defaulting it to lower case
     Left(Lower(ThisItem.Model),1),
     "b",
     Bulldozer,
     "e",
     Excavator
    )

    (Make sure Model never starts with a space, otherwise you may need to use the Trim() function as well)

     

    If this solves your question, would you be so kind as to accept it as a solution.
    Thanks!

  • MIA27 Profile Picture
    2 on at

    Data source - Table in Teams

    Data Type of Model is Text 

    Yes, the file name is correct. Because I test in another gallery, in another situation where Left was not been used.

  • MIA27 Profile Picture
    2 on at

    It is not lower case, and does not have space at the start.

  • MIA27 Profile Picture
    2 on at

    Also please note to test I put the below and it works

    Switch(
       ThisItem.Model,
       "D155A",
       Bulldozer,
       "PC400",
       Excavator
    )
     
    But this is not the requirement, as there are several models and can categorised by the first letter, therefore I was trying the left function.
    This proves that mistake is in Left function writing method.
     
    Pls guide
  • LaurensM Profile Picture
    12,516 Moderator on at

    Hi @MIA27,

     

    I suspect that this may be caused due to explicit column selection. A workaround would be defining the required columns via ShowColumns() in your gallery items property.

     

    In your case you could add an additional column containing the Left value:

    //Gallery items property
    AddColumns(
     Datasource, //replace with your datasource or Filter statement
     "ModelFirstChar",
     Left(Model, 1)
    )
    
    //Image property of the Image control
    Switch(
     ModelFirstChar,
     "B",
     Bulldozer,
     "E",
     Excavator
    )

     

    I hope this helps!

  • MIA27 Profile Picture
    2 on at

    I applied the code as below, but getting formula error as shown in the below image

     

    //Gallery items property
    AddColumns(
     colAllList, //replace with your datasource or Filter statement
     "ModelFirstChar",
     Left(Model, 1)
    )
    
    //Image property of the Image control
    Switch(
     ModelFirstChar,
     "B",
     Bulldozer,
     "E",
     Excavator
    )

     

    MIA27_0-1708372192384.png

     

     

    Please guide the correction

  • Verified answer
    LaurensM Profile Picture
    12,516 Moderator on at

    Hi @MIA27,

     

    I forgot to prefix ModelFirstChar with ThisItem. My apologies.

    Switch(
     //Changed here
     ThisItem.ModelFirstChar,
     "B",
     Bulldozer,
     "E",
     Excavator
    )

     

    Should the change above still result in no images - you may want to add this AddColumns when collecting the data instead:

    ClearCollect(
     AddColumns(
     DataSource,
     "ModelFirstChar",
     Left(Model, 1)
     )
    )

     

    I hope this helps!

  • MIA27 Profile Picture
    2 on at

    Not worked, so frustrating, such a simple formula, not working.

     

    When I apply with if for testing purpose, the left function works

    If(Left(ThisItem.Model,1) = "D",Bulldozer,"E",Excavator)
     
    Once changed to switch function with same left, does not work
    Switch(Left(ThisItem.Model,1) = "D",Bulldozer,"E",Excavator
     
    Funny situation, left bring the same value, in both situation, but not work in switch.
    Any idea, need to use .value or .text
     
    Please guide
     

     

  • MIA27 Profile Picture
    2 on at

    Finally it worked

    Switch(Left(ThisItem.Model,1),"D",Bulldozer,"E",Excavator)
     
    It was my mistake, the result I was putting with Left, it should be seperate,
     
    Thank you for all efffort and advise which gave me learning for future use
     

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
WarrenBelz Profile Picture

WarrenBelz 401 Most Valuable Professional

#2
11manish Profile Picture

11manish 201 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard