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 Apps
Answered

Look up function

(0) ShareShare
ReportReport
Posted on by

I've created a lookup function to set a variant. I want to set the variable to the first letter placed in a text box if it does not contain a P or the first 2 letters in the variable if it does. This is my formula: 

Set(varEventCode, If(IsBlank('EventSiteCode-TotalContact'),"", 'EventDate-TotalContact'.Text = Left("P",2),Left(Upper('EventSiteCode-TotalContact'.Text),2), Left(Upper('EventSiteCode-TotalContact'.Text),1)))

It doesn't seem to work with the else value asking for the number of characters set to 1. What am I missing? 



Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Lisea123 

    Not sure of the value the variable will bring to you, but in general, your formula should be the following:

    With({_val:Left(Upper('EventSiteCode-TotalContact'.Text),2)},
     If(StartsWith(_val, "P"), Left(_val, 1), _val)
    )

     

    I hope this is helpful for you.

  • LA-07111402-0 Profile Picture
    on at

    Thank you for this. I need my variable to be 2 characters if the text in EventSiteCode starts with a P and only 1 character if it starts with anything else. 
    So do I just flip your formula? 
    With({_val:Left(Upper('EventSiteCode-TotalContact'.Text),1)},If(StartsWith(_val,"P",Left(_val,2),_val))
    I tried this and it didn't work. 😞
     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Lisea123 

    The formula already accounted for that.

    With({_val:Left(Upper('EventSiteCode-TotalContact'.Text),2)},
     If(StartsWith(_val, "P"), Left(_val, 1), _val)
    )

    In general it reads like this:

    First, get the first 2 characters of the EventSiteCode-TotalContact (we only ever care about 2 characters).

    Then if the result (_val) starts with "P", then return just the first character, otherwise return the 2 characters.

     

    So, unless I am completely misunderstanding what you are saying, the provided formula should be giving you what you want.

     

  • LA-07111402-0 Profile Picture
    on at

    This is they way I need it.
    (if the result (_val) starts with "P", then return just the 2 character, otherwise return the 1 characters.)
    So can I just change the 1 to a 2? But that won't help with the ones that I only need 1 character. I need 2 characters if it's a P otherwise just 1 character. 

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Lisea123 

    Yes, got it...so change to:

    With({_val:Left(Upper('EventSiteCode-TotalContact'.Text),2)},
     If(StartsWith(_val, "P"), _val, Left(_val, 1))
    )

     

  • LA-07111402-0 Profile Picture
    on at

    THANK YOU!!!! Life saver! 

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 542 Most Valuable Professional

#2
Haque Profile Picture

Haque 206

#3
Kalathiya Profile Picture

Kalathiya 201 Super User 2026 Season 1

Last 30 days Overall leaderboard