web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : TTA8SdTUx6QPE0bKbu9ppm
Power Apps - Building Power Apps
Answered

Left function error

Like (0) ShareShare
ReportReport
Posted on 19 Feb 2024 18:15:02 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
)

 

I have the same question (0)
  • MIA27 Profile Picture
    on 20 Feb 2024 at 05:17:29
    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 20 Feb 2024 at 05:04:14
    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 Moderator on 19 Feb 2024 at 20:04:09
    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 19 Feb 2024 at 19:50:43
    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 Moderator on 19 Feb 2024 at 19:18:07
    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 19 Feb 2024 at 18:59:17
    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 19 Feb 2024 at 18:44:45
    Re: Left function error

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

  • MIA27 Profile Picture
    on 19 Feb 2024 at 18:40:11
    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 Moderator on 19 Feb 2024 at 18:24:18
    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,670 Super User 2024 Season 1 on 19 Feb 2024 at 18:24:01
    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Tom Macfarlan – Community Spotlight

We are honored to recognize Tom Macfarlan as our Community Spotlight for October…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 885 Most Valuable Professional

#2
developerAJ Profile Picture

developerAJ 571

#3
Michael E. Gernaey Profile Picture

Michael E. Gernaey 352 Super User 2025 Season 2

Last 30 days Overall leaderboard
Loading started
Loading complete