cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lisea123
Helper II
Helper II

Look up function

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? 



1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@Lisea123 

Yes, got it...so change to:

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

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

6 REPLIES 6
RandyHayes
Super User III
Super User III

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

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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
Super User III
Super User III

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

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

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
Super User III
Super User III

@Lisea123 

Yes, got it...so change to:

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

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

THANK YOU!!!! Life saver! 

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (3,295)