cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
noneother
Helper I
Helper I

Calculating duration between onselect

Hi all I have calculated the duration between onselect in powerapps by calculating the difference between: the now() at the first onselect and the now() at the second onselect.

 

These two times are stored in SharePoint using patch function and a calculated column then calculates the difference.

 

I noticed that doing this way doesn't always capture the right duration because the first onselect now() often doesn't get recorded. 

 

Is there another solution to getting the duration?

1 ACCEPTED SOLUTION

Accepted Solutions
KrishnaV
Community Champion
Community Champion

Hi @noneother ,

 

Try this:

UpdateContext({UpdateStartTime: Now()}); Patch('Consumer Sample for Survey FINAL', lookup('Consumer Sample for Survey FINAL',ID=Gallery1.Selected.ID), {'Call Started': Label13.Text,'Call Ended': Now()})

 
I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

View solution in original post

8 REPLIES 8
eka24
Super User
Super User

Are you using a Timer? Can you give more detail on your current Approach

------------

If you like this post, give a Thumbs up. Where it solved your request, Mark it as a Solution to enable other users find it.

KrishnaV
Community Champion
Community Champion

Hi @noneother ,

 

You are almost doing the right approach, please make the below changes to make it perfect:

  1. Create 2 labels on the screen (you can make their visible false once you are sure about the output)
  2. Set the label 1 with Now() for the onSelect of the button and the label 2 with Now() for the second of the button
  3. Now use the text on the label as part of your Patch 
    Note: Text on the Label will not change unless you reload the screen 😊 so you will the expected values to be stored in the list.

I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

@KrishnaV 

 
 

Unfortunately I couldn't get this to work.

 

Label with the following formula in Text: UpdateStartTime

 

My button forumla for the onselect:

UpdateContext({UpdateStartTime: Now()}); Patch('Consumer Sample for Survey FINAL', Gallery1.Selected, {'Call Started': Label13})

The button formula returns: unknown error

eka24 no timer. just using the now( ) to calculate duration between two time stamps. i thought this way would be quicker but it's hit or miss

KrishnaV
Community Champion
Community Champion

Hi @noneother ,

 

Try this:

UpdateContext({UpdateStartTime: Now()}); Patch('Consumer Sample for Survey FINAL', lookup('Consumer Sample for Survey FINAL',ID=Gallery1.Selected.ID), {'Call Started': Label13.Text,'Call Ended': Now()})

 
I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

@KrishnaV thank you. seems to be working.

I don't know why this is working better using a label rather than direct patching the now() to my SharePoint list but it seems to do the job and more responsive.

KrishnaV
Community Champion
Community Champion

Hi @noneother ,

 

I am really glad it is working for you. As I said before now() get the instant time.

Since the issue is resolved, do you mind marking it is a solution so that the new members of the community will make use of it?

 

I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
If this post helps you give a and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.

I know what now() does of course just not sure why writing a now to a label is AND then patching is more efficient than patching now() directly.

 

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Carousel_PP_768x460_Wave2 (1).png

2022 Release Wave 2 Plan

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

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Top Solution Authors
Users online (3,246)