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 Platform Community / Forums / Power Apps / Struggling with if sta...
Power Apps
Answered

Struggling with if statement

(0) ShareShare
ReportReport
Posted on by 1,625

Hi

 

I am trying to display a trash icon in a gallery only if the logged in user is an admin and the Location field in SQL is set to 'Admin'.

I have a variable for the other users and their location is being stored in a variable called vUserLocation

 

if vUserLocation matches the Location column value e.g. 'Prague' then the trash icon should be visible for those records, but not any records which are 'Admin'

if vUserLocation matches the Location column value e.g. 'London' then the trash icon should be visible for those records, but not any records which are 'Admin'

if vUserLocation matches the Location column value e.g. 'Manchester' then the trash icon should be visible for those records, but not any records which are 'Admin'

 

I dont think the If statement will need to have Prague, London or Manchester hard coded, rather the vUserLocation would be used to lookup the SQL table values where the same text exists?

 

But the trash icon must always be visible if the logged in user is admin, regardless of which location is specified for Location - which I think I have working

 

The following works for me without an if statement, where the trash icon is always visible for the admin, but adding an if statement I cannot get the conditions to work, as soon as I add an If statement to the below my code messes up

 

LookUp(SqlTable, ThisItem.Location = "Admin" || Not(ThisItem.Location = "Admin" And vAdminEmail.AdminEmail = vUser, true)

 

Categories:
  • hthpowerapper Profile Picture
    364 Super User 2024 Season 1 on at

    Assuming this is a formula for your icon.Visiblity it could look something like this. 

    If(
     vUserLocation = "Admin" || vUserLocation = ThisItem.Location,
     true, // Show the trash icon if the user is an admin or if the user's location matches the record's location
     false // Hide the trash icon for other cases
    )

    Including your failed If statement could provide valuable insight into where youre experiencing issues.

  • Krishna_R Profile Picture
    525 on at

    Hi @Lefty 

    I believe you can try something as below mentioned formula on the visible property of the Icon.

    If(ThisItem.Location = "Admin" || ThisItem.Location = vUserLocation, true, false)

     

  • Lefty Profile Picture
    1,625 on at

    @hthpowerapper 

    Thanks

    I see what you have suggested, thanks, but vUserLocation will never be admin, there is a different variable for that is not part of the logic of obtaining an admin, long story.

     

    my failed if statement just gets really messy

     

    but basically I need help to combine both the following and individually they work:

    LookUp(SqlTable,ThisItem.Location = vUserLocation, true)
    
    LookUp(SqlTable, ThisItem.Location = "Admin" || Not(ThisItem.Location = "Admin" And vAdminEmail.AdminEmail = vUser, true)

     

  • Lefty Profile Picture
    1,625 on at

    @Krishna_R 

    Hi

     

    I think you are on the right track with this, thanks just trying

  • Verified answer
    WarrenBelz Profile Picture
    156,926 Most Valuable Professional on at

    Hi @Lefty ,

    If this is for the Visible of an icon in a Gallery, do you need this ?

    vAdminEmail.AdminEmail = vUser ||
    (
     ThisItem.Location = vUserLocation && 
     !(ThisItem.Location = "Admin")
    )

    You do not need an If() statement - this will return a true/false result which will be reflected in the Visible of the icon 

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 220 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 194 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 150

Last 30 days Overall leaderboard