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 / If and Switch statemen...
Power Apps
Unanswered

If and Switch statement only working sometimes with certain users?

(0) ShareShare
ReportReport
Posted on by 503

Hi all

 

I have a clock in/out application. There are many different users and some users start at 7AM and others might start at different times. I have If statements inside a switch to recognize which user starts at which time and it works great on my end but when the users start using it, the if and switch statement is failing to recognize what time they start. 

 

Here is an example of the formula and as you can see if the user clocks in past the specified time then it will use current time to sign the user in- 

 

 

With(
 {
 wUserStart: DefaultTime.Text
 },
 Switch(
 wUserStart,
 StartTime7am.Text,
 If(
 Now() > DateTimeValue("7:00 AM"),
 Now(),
 DateTimeValue("7:00 AM")
 ),
 StartTime8am.Text,
 If(
 Now() > DateTimeValue("8:00 AM"),
 Now(),
 DateTimeValue("8:00 AM") 
 ),
 StartTime9am.Text,
 If(
 Now() > DateTimeValue("9:00 AM"),
 Now(),
 DateTimeValue("9:00 AM") 
 ),
 //Employees with no start time
 If(IsBlank(DefaultTime.Text),
 Now() 
 )
 
 )), 

 

 

 

So the DefaultTime.Text is pulling the start time (Text(Gallery.Selected.'Default Start Time', "HH:mm AM/PM") from a gallery that is linked to the dataverse and the users start time column/field. So this label can basically see the users start time. 

 

So if the switch finds a match in the variables then it will use that If statement below it. 

 

This all works great for me when I test, but when the users start clocking in e.g. before 7am, it still doesnt recognize they start at 7am and doesnt round their time up to 7am as seen in the screenshot. Although it worked for 3 users today but thats out of 20. 

So it seems like it works sometimes but other times it does? Im not sure if this could have something to do with the users Ipad? But it doesnt make sense that it worked for 3 users so im not sure. 

 

Im really stumped on this one and unsure if theres an alternate way to set this up using dataverse. 

 

Any help is much appreciated and just let me know if you need more info. Thank you 

Capture543553354.JPG
Categories:
  • StalinPonnusamy Profile Picture
    Super User 2024 Season 1 on at

    Hi @Usernametwice23 

     

    Looks like Seconds conversion is missing. Add seconds (:00) with default time.

     

    With(
     {
     wUserStart: DefaultTime.Text
     },
     Switch(
     wUserStart,
     StartTime7am.Text,
     If(
     Now() > DateTimeValue("7:00:00 AM"),
     Now(),
     DateTimeValue("7:00:00 AM")
     ),
     StartTime8am.Text,
     If(
     Now() > DateTimeValue("8:00:00 AM"),
     Now(),
     DateTimeValue("8:00:00 AM") 
     ),
     StartTime9am.Text,
     If(
     Now() > DateTimeValue("9:00:00 AM"),
     Now(),
     DateTimeValue("9:00:00 AM") 
     ),
     //Employees with no start time
     If(IsBlank(DefaultTime.Text),
     Now() 
     )
     
     )), 

     


    Thanks,
    Stalin - Learn To Illuminate

     

  • Usernametwice Profile Picture
    503 on at

    Hi @StalinPonnusamy  thanks for your suggestion. 

     

    Unfortunately the same thing happens when users start logging in and does not work although it works fine on my side. I posted again in power automate forum as I have tried creating a flow with the same purpose as an alternative but I cannot get the correct time/dates into dataverse so this solution (see post for example)

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 432 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 347

#3
WarrenBelz Profile Picture

WarrenBelz 254 Most Valuable Professional

Last 30 days Overall leaderboard