Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Look up function

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? 



  • Re: Look up function

    THANK YOU!!!! Life saver! 

  • Verified answer
    RandyHayes Profile Picture
    RandyHayes 76,308 on at
    Re: Look up function

    @Lisea123 

    Yes, got it...so change to:

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

     

  • Re: Look up function

    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. 

  • RandyHayes Profile Picture
    RandyHayes 76,308 on at
    Re: Look up function

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

     

  • Re: Look up function

    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
    RandyHayes 76,308 on at
    Re: Look up function

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

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,532

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,050

Leaderboard