I’ve been creating a Power App and needed to add some conditional logic to a button, the app I’ve been working on allows users to browse a list of registered mentors, view their profiles and submit a request for a mentoring session with a mentor using a button.
Within the app, I wanted the button on the mentor profile page that is used to request a session to display “Request {mentor first name} as a mentor“, the challenge I had is that for mentors with longer first names (>9 characters) it was causing the text to wrap and it looked ugly. I decided to add some logic to change the message displayed based on the length of the mentors first name, basically:
If the mentors first name is <10 characters display “Request {first name} as mentor”, otherwise displays “Request as Mentor”.
The other small challenge I had is that the mentor’s full name is held in a variable imaginatively named MentorName, therefore I needed to first split their full name so that I could pull out their first name. I achieved this with the split function using space ” ” as a delimiter. It then returns the first item from the resultant table outputted by the Split function (which would be the first name), using the First function.
This is then wrapped in an If function which uses the Len function to check the number of characters in the first name, if this is less than 10, return the name otherwise return nothing.
Below you can see an example of this in action, along with the Power Fx code. In this case MentorName = “Harrison Griffin”
"Request " & (If(Len(First(Split(MentorName," ")).Result)<10,(First(Split(MentorName," ")).Result),""))&" as Mentor"

The second screenshot shows the behaviour with a first name that is greater than 9 characters, in this case MentorName = “Christopher Griffin”


Leave a comment