Forum Discussion

New_be's avatar
New_be
Helper V
5 years ago
Solved

Convert -ve values to +ve values in Power Query

Hi everyone! Wish you all have a very nice day!

 

Based on the image above, i have TimeIn & TimeOut. So i try to get the hours between these 2 times, meaning that TimeOut - TimeIn. So based on that simple calculation, i got the hours worked values. But some of the value have -ve sign. I just want to know how many hours worked & i just want to ignore the -ve values. So how can i do that? Thanks in advance ðŸ˜Š

12 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    New_be - Use Number.Abs to get the absolute value. So formula should be:

     

    Number.Abs([Adj_OutTime] - [Adj_InTime])

     

     

    • New_be's avatar
      New_be
      Helper V

      I try to use this formula;


       

      But i got the error;

      • Greg_Deckler's avatar
        Greg_Deckler
        Community Champion

        New_be Maybe try some spaces? This worked for me
        Number.Abs([SampleID] - [Outcome]) * 24

        Oh, wait, those are date time, hang on.

         

  • New_be , I think because the out time in on next day

    if Duration.Hours([Adj_hour_worked]) <0  then [Adj_hour_worked]  + duration(1,0,0) else [Adj_hour_worked] 

    • New_be's avatar
      New_be
      Helper V

      Indeed! It is because the out time is in the next day & vice versa. Thanks!

      • amitchandak's avatar
        amitchandak
        Super User

        New_be , In case of the issue, is resolved. Accept all suitable solutions for others to get a similar solution.

    • New_be's avatar
      New_be
      Helper V

      Hi Mr. amitchandak , i try to use the formula, but it still have the problems;

       

       

      This is the result;

       

      • amitchandak's avatar
        amitchandak
        Super User

        New_be , If you have use hour(Adj_hourworked_temp) < 0 and try

        or Adj_hourworked_temp <#duration(0,0,0,0)