Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SkorpionAAM
Helper V
Helper V

Add 10 hours in TIME Data with Condition

I have data 

 

like this 

 

12:00 Am

2:00 Am

8:00 Am 

 

and so on 

 

what i need on these timing that 10:00 Am is this realy opeing timing of work

 

so if time start from 00:00:00 to 9:00 Am so add timing to cover 10 Am 

 

so example if time is 12:00 AM then add 10 hours

if time is 2:00 Am then add 8 hours 

if time is 8:00 Am then Add 2 hours 

 

i think i explina you guys weel as my english is not good

1 ACCEPTED SOLUTION

@SkorpionAAM 

 

Then use the IF statement to check it is between the time period, modify the table/column name accordingly

Column = 
 FORMAT (  IF([Column1]>=TIME(0,0,0)&&[Column1]<=TIME(10,0,0),TIME(10,0,0),[Column1]),"hh:mm:ss AM/PM" )

 

View solution in original post

15 REPLIES 15
Samarth_18
Community Champion
Community Champion

Hi @SkorpionAAM ,

 

You can create a column with below code:-

 

Column = 
VAR diff =
    DATEDIFF ( 'Table (2)'[Column1], "10:00:00 AM", HOUR )
RETURN
    FORMAT ( 'Table (2)'[Column1] + TIME ( diff, 0, 0 ), "hh:mm:ss AM/PM" )

 

Output:-

Samarth_18_0-1644220027278.png

 

 

Thanks,

Samarth

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Hi @SkorpionAAM 

 

Do you need to convert all time to 10am? Then you can simply add a column with value 10am...

Or only for the time between 0am to 10am should be converted to 10am? then like this?

Vera_33_0-1644220834887.png

 

only for the time between 0am to 10am should be converted to 10am

@SkorpionAAM 

 

Then use the IF statement to check it is between the time period, modify the table/column name accordingly

Column = 
 FORMAT (  IF([Column1]>=TIME(0,0,0)&&[Column1]<=TIME(10,0,0),TIME(10,0,0),[Column1]),"hh:mm:ss AM/PM" )

 

getting error

An argument of function 'TIME' has the wrong data type or the result is too large or too small.

thanks but i need to add the time 

 

so example if time is 12:00 AM then add 10 hours

if time is 2:00 Am then add 8 hours 

if time is 8:00 Am then Add 2 hours 

 

@SkorpionAAM It is adding the time only. I am hoping your column data type is time only?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

yes but it will not add the time if  10:00 Am till 23:59:59

 only add timing from 00:00:00 to 9:59:59

 

 

@SkorpionAAM What should be ideal output if time is 11:00 AM then do we need to add 23 hours into it?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

it would be same only Chnage time from 12:00:00 Am till 9:59:59

 

@SkorpionAAM Actually I am asking what is the expected output if time is 11:00 AM. What it should add into it.

Like you mentioned if it is 8:00 then add 2:00

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

nothing will add after 10 Am they will be same 

t would be same only Chnage time from 12:00:00 Am till 9:59:59 Am

yes its Time Datatype

@SkorpionAAM , Can you try again with below code:-

Column = 
VAR diff =
    DATEDIFF ( 'Table (2)'[Column1], "10:00:00 AM", HOUR )
RETURN
    FORMAT ( 'Table (2)'[Column1] + TIME ( diff, 0, 0 ), "hh:mm:ss AM/PM" )

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

same 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.