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

Convert number and format hour(00:00) and sum two types of hours

hello

How it converts number into hours? After that I want sum with another number hour format.

Example: (2000/5500)*60=21,81  It"s 21 minutes and 81 second, I want to format 00:21. After that I want to sum whith(Example) 10:00+00:21=10:21. I need this result.

 

Thank you

2 ACCEPTED SOLUTIONS

Accepted Solutions

@RandyHayes 

 

It worked very well 👏👏

Thank you very a lot

View solution in original post

RandyHayes
Super User
Super User

@Larussa 

No problem.  

Then change this line in the formula:

Text(_hours, "[$-en-US]00") & ":" & Text(Mod(_minutes, 60),"[$-en-US]00")

To this:

Text(Mod(_hours, 24), "[$-en-US]00") & ":" & Text(Mod(_minutes, 60),"[$-en-US]00")

 

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
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

16 REPLIES 16
RandyHayes
Super User
Super User

@Larussa 

Set the text property of a label to the following:

With({_seconds:((2000/5500)*60) + (10*3600) },
    Round(_seconds/3600, 0) & ":" & Text(Mod(_seconds, 3600), "[$-en-US]00")
)

In the above formula, the first part of the equation ((2000/5500)*60) provides the 21 minutes and 81 seconds.  The second part (10*3600) adds 10 minutes to that.

The text part will round the minutes and then the second text part returns the mod to provide the minutes.

 

Note: in your example, normally 21.81 seconds would considered 22 seconds when rounded.  The above does that.  If you need to remove the fractions of a second, then adjust the formula as necessary. i.e. 
   (RoundDown((2000/5500)*60, 0)) + (10*3600)

 

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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
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 @RandyHayes 

 

I’ll describe my problem better

 

Label3 = 2000(production measured)

Label5_1=5500(production of parts per hour)

label7,  I put the function below, that you mentioned

With({_seconds:((Label3.Text/Label5_1.Text)*60)+(10*3600)};Round(_seconds/3600;0)& ":" & Text(Mod(_seconds; 3600);"[$-en-US]00"))

Result(production time required) = 10:22, but the result should be 00:22 minutes(rounded)

 

After that  I would like to add result 00:22

Label 4 =10:00 + Label 7= 00:22

Label 8 =10:22( Final result)

 

RandyHayes
Super User
Super User

@Larussa 

I believe you were missing the fact that I put the 10 into the calculation to emphasize that we were adding 10 hours to the formula to show that was the place to do it.

 

I will write the formula a little different so you can see the breakout of where things are used in the formula:

With({_productionMeasured : Value(Label3.Text); 
      _productionPPH : Value(Label5_1.Text);
      _hoursToAdd : Value(Label4.Text)
     };
     
    With({_seconds:((_productionMeasured/_productionPPH)*60)+(_hoursToAdd * 3600)};

        Round(_seconds/3600;0)& ":" & Text(Mod(_seconds; 3600);"[$-en-US]00")
    )
)

 

So, you could use the above formula in the Text property of Label8 and you could use the same formula in Label7 except change the Value(Label4.Text) in the formula to 0

 

I hope that is clearer.

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

@RandyHayes 

 

It works, but when the result is greater than 60 minutes I woud like that result were 01:00.

Example below:  

 

Larussa_0-1610488242753.png01:08( hour format)

 

 

RandyHayes
Super User
Super User

@Larussa 

I'm a little confused.  The formula I gave you was in hh:mm format.

In the original, we added 10 hours to the 22 second result (and I apologize now looking back at the formula that I named things wrong, but the outcome was what was expected).  10 hours and 22 minutes

So your display showed "10:22" for 10 hours 22 minutes.

You should have never seen a "0:68" - what is your formula looking like at this point that got you that?

 

 

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

Look at this, 

powerapps.JPG

 

Model app

 

Math calculations

6000/5600=1,0714(Change for a minutes)*60=64 minutes

(piece for produce/Produce for hour)*60=produce time

 

I need to sum beggining time and produce time 

 

Result 11:00 (End of production)

@RandyHayes 

I used your instruction but It didn't work corretly. Look this result.

IMG_20210116_232350.jpg

IMG_20210116_233656.jpg

 Result 01:17, not 0:77

Sum It 10:00+01:17 result ia 11:17. Did you understand?

RandyHayes
Super User
Super User

@Larussa 

Yes, there was a overflow of minutes and hours in the previous formula.

Use this instead:

With({_productionMeasured : Value(Label13.Text), 
      _productionPPH : Value(Label15_1.Text),
      _minutesToAdd : With({_tval: TimeValue(Label12.Text)}, Hour(_tval)*60 + Minute(_tval))
     },
     
    With({_minutes:Round((_productionMeasured/_productionPPH)*60, 0) + _minutesToAdd  },
        With({
          _hours:RoundDown(_minutes/60, 0)
        },

        Text(_hours, "[$-en-US]00") & ":" & Text(Mod(_minutes, 60),"[$-en-US]00")
        )
    )
)

 

ALSO....DO NOT replace the items in the With formula with things like Label13.Text  Use this formula as it is.  You cannot rely on PowerApps to convert text to numeric and you also will not get any value trying to take the text of "10:00".

So, leave the inner formula the way that it is - in other words things like:

   _minutes:Round((_productionMeasured/_productionPPH)*60, 0) + _minutesToAdd

should be left as they are, do not put your labels in this formula as you showed in your picture.  The With function is already taking that into account.  If you need to change names of label controls, ONLY do it in the With signature.

 

Using the values of your picture I get (sorry no labels, but the same values):

RandyHayes_0-1610913415400.png

 

_____________________________________________________________________________________
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.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

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

@RandyHayes 

 

I did what you asked, it seems that this did not add up with the calculated result

app17_01.JPG

app17_01_2.JPG

Note that if I change the production start to 11:00(Below), the result also changes to 11:00.

It doesn’t seem to be adding up

app17_01_3.JPG

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (5,344)