Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Left function error

(0) ShareShare
ReportReport
Posted on by

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
)

 

  • MIA27 Profile Picture
    on at
    Re: Left function error

    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
     
  • MIA27 Profile Picture
    on at
    Re: Left function error

    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
     

     

  • Verified answer
    LaurensM Profile Picture
    12,510 Super User 2025 Season 1 on at
    Re: Left function error

    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
    on at
    Re: Left function error

    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

  • LaurensM Profile Picture
    12,510 Super User 2025 Season 1 on at
    Re: Left function error

    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
    on at
    Re: Left function error

    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
  • MIA27 Profile Picture
    on at
    Re: Left function error

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

  • MIA27 Profile Picture
    on at
    Re: Left function error

    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.

  • LaurensM Profile Picture
    12,510 Super User 2025 Season 1 on at
    Re: Left function error

    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!

  • Ami K Profile Picture
    15,665 Super User 2024 Season 1 on at
    Re: Left function error

    @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).

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,651 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard